@@ -337,11 +337,12 @@ List<PostmanRequestItem> getPostmanRequests(CodegenOperation codegenOperation) {
337337
338338 List <PostmanRequestItem > items = new ArrayList <>();
339339
340- if (codegenOperation .getHasBodyParam ()) {
340+ if (codegenOperation .getHasBodyParam ()) {
341341 // operation with bodyParam
342342 if (requestParameterGeneration .equalsIgnoreCase ("Schema" )) {
343343 // 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 ));
345346 } else {
346347 // get from examples
347348 if (codegenOperation .bodyParam .getContent ().get ("application/json" ) != null &&
@@ -362,44 +363,60 @@ List<PostmanRequestItem> getPostmanRequests(CodegenOperation codegenOperation) {
362363 exampleAsString = new ExampleJsonHelper ().getJsonFromExample (entry .getValue ());
363364 exampleName = entry .getValue ().getSummary ();
364365 }
365- items .add (new PostmanRequestItem (exampleName , exampleAsString , entry .getKey ()));
366+ items .add (new PostmanRequestItem (exampleName , exampleAsString , entry .getKey (), codegenOperation . httpMethod ));
366367 }
367368 } else if (codegenOperation .bodyParam .example != null ) {
368369 // 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 ));
370372 } else if (codegenOperation .bodyParam .getSchema () != null ) {
371373 // find in schema example
372374 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 ));
374376 } else {
375377 // example not found
376378 // 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 ));
378380
379381 }
380382 }
381383 } else {
382384 // operation without bodyParam
383- items .add (new PostmanRequestItem (codegenOperation .summary , "" ));
385+ PostmanRequestItem postmanRequestItem = new PostmanRequestItem (codegenOperation .summary , "" , codegenOperation .httpMethod );
386+ items .add (postmanRequestItem );
384387 }
385388
386389 // Grabbing responses
387390 List <CodegenResponse > responses = codegenOperation .responses ;
388391 List <PostmanResponse > allPostmanResponses = new ArrayList <>();
389392 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 );
392395 }
393396
394397 // 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 ()) {
398401 postmanResponses .forEach (r -> r .setOriginalRequest (item ));
399402 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+ }
400418 }
401419 }
402-
403420 return items ;
404421 }
405422
0 commit comments