Skip to content

Commit c46fb09

Browse files
committed
merge master
2 parents 7efcc0a + 79b1cc5 commit c46fb09

File tree

376 files changed

+3017
-1400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

376 files changed

+3017
-1400
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostmanCollectionCodegen.java

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.*;
2525
import java.util.regex.Matcher;
2626
import java.util.regex.Pattern;
27+
import java.util.stream.Collectors;
2728

2829
/**
2930
* OpenAPI generator for Postman Collection format v2.1
@@ -389,12 +390,14 @@ List<PostmanRequestItem> getPostmanRequests(CodegenOperation codegenOperation) {
389390
String exampleRef = entry.getValue().get$ref();
390391
Example example = this.openAPI.getComponents().getExamples().get(extractExampleByName(exampleRef));
391392
String exampleAsString = getJsonFromExample(example);
393+
String exampleName = entry.getKey();
392394

393-
items.add(new PostmanRequestItem(example.getSummary(), exampleAsString));
395+
items.add(new PostmanRequestItem(exampleName, example.getSummary(), exampleAsString));
394396
} else if (entry.getValue().getValue() != null && entry.getValue().getValue() instanceof ObjectNode) {
395397
// find inline
396398
String exampleAsString = convertToJson((ObjectNode) entry.getValue().getValue());
397-
items.add(new PostmanRequestItem(entry.getKey(), exampleAsString));
399+
String exampleName = entry.getKey();
400+
items.add(new PostmanRequestItem(exampleName, entry.getKey(), exampleAsString));
398401
}
399402
}
400403
} else if (codegenOperation.bodyParam.example != null) {
@@ -416,6 +419,24 @@ List<PostmanRequestItem> getPostmanRequests(CodegenOperation codegenOperation) {
416419
items.add(new PostmanRequestItem(codegenOperation.summary, ""));
417420
}
418421

422+
// Grabbing responses
423+
List<CodegenResponse> responses = codegenOperation.responses;
424+
List<PostmanResponse> allPostmanResponses = new ArrayList<>();
425+
for (CodegenResponse response : responses) {
426+
List<PostmanResponse> postmanResponses = getResponseExamples(response, response.message);
427+
allPostmanResponses.addAll(postmanResponses);
428+
}
429+
430+
// Adding responses to corresponding requests
431+
for(PostmanRequestItem item: items){
432+
List<PostmanResponse> postmanResponses = allPostmanResponses.stream().filter( r -> Objects.equals(r.getId(), item.getId())).collect(Collectors.toList());
433+
if(!postmanResponses.isEmpty()){
434+
postmanResponses.forEach(r -> r.setOriginalRequest(item));
435+
item.addResponses(postmanResponses);
436+
}
437+
}
438+
439+
419440
return items;
420441
}
421442

@@ -454,6 +475,37 @@ List<PostmanRequestItem> setPostmanIsoTimestamp(List<PostmanRequestItem> postman
454475
return postmanRequests;
455476
}
456477

478+
List<PostmanResponse> getResponseExamples(CodegenResponse codegenResponse, String message) {
479+
List<PostmanResponse> postmanResponses = new ArrayList<>();
480+
481+
if (codegenResponse.getContent() != null && codegenResponse.getContent().get("application/json") != null &&
482+
codegenResponse.getContent().get("application/json").getExamples() != null) {
483+
484+
var examples = codegenResponse.getContent().get("application/json").getExamples();
485+
for (Map.Entry<String, Example> entry : examples.entrySet()) {
486+
String key = entry.getKey();
487+
String ref = entry.getValue().get$ref();
488+
489+
String response;
490+
if (ref != null) {
491+
// get example by $ref
492+
Example example = this.openAPI.getComponents().getExamples().get(extractExampleByName(ref));
493+
response = getJsonFromExample(example);
494+
} else {
495+
// get inline example
496+
response = getJsonFromExample(entry.getValue());
497+
}
498+
postmanResponses.add(new PostmanResponse(key, codegenResponse, message, response));
499+
}
500+
501+
} else if (codegenResponse.getContent() != null) {
502+
// TODO : Implement
503+
}
504+
505+
return postmanResponses;
506+
}
507+
508+
457509
/**
458510
* Returns human-friendly help for the generator. Provide the consumer with help
459511
* tips, parameters here
@@ -836,17 +888,65 @@ public String getPostmanType(CodegenProperty codegenProperty) {
836888
@Setter
837889
public class PostmanRequestItem {
838890

891+
private String id;
839892
private String name;
840893
private String body;
894+
private List<PostmanResponse> responses;
895+
896+
private PostmanRequestItem originalRequest;
841897

842898
public PostmanRequestItem() {
843899
}
844900

901+
public PostmanRequestItem(String id, String name, String body) {
902+
this.id = id;
903+
this.name = name;
904+
this.body = body;
905+
}
906+
845907
public PostmanRequestItem(String name, String body) {
846908
this.name = name;
847909
this.body = body;
848910
}
849911

912+
public void addResponses(List<PostmanResponse> responses) {
913+
if(this.responses == null) { this.responses = new ArrayList<>(); }
914+
915+
this.responses.addAll(responses);
916+
}
917+
918+
}
919+
920+
@Getter
921+
@Setter
922+
public class PostmanResponse {
923+
924+
private String id;
925+
private String code;
926+
private String status;
927+
private String name;
928+
private String body;
929+
private PostmanRequestItem originalRequest;
930+
931+
public PostmanResponse(String id, CodegenResponse response, String name, String body) {
932+
this.id = id;
933+
this.code = response.code;
934+
this.status = PostmanCollectionCodegen.this.getStatus(response);
935+
this.name = name;
936+
this.body = body;
937+
this.originalRequest = null; // Setting this here explicitly for clarity
938+
}
939+
940+
941+
public PostmanRequestItem getOriginalRequest() {
942+
return originalRequest;
943+
}
944+
945+
public void setOriginalRequest(PostmanRequestItem originalRequest) {
946+
this.originalRequest = originalRequest;
947+
}
948+
949+
850950
}
851951

852952
@Getter

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/StaticDocCodegen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public StaticDocCodegen() {
7474
outputFolder + "/assets/images", "logo.png"));
7575
supportingFiles.add(new SupportingFile("assets/js/bootstrap.js",
7676
outputFolder + "/assets/js", "bootstrap.js"));
77-
supportingFiles.add(new SupportingFile("assets/js/jquery-1.8.3.min.js",
78-
outputFolder + "/assets/js", "jquery-1.8.3.min.js"));
77+
supportingFiles.add(new SupportingFile("assets/js/jquery-3.7.1.min.js",
78+
outputFolder + "/assets/js", "jquery-3.7.1.min.js"));
7979
supportingFiles.add(new SupportingFile("assets/js/main.js",
8080
outputFolder + "/assets/js", "main.js"));
8181
supportingFiles.add(new SupportingFile("index.mustache",

modules/openapi-generator/src/main/resources/JavaSpring/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{/allowableValues}}
3131
{{/gson}}
3232

33-
private {{{dataType}}} value;
33+
private final {{{dataType}}} value;
3434

3535
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{dataType}}} value) {
3636
this.value = value;

modules/openapi-generator/src/main/resources/JavaSpring/enumOuterClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatyp
3131
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
3232
{{/gson}}
3333

34-
private {{{dataType}}} value;
34+
private final {{{dataType}}} value;
3535

3636
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
3737
this.value = value;

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ namespace {{packageName}}.{{apiPackage}}
382382
uriBuilderLocalVar.Host = HttpClient.BaseAddress{{nrt!}}.Host;
383383
uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port;
384384
uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme;
385-
uriBuilderLocalVar.Path = string.Concat(HttpClient.BaseAddress.AbsolutePath, "{{{path}}}");
385+
uriBuilderLocalVar.Path = HttpClient.BaseAddress.AbsolutePath == "/"
386+
? "{{{path}}}"
387+
: string.Concat(HttpClient.BaseAddress.AbsolutePath, "{{{path}}}");
386388
{{/servers}}
387389
{{#servers}}
388390
{{#-first}}

modules/openapi-generator/src/main/resources/openapi-static/assets/js/jquery-1.8.3.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

modules/openapi-generator/src/main/resources/openapi-static/assets/js/jquery-3.7.1.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/openapi-generator/src/main/resources/openapi-static/index.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css" media="screen">
77
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap-responsive.css" media="screen">
88
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
9-
<script src="assets/js/jquery-1.8.3.min.js" type="text/javascript"></script>
9+
<script src="assets/js/jquery-3.7.1.min.js" type="text/javascript"></script>
1010
<script src="assets/js/main.js" type="text/javascript"></script>
1111

1212
<title>REST API Resources</title>

modules/openapi-generator/src/main/resources/postman-collection/item.mustache

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,23 @@
55
{{#vendorExtensions.postmanRequests}}
66
{
77
"name": "{{{name}}}",
8-
"request": {
9-
"method": "{{httpMethod}}",
10-
"header": [
11-
{{#headerParams}}
12-
{
13-
"key": "{{baseName}}",
14-
"value": "{{schema.defaultValue}}",
15-
"description": "{{{description}}}",
16-
"disabled": {{#schema.defaultValue}}false{{/schema.defaultValue}}{{^schema.defaultValue}}true{{/schema.defaultValue}}
17-
}{{^-last}},{{/-last}}
18-
{{/headerParams}}
19-
],
20-
"body": {
21-
"mode": "raw",
22-
"raw": "{{{body}}}",
23-
"options": {
24-
"raw": {
25-
"language": "json"
26-
}
27-
}
28-
},
29-
"url": {
30-
"raw": "{{=<% %>=}}{{baseUrl}}<%={{ }}=%>{{{path}}}",
31-
"host": [
32-
"{{=<% %>=}}{{baseUrl}}<%={{ }}=%>"
33-
],
34-
"path": [
35-
{{#vendorExtensions.pathSegments}}
36-
"{{.}}"{{^-last}},{{/-last}}
37-
{{/vendorExtensions.pathSegments}}
38-
],
39-
"variable": [
40-
{{#pathParams}}
41-
{
42-
"key": "{{paramName}}",
43-
"value": "{{defaultValue}}",
44-
"description": "{{{description}}}"
45-
}{{^-last}},{{/-last}}
46-
{{/pathParams}}
47-
],
48-
"query": [
49-
{{#queryParams}}
50-
{
51-
"key": "{{paramName}}",
52-
"value": "{{example}}",
53-
"description": "{{{description}}}",
54-
"disabled": {{#required}}false{{/required}}{{^required}}true{{/required}}
55-
}{{^-last}},{{/-last}}
56-
{{/queryParams}}
57-
]
58-
},
59-
"description": "{{{notes}}}"
60-
}
8+
"request": {{>request}}
9+
,"response": [
10+
{{#responses}}
11+
{"name": "{{name}}",
12+
"code": {{code}},
13+
"status": "{{status}}",
14+
"header": [{
15+
"key": "Content-Type",
16+
"value": "application/json"}
17+
],
18+
"_postman_previewlanguage": "json",
19+
"cookie": [],
20+
"body" : "{{{body}}}",
21+
"originalRequest": {{#originalRequest}}{{>request}}{{/originalRequest}}
22+
}{{^-last}},{{/-last}}
23+
{{/responses}}
24+
]
6125
}{{^-last}},{{/-last}}
6226
{{/vendorExtensions.postmanRequests}}
6327
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"method": "{{httpMethod}}",
3+
"header": [
4+
{{#headerParams}}
5+
{
6+
"key": "{{baseName}}",
7+
"value": "{{schema.defaultValue}}",
8+
"description": "{{{description}}}",
9+
"disabled": {{#schema.defaultValue}}false{{/schema.defaultValue}}{{^schema.defaultValue}}true{{/schema.defaultValue}}
10+
}{{^-last}},{{/-last}}
11+
{{/headerParams}}
12+
],
13+
"body": {
14+
"mode": "raw",
15+
"raw": "{{{body}}}",
16+
"options": {
17+
"raw": {
18+
"language": "json"
19+
}
20+
}
21+
},
22+
"url": {
23+
"raw": "{{=<% %>=}}{{baseUrl}}<%={{ }}=%>{{path}}",
24+
"host": [
25+
"{{=<% %>=}}{{baseUrl}}<%={{ }}=%>"
26+
],
27+
"path": [
28+
{{#vendorExtensions.pathSegments}}
29+
"{{.}}"{{^-last}},{{/-last}}
30+
{{/vendorExtensions.pathSegments}}
31+
],
32+
"variable": [
33+
{{#pathParams}}
34+
{
35+
"key": "{{paramName}}",
36+
"value": "{{defaultValue}}",
37+
"description": "{{{description}}}"
38+
}{{^-last}},{{/-last}}
39+
{{/pathParams}}
40+
],
41+
"query": [
42+
{{#queryParams}}
43+
{
44+
"key": "{{paramName}}",
45+
"value": "{{example}}",
46+
"description": "{{{description}}}",
47+
"disabled": {{#required}}false{{/required}}{{^required}}true{{/required}}
48+
}{{^-last}},{{/-last}}
49+
{{/queryParams}}
50+
]
51+
},
52+
"description": "{{{notes}}}"
53+
}

0 commit comments

Comments
 (0)