Skip to content

Commit 3fa3af3

Browse files
committed
OpenAPI: use ':' instead of '#' to separate parts of a component path (#4184)
1 parent 5581a3c commit 3fa3af3

File tree

5 files changed

+6310
-6306
lines changed

5 files changed

+6310
-6306
lines changed

compiler-rs/clients_schema_to_openapi/src/components.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use openapiv3::{Components, Parameter, ReferenceOr, RequestBody, Response, Schem
2020

2121
use crate::utils::SchemaName;
2222

23+
// Separator used to combine parts of a component path.
24+
// See https://github.com/elastic/elasticsearch-specification/issues/4183
25+
pub const SEPARATOR: char = ':';
26+
2327
pub struct TypesAndComponents<'a> {
2428
pub model: &'a clients_schema::IndexedModel,
2529
pub components: &'a mut Components,
@@ -43,14 +47,14 @@ impl<'a> TypesAndComponents<'a> {
4347
let suffix = if duplicate { "_" } else { "" };
4448
let result = ReferenceOr::Reference {
4549
reference: format!(
46-
"#/components/parameters/{}#{}{}",
50+
"#/components/parameters/{}{SEPARATOR}{}{}",
4751
endpoint,
4852
&param.parameter_data_ref().name,
4953
suffix
5054
),
5155
};
5256
self.components.parameters.insert(
53-
format!("{}#{}{}", endpoint, &param.parameter_data_ref().name, suffix),
57+
format!("{}{SEPARATOR}{}{}", endpoint, &param.parameter_data_ref().name, suffix),
5458
ReferenceOr::Item(param),
5559
);
5660
result
@@ -59,9 +63,9 @@ impl<'a> TypesAndComponents<'a> {
5963
pub fn add_response(&mut self, endpoint: &str, status: StatusCode, response: Response) -> ReferenceOr<Response> {
6064
self.components
6165
.responses
62-
.insert(format!("{}#{}", endpoint, status), ReferenceOr::Item(response));
66+
.insert(format!("{}{SEPARATOR}{}", endpoint, status), ReferenceOr::Item(response));
6367
ReferenceOr::Reference {
64-
reference: format!("#/components/responses/{}#{}", endpoint, status),
68+
reference: format!("#/components/responses/{}{SEPARATOR}{}", endpoint, status),
6569
}
6670
}
6771

compiler-rs/clients_schema_to_openapi/src/paths.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ pub fn add_endpoint(
132132
external_value: None,
133133
extensions: Default::default(),
134134
};
135-
openapi_examples.insert(name.clone(), ReferenceOr::Item(openapi_example));
135+
openapi_examples.insert(name.clone(), ReferenceOr::Item(openapi_example));
136136
}
137137
return openapi_examples;
138138
}
139139

140140

141141
let mut request_examples: IndexMap<String, ReferenceOr<Example>> = indexmap! {};
142-
// If this endpoint request has examples in schema.json, convert them to the
142+
// If this endpoint request has examples in schema.json, convert them to the
143143
// OpenAPI format and add them to the endpoint request in the OpenAPI document.
144144
if request.examples.is_some() {
145145
request_examples = get_openapi_examples(request.examples.as_ref().unwrap().clone());
@@ -177,7 +177,7 @@ pub fn add_endpoint(
177177
// TODO: handle binary responses
178178
let response_def = tac.model.get_response(endpoint.response.as_ref().unwrap())?;
179179
let mut response_examples: IndexMap<String, ReferenceOr<Example>> = indexmap! {};
180-
// If this endpoint response has examples in schema.json, convert them to the
180+
// If this endpoint response has examples in schema.json, convert them to the
181181
// OpenAPI format and add them to the endpoint response in the OpenAPI document.
182182
if response_def.examples.is_some() {
183183
response_examples = get_openapi_examples(response_def.examples.as_ref().unwrap().clone());
Binary file not shown.

0 commit comments

Comments
 (0)