@@ -41,10 +41,18 @@ pub struct Configuration {
4141 /// be the longest one (with values for all optional parameters), and the other paths will be added
4242 /// at the beginning of the operation's description.
4343 pub merge_multipath_endpoints : bool ,
44+
45+ /// Should we output a redirect map when merging multipath endpoints?
46+ pub multipath_redirects : bool ,
47+ }
48+
49+ pub struct OpenApiConversion {
50+ pub openapi : OpenAPI ,
51+ pub redirects : Option < String > ,
4452}
4553
4654/// 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 > {
55+ pub fn convert_schema ( mut schema : IndexedModel , config : Configuration ) -> anyhow:: Result < OpenApiConversion > {
4856 // Expand generics
4957 schema = clients_schema:: transform:: expand_generics ( schema, ExpandConfig :: default ( ) ) ?;
5058
@@ -74,7 +82,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
7482/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understand it.
7583///
7684/// [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 > {
85+ pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration ) -> anyhow:: Result < OpenApiConversion > {
7886 let mut openapi = OpenAPI {
7987 openapi : "3.0.3" . into ( ) ,
8088 info : info ( model) ,
@@ -130,7 +138,21 @@ pub fn convert_expanded_schema(model: &IndexedModel, config: &Configuration) ->
130138 // comp.security_schemes.sort_keys();
131139 // }
132140
133- Ok ( openapi)
141+ let redirects = if let Some ( redirects) = tac. redirects {
142+ use std:: fmt:: Write ;
143+ let mut result = String :: new ( ) ;
144+ for ( source, target) in redirects. iter ( ) {
145+ writeln ! ( & mut result, "{},{}" , source, target) ?;
146+ }
147+ Some ( result)
148+ } else {
149+ None
150+ } ;
151+
152+ Ok ( OpenApiConversion {
153+ openapi,
154+ redirects,
155+ } )
134156}
135157
136158fn info ( model : & IndexedModel ) -> openapiv3:: Info {
@@ -183,7 +205,7 @@ pub fn convert_availabilities(availabilities: &Option<Availabilities>, flavor: &
183205 let exp_since = format ! ( "Technical preview{since_str}" ) ;
184206 result. insert ( "x-state" . to_string ( ) , Value :: String ( exp_since) ) ;
185207 }
186- Stability :: Stable => {
208+ Stability :: Stable => {
187209 let stable_since = format ! ( "Generally available{since_str}" ) ;
188210 result. insert ( "x-state" . to_string ( ) , Value :: String ( stable_since) ) ;
189211 }
0 commit comments