Skip to content

Commit 056c071

Browse files
authored
Merge branch 'main' into compiler-inline-generics
2 parents 202f009 + 53edb78 commit 056c071

File tree

13 files changed

+186
-124
lines changed

13 files changed

+186
-124
lines changed

compiler/src/transform/expand-generics.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
159159
}
160160
}
161161

162+
/**
163+
* Add dangling types like CommonQueryParameters & BaseEsqlVersion to the generic less schema.
164+
* @param type the type definition
165+
*/
166+
function addDanglingTypeIfNotSeen (type: TypeDefinition): void {
167+
switch (type.kind) {
168+
case 'type_alias':
169+
if (type.generics !== undefined && type.generics.length > 0) {
170+
return
171+
}
172+
break
173+
case 'interface':
174+
if (type.generics !== undefined && type.generics.length > 0) {
175+
return
176+
}
177+
break
178+
}
179+
addIfNotSeen(type.name, () => type)
180+
}
181+
162182
/**
163183
* Expand an interface definition.
164184
*
@@ -173,6 +193,18 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
173193

174194
result.inherits = expandInherits(result.inherits, mappings)
175195

196+
// We add to the schema the non generics behaviors
197+
// CommonQueryParameters
198+
// CommonCatQueryParameters
199+
if (result.behaviors != null) {
200+
result.behaviors.forEach(b => {
201+
if (b.generics == null) {
202+
const type = getType(b.type)
203+
addIfNotSeen(b.type, () => type)
204+
}
205+
})
206+
}
207+
176208
if (result.behaviors != null) {
177209
// We keep the generic parameters, but expand their value
178210
result.behaviors = result.behaviors.map(b => {
@@ -415,6 +447,11 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
415447
expandRootType(endpoint.response)
416448
}
417449

450+
// Allows to retrieve EsqlBase*EsqlVersion
451+
for (const type of inputModel.types) {
452+
addDanglingTypeIfNotSeen(type)
453+
}
454+
418455
sortTypeDefinitions(types)
419456

420457
return {

output/openapi/elasticsearch-serverless-openapi.json

Lines changed: 13 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)