@@ -40,10 +40,18 @@ pub struct Configuration {
4040 /// be the longest one (with values for all optional parameters), and the other paths will be added
4141 /// at the beginning of the operation's description.
4242 pub merge_multipath_endpoints : bool ,
43+
44+ /// Should we output a redirect map when merging multipath endpoints?
45+ pub multipath_redirects : bool ,
46+ }
47+
48+ pub struct OpenApiConversion {
49+ pub openapi : OpenAPI ,
50+ pub redirects : Option < String > ,
4351}
4452
4553/// Convert an API model into an OpenAPI v3 schema, optionally filtered for a given flavor
46- pub fn convert_schema ( mut schema : IndexedModel , config : Configuration ) -> anyhow:: Result < OpenAPI > {
54+ pub fn convert_schema ( mut schema : IndexedModel , config : Configuration ) -> anyhow:: Result < OpenApiConversion > {
4755 // Expand generics
4856 schema = clients_schema:: transform:: expand_generics ( schema, ExpandConfig :: default ( ) ) ?;
4957
@@ -73,7 +81,7 @@ pub fn convert_schema(mut schema: IndexedModel, config: Configuration) -> anyhow
7381/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understand it.
7482///
7583/// [generics in JSON Schema]: https://json-schema.org/blog/posts/dynamicref-and-generics
76- pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration ) -> anyhow:: Result < OpenAPI > {
84+ pub fn convert_expanded_schema ( model : & IndexedModel , config : & Configuration ) -> anyhow:: Result < OpenApiConversion > {
7785 let mut openapi = OpenAPI {
7886 openapi : "3.0.3" . into ( ) ,
7987 info : info ( model) ,
@@ -129,7 +137,21 @@ pub fn convert_expanded_schema(model: &IndexedModel, config: &Configuration) ->
129137 // comp.security_schemes.sort_keys();
130138 // }
131139
132- Ok ( openapi)
140+ let redirects = if let Some ( redirects) = tac. redirects {
141+ use std:: fmt:: Write ;
142+ let mut result = String :: new ( ) ;
143+ for ( source, target) in redirects. iter ( ) {
144+ writeln ! ( & mut result, "{},{}" , source, target) ?;
145+ }
146+ Some ( result)
147+ } else {
148+ None
149+ } ;
150+
151+ Ok ( OpenApiConversion {
152+ openapi,
153+ redirects,
154+ } )
133155}
134156
135157fn info ( model : & IndexedModel ) -> openapiv3:: Info {
0 commit comments