Skip to content

Commit

Permalink
Merge branch 'main' into compiler-inline-generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Anaethelion authored May 13, 2024
2 parents 202f009 + 53edb78 commit 056c071
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 124 deletions.
37 changes: 37 additions & 0 deletions compiler/src/transform/expand-generics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
}
}

/**
* Add dangling types like CommonQueryParameters & BaseEsqlVersion to the generic less schema.
* @param type the type definition
*/
function addDanglingTypeIfNotSeen (type: TypeDefinition): void {
switch (type.kind) {
case 'type_alias':
if (type.generics !== undefined && type.generics.length > 0) {
return
}
break
case 'interface':
if (type.generics !== undefined && type.generics.length > 0) {
return
}
break
}
addIfNotSeen(type.name, () => type)
}

/**
* Expand an interface definition.
*
Expand All @@ -173,6 +193,18 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo

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

// We add to the schema the non generics behaviors
// CommonQueryParameters
// CommonCatQueryParameters
if (result.behaviors != null) {
result.behaviors.forEach(b => {
if (b.generics == null) {
const type = getType(b.type)
addIfNotSeen(b.type, () => type)
}
})
}

if (result.behaviors != null) {
// We keep the generic parameters, but expand their value
result.behaviors = result.behaviors.map(b => {
Expand Down Expand Up @@ -415,6 +447,11 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
expandRootType(endpoint.response)
}

// Allows to retrieve EsqlBase*EsqlVersion
for (const type of inputModel.types) {
addDanglingTypeIfNotSeen(type)
}

sortTypeDefinitions(types)

return {
Expand Down
32 changes: 13 additions & 19 deletions output/openapi/elasticsearch-serverless-openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 056c071

Please sign in to comment.