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