Skip to content

[Backport 8.19] [compiler] Include exceptions to schema #4696

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

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions compiler-rs/clients_schema/src/transform/expand_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ pub fn expand(model: IndexedModel, config: ExpandConfig) -> anyhow::Result<Index

expand_behaviors(&mut resp.behaviors, &mappings, model, ctx)?;
expand_body(&mut resp.body, &mappings, model, ctx)?;

// TODO: exceptions

for exception in &mut resp.exceptions {
expand_body(&mut exception.body, &mappings, model, ctx)?;
}

Ok(resp.into())
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/src/steps/validate-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,23 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Unknown kind: ${typeDef.body.kind}`)
}

if (typeDef.exceptions != null) {
for (const ex of typeDef.exceptions) {
switch (ex.body.kind) {
case 'properties':
validateProperties(ex.body.properties, openGenerics, new Set<string>())
break
case 'value':
validateValueOf(ex.body.value, openGenerics)
break
case 'no_body':
// Nothing to validate
break
}
}
}

context.pop()
}

Expand Down
13 changes: 12 additions & 1 deletion compiler/src/transform/expand-generics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
Request,
Response,
Body,
InstanceOf, Inherits, Property
InstanceOf, Inherits, Property, ResponseException
} from '../model/metamodel'
import { readFile, writeFile } from 'fs/promises'
import stringify from 'safe-stable-stringify'
Expand Down Expand Up @@ -293,6 +293,17 @@ export function expandGenerics (inputModel: Model, config?: ExpansionConfig): Mo
return addIfNotSeen(resp.name, () => {
const result = { ...resp }
result.body = expandBody(resp.body, genericParamMapping(resp.generics, params))
if (resp.exceptions != null) {
result.exceptions = []
for (const exception of resp.exceptions) {
const except: ResponseException = {
description: exception.description,
statusCodes: exception.statusCodes,
body: expandBody(exception.body, genericParamMapping(resp.generics, params))
}
result.exceptions.push(except)
}
}
result.generics = undefined
return result
})
Expand Down
15 changes: 4 additions & 11 deletions specification/indices/get_alias/IndicesGetAliasResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import { ErrorResponseBase } from '@_types/Base'
import { IndexName } from '@_types/common'
import { AliasDefinition } from '@indices/_types/AliasDefinition'
import { AdditionalProperties } from '@spec_utils/behaviors'
import {
IndexAliases,
NotFoundAliases
} from '@indices/get_alias/_types/response'
import { Dictionary } from '@spec_utils/Dictionary'

export class Response {
Expand All @@ -33,12 +35,3 @@ export class Response {
}
]
}

export class IndexAliases {
aliases: Dictionary<string, AliasDefinition>
}

class NotFoundAliases implements AdditionalProperties<string, IndexAliases> {
error: string
status: number
}
33 changes: 33 additions & 0 deletions specification/indices/get_alias/_types/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { AliasDefinition } from '@indices/_types/AliasDefinition'
import { AdditionalProperties } from '@spec_utils/behaviors'
import { Dictionary } from '@spec_utils/Dictionary'

export class IndexAliases {
aliases: Dictionary<string, AliasDefinition>
}

export class NotFoundAliases
implements AdditionalProperties<string, IndexAliases>
{
error: string
status: number
}