Skip to content

[8.x] OpenAPI: use ':' instead of '#' to separate parts of a component path (#4184) #4197

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
Apr 4, 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
12 changes: 8 additions & 4 deletions compiler-rs/clients_schema_to_openapi/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use openapiv3::{Components, Parameter, ReferenceOr, RequestBody, Response, Schem

use crate::utils::SchemaName;

// Separator used to combine parts of a component path.
// See https://github.com/elastic/elasticsearch-specification/issues/4183
pub const SEPARATOR: char = ':';

pub struct TypesAndComponents<'a> {
pub model: &'a clients_schema::IndexedModel,
pub components: &'a mut Components,
Expand All @@ -43,14 +47,14 @@ impl<'a> TypesAndComponents<'a> {
let suffix = if duplicate { "_" } else { "" };
let result = ReferenceOr::Reference {
reference: format!(
"#/components/parameters/{}#{}{}",
"#/components/parameters/{}{SEPARATOR}{}{}",
endpoint,
&param.parameter_data_ref().name,
suffix
),
};
self.components.parameters.insert(
format!("{}#{}{}", endpoint, &param.parameter_data_ref().name, suffix),
format!("{}{SEPARATOR}{}{}", endpoint, &param.parameter_data_ref().name, suffix),
ReferenceOr::Item(param),
);
result
Expand All @@ -59,9 +63,9 @@ impl<'a> TypesAndComponents<'a> {
pub fn add_response(&mut self, endpoint: &str, status: StatusCode, response: Response) -> ReferenceOr<Response> {
self.components
.responses
.insert(format!("{}#{}", endpoint, status), ReferenceOr::Item(response));
.insert(format!("{}{SEPARATOR}{}", endpoint, status), ReferenceOr::Item(response));
ReferenceOr::Reference {
reference: format!("#/components/responses/{}#{}", endpoint, status),
reference: format!("#/components/responses/{}{SEPARATOR}{}", endpoint, status),
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ pub fn add_endpoint(
external_value: None,
extensions: Default::default(),
};
openapi_examples.insert(name.clone(), ReferenceOr::Item(openapi_example));
openapi_examples.insert(name.clone(), ReferenceOr::Item(openapi_example));
}
return openapi_examples;
}


let mut request_examples: IndexMap<String, ReferenceOr<Example>> = indexmap! {};
// If this endpoint request has examples in schema.json, convert them to the
// If this endpoint request has examples in schema.json, convert them to the
// OpenAPI format and add them to the endpoint request in the OpenAPI document.
if request.examples.is_some() {
request_examples = get_openapi_examples(request.examples.as_ref().unwrap().clone());
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn add_endpoint(
// TODO: handle binary responses
let response_def = tac.model.get_response(endpoint.response.as_ref().unwrap())?;
let mut response_examples: IndexMap<String, ReferenceOr<Example>> = indexmap! {};
// If this endpoint response has examples in schema.json, convert them to the
// If this endpoint response has examples in schema.json, convert them to the
// OpenAPI format and add them to the endpoint response in the OpenAPI document.
if response_def.examples.is_some() {
response_examples = get_openapi_examples(response_def.examples.as_ref().unwrap().clone());
Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
Loading