diff --git a/compiler/src/transform/expand-generics.ts b/compiler/src/transform/expand-generics.ts index 065bce4ba6..07378e9c51 100644 --- a/compiler/src/transform/expand-generics.ts +++ b/compiler/src/transform/expand-generics.ts @@ -134,6 +134,26 @@ export function expandGenerics (inputModel: Model): Model { } } + /** + * 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. * @@ -148,6 +168,18 @@ export function expandGenerics (inputModel: Model): Model { 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 => { @@ -361,6 +393,11 @@ export function expandGenerics (inputModel: Model): Model { expandRootType(endpoint.response) } + // Allows to retrieve EsqlBase*EsqlVersion + for (const type of inputModel.types) { + addDanglingTypeIfNotSeen(type) + } + sortTypeDefinitions(types) return {