@@ -52,7 +52,7 @@ pub struct OpenApiConversion {
52
52
}
53
53
54
54
/// Convert an API model into an OpenAPI v3 schema, optionally filtered for a given flavor
55
- pub fn convert_schema ( mut schema : IndexedModel , config : Configuration ) -> anyhow:: Result < OpenApiConversion > {
55
+ pub fn convert_schema ( mut schema : IndexedModel , config : Configuration , product_meta : IndexMap < String , String > ) -> anyhow:: Result < OpenApiConversion > {
56
56
// Expand generics
57
57
schema = clients_schema:: transform:: expand_generics ( schema, ExpandConfig :: default ( ) ) ?;
58
58
@@ -73,7 +73,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
73
73
schema = clients_schema:: transform:: filter_availability ( schema, filter) ?;
74
74
}
75
75
76
- convert_expanded_schema ( & schema, & config)
76
+ convert_expanded_schema ( & schema, & config, & product_meta )
77
77
}
78
78
79
79
/// Convert an API model into an OpenAPI v3 schema. The input model must have all generics expanded, conversion
@@ -82,7 +82,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
82
82
/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understand it.
83
83
///
84
84
/// [generics in JSON Schema]: https://json-schema.org/blog/posts/dynamicref-and-generics
85
- pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration ) -> anyhow:: Result < OpenApiConversion > {
85
+ pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration , product_meta : & IndexMap < String , String > ) -> anyhow:: Result < OpenApiConversion > {
86
86
let mut openapi = OpenAPI {
87
87
openapi : "3.0.3" . into ( ) ,
88
88
info : info ( model) ,
@@ -120,7 +120,7 @@ pub fn convert_expanded_schema(model: &IndexedModel, config: &Configuration) ->
120
120
continue ;
121
121
}
122
122
}
123
- paths:: add_endpoint ( endpoint, & mut tac, & mut openapi. paths ) ?;
123
+ paths:: add_endpoint ( endpoint, & mut tac, & mut openapi. paths , product_meta ) ?;
124
124
}
125
125
126
126
// // Sort maps to ensure output stability
@@ -180,7 +180,19 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
180
180
}
181
181
}
182
182
183
- pub fn availability_as_extensions ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > ) -> IndexMap < String , serde_json:: Value > {
183
+ pub fn product_meta_as_extensions ( namespace : & str , product_meta : & IndexMap < String , String > ) -> IndexMap < String , Value > {
184
+ let mut result = IndexMap :: new ( ) ;
185
+ let mut additional_namespace= "" . to_string ( ) ;
186
+ if let Some ( meta) = product_meta. get ( namespace) {
187
+ additional_namespace = format ! ( ", {meta}" ) ;
188
+ }
189
+
190
+ let product_str = format ! ( "elasticsearch{additional_namespace}" ) ;
191
+ result. insert ( "x-product-feature" . to_string ( ) , Value :: String ( product_str) ) ;
192
+ result
193
+ }
194
+
195
+ pub fn availability_as_extensions ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > ) -> IndexMap < String , Value > {
184
196
let mut result = IndexMap :: new ( ) ;
185
197
convert_availabilities ( availabilities, flavor, & mut result) ;
186
198
result
0 commit comments