From ef05e36404f128e6adcda4cf98f2fbc079d88111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Saint-F=C3=A9lix?= Date: Fri, 3 May 2024 14:38:10 +0200 Subject: [PATCH 1/4] add dangling types to the genericless schema --- compiler/src/transform/expand-generics.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/compiler/src/transform/expand-generics.ts b/compiler/src/transform/expand-generics.ts index 065bce4ba6..2d57c052c8 100644 --- a/compiler/src/transform/expand-generics.ts +++ b/compiler/src/transform/expand-generics.ts @@ -134,6 +134,24 @@ 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) { + switch (type.kind) { + case "type_alias": + if (type.generics !== undefined && type.generics.length > 0) { + return; + } + case "interface": + if (type.generics !== undefined && type.generics.length > 0) { + return; + } + } + addIfNotSeen(type.name, () => type) + } + /** * Expand an interface definition. * @@ -361,6 +379,10 @@ export function expandGenerics (inputModel: Model): Model { expandRootType(endpoint.response) } + for (const type of inputModel.types) { + addDanglingTypeIfNotSeen(type); + } + sortTypeDefinitions(types) return { From ca6472f93aa42f42c1514701c9fed6c126f84ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Saint-F=C3=A9lix?= Date: Fri, 3 May 2024 14:53:09 +0200 Subject: [PATCH 2/4] fix linting --- compiler/src/transform/expand-generics.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/src/transform/expand-generics.ts b/compiler/src/transform/expand-generics.ts index 2d57c052c8..d930d2fa14 100644 --- a/compiler/src/transform/expand-generics.ts +++ b/compiler/src/transform/expand-generics.ts @@ -138,16 +138,18 @@ 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) { + function addDanglingTypeIfNotSeen (type: TypeDefinition): void { switch (type.kind) { - case "type_alias": + case 'type_alias': if (type.generics !== undefined && type.generics.length > 0) { - return; + return } - case "interface": + break + case 'interface': if (type.generics !== undefined && type.generics.length > 0) { - return; + return } + break } addIfNotSeen(type.name, () => type) } @@ -380,7 +382,7 @@ export function expandGenerics (inputModel: Model): Model { } for (const type of inputModel.types) { - addDanglingTypeIfNotSeen(type); + addDanglingTypeIfNotSeen(type) } sortTypeDefinitions(types) From 70fb36c52a311032f1c5aee9dbce11d5459fe4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Saint-F=C3=A9lix?= Date: Fri, 3 May 2024 16:17:43 +0200 Subject: [PATCH 3/4] add an explicit pass in expandInterface for missing behaviors --- compiler/src/transform/expand-generics.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/src/transform/expand-generics.ts b/compiler/src/transform/expand-generics.ts index d930d2fa14..8a4792b1b4 100644 --- a/compiler/src/transform/expand-generics.ts +++ b/compiler/src/transform/expand-generics.ts @@ -168,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) { + var 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 => { @@ -381,6 +393,7 @@ export function expandGenerics (inputModel: Model): Model { expandRootType(endpoint.response) } + // Allows to retrieve EsqlBase*EsqlVersion for (const type of inputModel.types) { addDanglingTypeIfNotSeen(type) } From 24577a44403e4e5c99c086c377449c0fc7db0c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Saint-F=C3=A9lix?= Date: Fri, 3 May 2024 16:18:54 +0200 Subject: [PATCH 4/4] please the linter gods by using a const --- compiler/src/transform/expand-generics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/transform/expand-generics.ts b/compiler/src/transform/expand-generics.ts index 8a4792b1b4..07378e9c51 100644 --- a/compiler/src/transform/expand-generics.ts +++ b/compiler/src/transform/expand-generics.ts @@ -174,7 +174,7 @@ export function expandGenerics (inputModel: Model): Model { if (result.behaviors != null) { result.behaviors.forEach(b => { if (b.generics == null) { - var type = getType(b.type) + const type = getType(b.type) addIfNotSeen(b.type, () => type) } })