Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dangling types to the generic-less schema #2542

Merged
merged 4 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions compiler/src/transform/expand-generics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 {
Expand Down
Loading