@@ -67,6 +67,8 @@ pub struct GenerationSettings {
6767 post_hook_async : Option < TokenStream > ,
6868 extra_derives : Vec < String > ,
6969
70+ operation_id_strategy : OperationIdStrategy ,
71+
7072 map_type : Option < String > ,
7173 unknown_crates : UnknownPolicy ,
7274 crates : BTreeMap < String , CrateSpec > ,
@@ -112,6 +114,23 @@ impl Default for TagStyle {
112114 }
113115}
114116
117+ /// Style for handing operations that do not have an operation ID.
118+ #[ derive( Copy , Clone ) ]
119+ pub enum OperationIdStrategy {
120+ /// The default behaviour. Reject when any operation on the resulting
121+ /// client does not have an operation ID.
122+ RejectMissing ,
123+ /// Omit any operation on the resulting client that does not have an
124+ /// operation ID.
125+ OmitMissing ,
126+ }
127+
128+ impl Default for OperationIdStrategy {
129+ fn default ( ) -> Self {
130+ Self :: RejectMissing
131+ }
132+ }
133+
115134impl GenerationSettings {
116135 /// Create new generator settings with default values.
117136 pub fn new ( ) -> Self {
@@ -241,6 +260,16 @@ impl GenerationSettings {
241260 self . map_type = Some ( map_type. to_string ( ) ) ;
242261 self
243262 }
263+
264+ /// Set the strategy to be used when encountering operations that do not
265+ /// have an operation ID.
266+ pub fn with_operation_id_strategy (
267+ & mut self ,
268+ operation_id_strategy : OperationIdStrategy ,
269+ ) -> & mut Self {
270+ self . operation_id_strategy = operation_id_strategy;
271+ self
272+ }
244273}
245274
246275impl Default for Generator {
@@ -306,7 +335,7 @@ impl Generator {
306335
307336 /// Emit a [TokenStream] containing the generated client code.
308337 pub fn generate_tokens ( & mut self , spec : & OpenAPI ) -> Result < TokenStream > {
309- validate_openapi ( spec) ?;
338+ validate_openapi ( spec, self . settings . operation_id_strategy ) ?;
310339
311340 // Convert our components dictionary to schemars
312341 let schemas = spec. components . iter ( ) . flat_map ( |components| {
@@ -328,8 +357,9 @@ impl Generator {
328357 ( path. as_str ( ) , method, operation, & item. parameters )
329358 } )
330359 } )
331- . map ( |( path, method, operation, path_parameters) | {
360+ . filter_map ( |( path, method, operation, path_parameters) | {
332361 self . process_operation ( operation, & spec. components , path, method, path_parameters)
362+ . transpose ( )
333363 } )
334364 . collect :: < Result < Vec < _ > > > ( ) ?;
335365
@@ -674,7 +704,7 @@ fn validate_openapi_spec_version(spec_version: &str) -> Result<()> {
674704}
675705
676706/// Do some very basic checks of the OpenAPI documents.
677- pub fn validate_openapi ( spec : & OpenAPI ) -> Result < ( ) > {
707+ pub fn validate_openapi ( spec : & OpenAPI , operation_id_strategy : OperationIdStrategy ) -> Result < ( ) > {
678708 validate_openapi_spec_version ( spec. openapi . as_str ( ) ) ?;
679709
680710 let mut opids = HashSet :: new ( ) ;
@@ -695,10 +725,15 @@ pub fn validate_openapi(spec: &OpenAPI) -> Result<()> {
695725 ) ) ) ;
696726 }
697727 } else {
698- return Err ( Error :: UnexpectedFormat ( format ! (
699- "path {} is missing operation ID" ,
700- p. 0 ,
701- ) ) ) ;
728+ match operation_id_strategy {
729+ OperationIdStrategy :: RejectMissing => {
730+ return Err ( Error :: UnexpectedFormat ( format ! (
731+ "path {} is missing operation ID" ,
732+ p. 0 ,
733+ ) ) ) ;
734+ }
735+ OperationIdStrategy :: OmitMissing => { }
736+ }
702737 }
703738 Ok ( ( ) )
704739 } )
0 commit comments