Skip to content

Commit aedb8ee

Browse files
Add dangling types to the generic-less schema (#2542) (#2543)
* 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 0f89005) Co-authored-by: Laurent Saint-Félix <laurent.saintfelix@elastic.co>
1 parent 66a8d19 commit aedb8ee

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

compiler/src/transform/expand-generics.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ export function expandGenerics (inputModel: Model): Model {
134134
}
135135
}
136136

137+
/**
138+
* Add dangling types like CommonQueryParameters & BaseEsqlVersion to the generic less schema.
139+
* @param type the type definition
140+
*/
141+
function addDanglingTypeIfNotSeen (type: TypeDefinition): void {
142+
switch (type.kind) {
143+
case 'type_alias':
144+
if (type.generics !== undefined && type.generics.length > 0) {
145+
return
146+
}
147+
break
148+
case 'interface':
149+
if (type.generics !== undefined && type.generics.length > 0) {
150+
return
151+
}
152+
break
153+
}
154+
addIfNotSeen(type.name, () => type)
155+
}
156+
137157
/**
138158
* Expand an interface definition.
139159
*
@@ -148,6 +168,18 @@ export function expandGenerics (inputModel: Model): Model {
148168

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

171+
// We add to the schema the non generics behaviors
172+
// CommonQueryParameters
173+
// CommonCatQueryParameters
174+
if (result.behaviors != null) {
175+
result.behaviors.forEach(b => {
176+
if (b.generics == null) {
177+
const type = getType(b.type)
178+
addIfNotSeen(b.type, () => type)
179+
}
180+
})
181+
}
182+
151183
if (result.behaviors != null) {
152184
// We keep the generic parameters, but expand their value
153185
result.behaviors = result.behaviors.map(b => {
@@ -361,6 +393,11 @@ export function expandGenerics (inputModel: Model): Model {
361393
expandRootType(endpoint.response)
362394
}
363395

396+
// Allows to retrieve EsqlBase*EsqlVersion
397+
for (const type of inputModel.types) {
398+
addDanglingTypeIfNotSeen(type)
399+
}
400+
364401
sortTypeDefinitions(types)
365402

366403
return {

0 commit comments

Comments
 (0)