@@ -44,7 +44,7 @@ pub struct Configuration {
4444}
4545
4646/// Convert an API model into an OpenAPI v3 schema, optionally filtered for a given flavor
47- pub fn convert_schema ( mut schema : IndexedModel , config : Configuration ) -> anyhow:: Result < OpenAPI > {
47+ pub fn convert_schema ( mut schema : IndexedModel , config : Configuration , product_meta : IndexMap < String , String > ) -> anyhow:: Result < OpenAPI > {
4848 // Expand generics
4949 schema = clients_schema:: transform:: expand_generics ( schema, ExpandConfig :: default ( ) ) ?;
5050
@@ -65,7 +65,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
6565 schema = clients_schema:: transform:: filter_availability ( schema, filter) ?;
6666 }
6767
68- convert_expanded_schema ( & schema, & config)
68+ convert_expanded_schema ( & schema, & config, & product_meta )
6969}
7070
7171/// Convert an API model into an OpenAPI v3 schema. The input model must have all generics expanded, conversion
@@ -74,7 +74,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
7474/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understand it.
7575///
7676/// [generics in JSON Schema]: https://json-schema.org/blog/posts/dynamicref-and-generics
77- pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration ) -> anyhow:: Result < OpenAPI > {
77+ pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration , product_meta : & IndexMap < String , String > ) -> anyhow:: Result < OpenAPI > {
7878 let mut openapi = OpenAPI {
7979 openapi : "3.0.3" . into ( ) ,
8080 info : info ( model) ,
@@ -112,7 +112,7 @@ pub fn convert_expanded_schema(model: &IndexedModel, config: &Configuration) ->
112112 continue ;
113113 }
114114 }
115- paths:: add_endpoint ( endpoint, & mut tac, & mut openapi. paths ) ?;
115+ paths:: add_endpoint ( endpoint, & mut tac, & mut openapi. paths , product_meta ) ?;
116116 }
117117
118118 // // Sort maps to ensure output stability
@@ -158,15 +158,12 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
158158 }
159159}
160160
161- pub fn product_meta_as_extensions ( namespace : & str ) -> IndexMap < String , Value > {
161+ pub fn product_meta_as_extensions ( namespace : & str , product_meta : & IndexMap < String , String > ) -> IndexMap < String , Value > {
162162 let mut result = IndexMap :: new ( ) ;
163- let additional_namespace = match namespace {
164- "inference" => { ", machine-learning" }
165- "ml" => { ", machine-learning" }
166- "fleet" => { ", fleet" }
167- "logstash" => { ", logstash" }
168- & _ => { "" }
169- } ;
163+ let mut additional_namespace= "" . to_string ( ) ;
164+ if let Some ( meta) = product_meta. get ( namespace) {
165+ additional_namespace = format ! ( ", {meta}" ) ;
166+ }
170167
171168 let product_str = format ! ( "elasticsearch{additional_namespace}" ) ;
172169 result. insert ( "x-product-feature" . to_string ( ) , Value :: String ( product_str) ) ;
0 commit comments