@@ -25,7 +25,7 @@ use indexmap::IndexMap;
2525
2626use clients_schema:: { Availabilities , Availability , Flavor , IndexedModel , Stability , Visibility } ;
2727use openapiv3:: { Components , OpenAPI } ;
28- use serde_json:: Value ;
28+ use serde_json:: { Map , Value } ;
2929use clients_schema:: transform:: ExpandConfig ;
3030use crate :: components:: TypesAndComponents ;
3131
@@ -56,7 +56,7 @@ pub struct OpenApiConversion {
5656}
5757
5858/// 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 > {
6060 // Expand generics
6161 schema = clients_schema:: transform:: expand_generics ( schema, ExpandConfig :: default ( ) ) ?;
6262
@@ -77,7 +77,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
7777 schema = clients_schema:: transform:: filter_availability ( schema, filter) ?;
7878 }
7979
80- convert_expanded_schema ( & schema, & config)
80+ convert_expanded_schema ( & schema, & config, & product_meta )
8181}
8282
8383/// 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
8686/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understand it.
8787///
8888/// [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 > {
9090 let mut openapi = OpenAPI {
9191 openapi : "3.0.3" . into ( ) ,
9292 info : info ( model) ,
@@ -124,7 +124,7 @@ pub fn convert_expanded_schema(model: &IndexedModel, config: &Configuration) ->
124124 continue ;
125125 }
126126 }
127- paths:: add_endpoint ( endpoint, & mut tac, & mut openapi. paths ) ?;
127+ paths:: add_endpoint ( endpoint, & mut tac, & mut openapi. paths , product_meta ) ?;
128128 }
129129
130130 // // Sort maps to ensure output stability
@@ -184,7 +184,24 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
184184 }
185185}
186186
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+ let mut product_feature_list: Vec < Value > = Vec :: new ( ) ;
196+ let mut product_feature: Map < String , Value > = Map :: new ( ) ;
197+ product_feature. insert ( "name" . to_string ( ) , Value :: String ( "product_name" . to_string ( ) ) ) ;
198+ product_feature. insert ( "content" . to_string ( ) , Value :: String ( product_str) ) ;
199+ product_feature_list. push ( Value :: Object ( product_feature) ) ;
200+ result. insert ( "x-metaTags" . to_string ( ) , Value :: Array ( product_feature_list) ) ;
201+ result
202+ }
203+
204+ pub fn availability_as_extensions ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > ) -> IndexMap < String , Value > {
188205 let mut result = IndexMap :: new ( ) ;
189206 convert_availabilities ( availabilities, flavor, & mut result) ;
190207 result
0 commit comments