@@ -167,7 +167,7 @@ impl Spec {
167
167
}
168
168
169
169
/// Resolve a reference or schema to a resolved schema
170
- pub fn resolve_schema < P : AsRef < Path > > ( & self , doc_file : P , ref_or_schema : & ReferenceOr < Schema > ) -> Result < ResolvedSchema > {
170
+ fn resolve_schema < P : AsRef < Path > > ( & self , doc_file : P , ref_or_schema : & ReferenceOr < Schema > ) -> Result < ResolvedSchema > {
171
171
match ref_or_schema {
172
172
ReferenceOr :: Item ( schema) => Ok ( ResolvedSchema {
173
173
ref_key : None ,
@@ -177,15 +177,6 @@ impl Spec {
177
177
}
178
178
}
179
179
180
- /// Resolve a collection of references or schemas to a collection of resolved schemas
181
- pub fn resolve_schemas < P : AsRef < Path > > ( & self , doc_file : P , ref_or_schemas : & [ ReferenceOr < Schema > ] ) -> Result < Vec < ResolvedSchema > > {
182
- let mut resolved = Vec :: new ( ) ;
183
- for schema in ref_or_schemas {
184
- resolved. push ( self . resolve_schema ( & doc_file, schema) ?) ;
185
- }
186
- Ok ( resolved)
187
- }
188
-
189
180
/// Resolve a collection of references or schemas to a collection of resolved schemas
190
181
pub fn resolve_schema_map < P : AsRef < Path > > (
191
182
& self ,
@@ -218,14 +209,14 @@ impl Spec {
218
209
Ok ( resolved)
219
210
}
220
211
221
- pub fn resolve_parameter ( & self , doc_file : & Path , parameter : & ReferenceOr < Parameter > ) -> Result < Parameter > {
212
+ fn resolve_parameter ( & self , doc_file : & Path , parameter : & ReferenceOr < Parameter > ) -> Result < Parameter > {
222
213
match parameter {
223
214
ReferenceOr :: Item ( param) => Ok ( param. clone ( ) ) ,
224
215
ReferenceOr :: Reference { reference, .. } => self . resolve_parameter_ref ( doc_file, reference. clone ( ) ) ,
225
216
}
226
217
}
227
218
228
- pub fn resolve_parameters ( & self , doc_file : & Path , parameters : & [ ReferenceOr < Parameter > ] ) -> Result < Vec < Parameter > > {
219
+ fn resolve_parameters ( & self , doc_file : & Path , parameters : & [ ReferenceOr < Parameter > ] ) -> Result < Vec < Parameter > > {
229
220
let mut resolved = Vec :: new ( ) ;
230
221
for param in parameters {
231
222
resolved. push ( self . resolve_parameter ( doc_file, param) ?) ;
@@ -234,18 +225,37 @@ impl Spec {
234
225
}
235
226
236
227
// only operations from listed input files
237
- pub fn operations ( & self ) -> Result < Vec < WebOperation > > {
238
- let mut operations: Vec < WebOperation > = Vec :: new ( ) ;
228
+ fn operations_unresolved ( & self ) -> Result < Vec < WebOperationUnresolved > > {
229
+ let mut operations: Vec < WebOperationUnresolved > = Vec :: new ( ) ;
239
230
for ( doc_file, doc) in self . docs ( ) {
240
231
if self . is_input_file ( & doc_file) {
241
232
let paths = self . resolve_path_map ( doc_file, doc. paths ( ) ) ?;
242
233
for ( path, item) in & paths {
243
- operations. extend ( path_operations ( doc_file, path, item) )
234
+ operations. extend ( path_operations_unresolved ( doc_file, path, item) )
244
235
}
245
236
}
246
237
}
247
238
Ok ( operations)
248
239
}
240
+
241
+ // only operations from listed input files
242
+ pub fn operations ( & self ) -> Result < Vec < WebOperation > > {
243
+ self . operations_unresolved ( ) ?
244
+ . into_iter ( )
245
+ . map ( {
246
+ |op| {
247
+ Ok ( WebOperation {
248
+ id : op. id ,
249
+ path : op. path ,
250
+ verb : op. verb ,
251
+ parameters : self . resolve_parameters ( & op. doc_file , & op. parameters ) ?,
252
+ responses : op. responses ,
253
+ examples : op. examples ,
254
+ } )
255
+ }
256
+ } )
257
+ . collect ( )
258
+ }
249
259
}
250
260
251
261
type Result < T , E = Error > = std:: result:: Result < T , E > ;
@@ -330,7 +340,7 @@ pub mod openapi {
330
340
match item {
331
341
ReferenceOr :: Reference { reference, .. } => list. push ( TypedReference :: PathItem ( reference. clone ( ) ) ) ,
332
342
ReferenceOr :: Item ( item) => {
333
- for operation in path_operations ( & doc_file, path, item) {
343
+ for operation in path_operations_unresolved ( & doc_file, path, item) {
334
344
// parameters
335
345
for param in & operation. parameters {
336
346
match param {
@@ -386,7 +396,8 @@ pub mod openapi {
386
396
}
387
397
}
388
398
389
- pub struct WebOperation {
399
+ // contains unresolved parameters
400
+ struct WebOperationUnresolved {
390
401
pub doc_file : PathBuf ,
391
402
pub id : Option < String > ,
392
403
pub path : String ,
@@ -396,6 +407,16 @@ pub struct WebOperation {
396
407
pub examples : MsExamples ,
397
408
}
398
409
410
+ // contains resolved parameters
411
+ pub struct WebOperation {
412
+ pub id : Option < String > ,
413
+ pub path : String ,
414
+ pub verb : WebVerb ,
415
+ pub parameters : Vec < Parameter > ,
416
+ pub responses : IndexMap < StatusCode , Response > ,
417
+ pub examples : MsExamples ,
418
+ }
419
+
399
420
impl WebOperation {
400
421
pub fn rust_module_name ( & self ) -> Option < String > {
401
422
match & self . id {
@@ -462,7 +483,7 @@ struct OperationVerb<'a> {
462
483
pub verb : WebVerb ,
463
484
}
464
485
465
- pub fn path_operations < P : AsRef < Path > > ( doc_file : P , path : & str , item : & PathItem ) -> Vec < WebOperation > {
486
+ fn path_operations_unresolved < P : AsRef < Path > > ( doc_file : P , path : & str , item : & PathItem ) -> Vec < WebOperationUnresolved > {
466
487
vec ! [
467
488
OperationVerb {
468
489
operation: item. get. as_ref( ) ,
@@ -498,7 +519,7 @@ pub fn path_operations<P: AsRef<Path>>(doc_file: P, path: &str, item: &PathItem)
498
519
Some ( op) => {
499
520
let mut parameters = item. parameters . clone ( ) ;
500
521
parameters. append ( & mut op. parameters . clone ( ) ) ;
501
- Some ( WebOperation {
522
+ Some ( WebOperationUnresolved {
502
523
doc_file : doc_file. as_ref ( ) . to_path_buf ( ) ,
503
524
id : op. operation_id . clone ( ) ,
504
525
path : path. to_string ( ) ,
@@ -588,7 +609,6 @@ mod tests {
588
609
#[ test]
589
610
fn test_function_name_from_operation_id ( ) {
590
611
let operation = WebOperation {
591
- doc_file : PathBuf :: from ( "" ) ,
592
612
id : Some ( "PrivateClouds_CreateOrUpdate" . to_owned ( ) ) ,
593
613
path : "/horse" . to_owned ( ) ,
594
614
verb : WebVerb :: Get ,
@@ -603,7 +623,6 @@ mod tests {
603
623
#[ test]
604
624
fn test_function_name_from_verb_and_path ( ) {
605
625
let operation = WebOperation {
606
- doc_file : PathBuf :: from ( "" ) ,
607
626
id : None ,
608
627
path : "/horse" . to_owned ( ) ,
609
628
verb : WebVerb :: Get ,
@@ -618,7 +637,6 @@ mod tests {
618
637
#[ test]
619
638
fn test_function_name_with_no_module_name ( ) {
620
639
let operation = WebOperation {
621
- doc_file : PathBuf :: from ( "" ) ,
622
640
id : Some ( "PerformConnectivityCheck" . to_owned ( ) ) ,
623
641
path : "/horse" . to_owned ( ) ,
624
642
verb : WebVerb :: Put ,
0 commit comments