From a8238eea212e7a10813febba6d846dd1158b7bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Saint-F=C3=A9lix?= Date: Fri, 3 May 2024 17:52:47 +0200 Subject: [PATCH] Add dangling types to the generic-less schema (#2542) * add dangling types to the genericless schema * fix linting * add an explicit pass in expandInterface for missing behaviors * please the linter gods by using a const (cherry picked from commit 0f890056ff24885602afe232039f453a7e18f592) --- compiler/src/transform/expand-generics.ts | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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 {