@@ -337,11 +337,12 @@ List<PostmanRequestItem> getPostmanRequests(CodegenOperation codegenOperation) {
337
337
338
338
List <PostmanRequestItem > items = new ArrayList <>();
339
339
340
- if (codegenOperation .getHasBodyParam ()) {
340
+ if (codegenOperation .getHasBodyParam ()) {
341
341
// operation with bodyParam
342
342
if (requestParameterGeneration .equalsIgnoreCase ("Schema" )) {
343
343
// get from schema
344
- items .add (new PostmanRequestItem (codegenOperation .summary , new ExampleJsonHelper ().getJsonFromSchema (codegenOperation .bodyParam )));
344
+ items .add (new PostmanRequestItem (codegenOperation .summary , new ExampleJsonHelper ().getJsonFromSchema (codegenOperation .bodyParam ),
345
+ codegenOperation .httpMethod ));
345
346
} else {
346
347
// get from examples
347
348
if (codegenOperation .bodyParam .getContent ().get ("application/json" ) != null &&
@@ -362,44 +363,60 @@ List<PostmanRequestItem> getPostmanRequests(CodegenOperation codegenOperation) {
362
363
exampleAsString = new ExampleJsonHelper ().getJsonFromExample (entry .getValue ());
363
364
exampleName = entry .getValue ().getSummary ();
364
365
}
365
- items .add (new PostmanRequestItem (exampleName , exampleAsString , entry .getKey ()));
366
+ items .add (new PostmanRequestItem (exampleName , exampleAsString , entry .getKey (), codegenOperation . httpMethod ));
366
367
}
367
368
} else if (codegenOperation .bodyParam .example != null ) {
368
369
// find in bodyParam example
369
- items .add (new PostmanRequestItem (codegenOperation .summary , new ExampleJsonHelper ().formatJson (codegenOperation .bodyParam .example )));
370
+ items .add (new PostmanRequestItem (codegenOperation .summary , new ExampleJsonHelper ().formatJson (codegenOperation .bodyParam .example ),
371
+ codegenOperation .httpMethod ));
370
372
} else if (codegenOperation .bodyParam .getSchema () != null ) {
371
373
// find in schema example
372
374
String exampleAsString = new ExampleJsonHelper ().formatJson (codegenOperation .bodyParam .getSchema ().getExample ());
373
- items .add (new PostmanRequestItem (codegenOperation .summary , exampleAsString ));
375
+ items .add (new PostmanRequestItem (codegenOperation .summary , exampleAsString , codegenOperation . httpMethod ));
374
376
} else {
375
377
// example not found
376
378
// get from schema
377
- items .add (new PostmanRequestItem (codegenOperation .summary , new ExampleJsonHelper ().getJsonFromSchema (codegenOperation .bodyParam )));
379
+ items .add (new PostmanRequestItem (codegenOperation .summary , new ExampleJsonHelper ().getJsonFromSchema (codegenOperation .bodyParam ), codegenOperation . httpMethod ));
378
380
379
381
}
380
382
}
381
383
} else {
382
384
// operation without bodyParam
383
- items .add (new PostmanRequestItem (codegenOperation .summary , "" ));
385
+ PostmanRequestItem postmanRequestItem = new PostmanRequestItem (codegenOperation .summary , "" , codegenOperation .httpMethod );
386
+ items .add (postmanRequestItem );
384
387
}
385
388
386
389
// Grabbing responses
387
390
List <CodegenResponse > responses = codegenOperation .responses ;
388
391
List <PostmanResponse > allPostmanResponses = new ArrayList <>();
389
392
for (CodegenResponse response : responses ) {
390
- List <PostmanResponse > postmanResponses = getResponseExamples (response , response .message );
391
- allPostmanResponses .addAll (postmanResponses );
393
+ List <PostmanResponse > postmanResponses = getResponseExamples (response , response .message );
394
+ allPostmanResponses .addAll (postmanResponses );
392
395
}
393
396
394
397
// Adding responses to corresponding requests
395
- for (PostmanRequestItem item : items ){
396
- List <PostmanResponse > postmanResponses = allPostmanResponses .stream ().filter ( r -> Objects .equals (r .getId (), item .getId ())).collect (Collectors .toList ());
397
- if (!postmanResponses .isEmpty ()){
398
+ for (PostmanRequestItem item : items ) {
399
+ List <PostmanResponse > postmanResponses = allPostmanResponses .stream ().filter (r -> Objects .equals (r .getId (), item .getId ())).collect (Collectors .toList ());
400
+ if (!postmanResponses .isEmpty ()) {
398
401
postmanResponses .forEach (r -> r .setOriginalRequest (item ));
399
402
item .addResponses (postmanResponses );
403
+ } else {
404
+ // no matching response example
405
+ if (item .getHttpMethod () != null && item .getHttpMethod ().equals ("GET" )) {
406
+ // in case of GET use first response example
407
+ if (allPostmanResponses .size () > 0 ) {
408
+ PostmanResponse postmanResponse = allPostmanResponses .stream ()
409
+ .findFirst ()
410
+ .orElse (null );
411
+
412
+ if (postmanResponse != null ) {
413
+ postmanResponse .setOriginalRequest (item );
414
+ item .addResponse (postmanResponse );
415
+ }
416
+ }
417
+ }
400
418
}
401
419
}
402
-
403
420
return items ;
404
421
}
405
422
0 commit comments