-
Couldn't load subscription status.
- Fork 6k
Feature/success code responses #7674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d69c934
0c5929c
5124bd3
bf8ee90
177b0d2
9e384ab
65446af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1985,20 +1985,20 @@ protected void setNonArrayMapProperty(CodegenProperty property, String type) { | |
| * @param responses Swagger Operation's responses | ||
| * @return default method response or <tt>null</tt> if not found | ||
| */ | ||
| protected Response findMethodResponse(Map<String, Response> responses) { | ||
| protected Entry<String, Response> findMethodResponse(Map<String, Response> responses) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand your code correctly, this seems to be a change to the CORE of swagger codegen since it change the way we handle return status. At the beginning, I though it was only Play Framework generator that was missing feature to return the good code but since you needed to add stuff in the DefaultCodegen, I guess it was missing from all codegen. That is making this change request more important and I think that core members should review it too. @wing328 Can you check this and also tag some core members to review this. Thanks! |
||
|
|
||
| String code = null; | ||
| for (String responseCode : responses.keySet()) { | ||
| if (responseCode.startsWith("2") || responseCode.equals("default")) { | ||
| if (code == null || code.compareTo(responseCode) > 0) { | ||
| code = responseCode; | ||
| Entry<String, Response> response = null; | ||
| for (Entry<String, Response> entry : responses.entrySet()) { | ||
| if (entry.getKey().startsWith("2") || "default".equals(entry.getKey())) { | ||
| if (response == null || response.getKey().compareTo(entry.getKey()) > 0) { | ||
| response = entry; | ||
| } | ||
| } | ||
| } | ||
| if (code == null) { | ||
| if (response == null) { | ||
| return null; | ||
| } | ||
| return responses.get(code); | ||
| return response; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -2133,80 +2133,84 @@ public CodegenOperation fromOperation(String path, | |
| } | ||
|
|
||
| if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { | ||
| Response methodResponse = findMethodResponse(operation.getResponses()); | ||
|
|
||
| for (Map.Entry<String, Response> entry : operation.getResponses().entrySet()) { | ||
| Response response = entry.getValue(); | ||
| CodegenResponse r = fromResponse(entry.getKey(), response); | ||
| r.hasMore = true; | ||
| if (r.baseType != null && | ||
| !defaultIncludes.contains(r.baseType) && | ||
| !languageSpecificPrimitives.contains(r.baseType)) { | ||
| imports.add(r.baseType); | ||
| } | ||
| r.isDefault = response == methodResponse; | ||
| op.responses.add(r); | ||
| if (Boolean.TRUE.equals(r.isBinary) && Boolean.TRUE.equals(r.isDefault)){ | ||
| op.isResponseBinary = Boolean.TRUE; | ||
| } | ||
| if (Boolean.TRUE.equals(r.isFile) && Boolean.TRUE.equals(r.isDefault)){ | ||
| op.isResponseFile = Boolean.TRUE; | ||
| } | ||
| } | ||
| op.responses.get(op.responses.size() - 1).hasMore = false; | ||
| Entry<String, Response> methodResponse = findMethodResponse(operation.getResponses()); | ||
|
|
||
| if (methodResponse != null) { | ||
| if (methodResponse.getSchema() != null) { | ||
| CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); | ||
|
|
||
| Property responseProperty = methodResponse.getSchema(); | ||
|
|
||
| if (responseProperty instanceof ArrayProperty) { | ||
| ArrayProperty ap = (ArrayProperty) responseProperty; | ||
| CodegenProperty innerProperty = fromProperty("response", ap.getItems()); | ||
| op.returnBaseType = innerProperty.baseType; | ||
| } else if (responseProperty instanceof MapProperty) { | ||
| MapProperty ap = (MapProperty) responseProperty; | ||
| CodegenProperty innerProperty = fromProperty("response", ap.getAdditionalProperties()); | ||
| op.returnBaseType = innerProperty.baseType; | ||
| } else { | ||
| if (cm.complexType != null) { | ||
| op.returnBaseType = cm.complexType; | ||
| String code = methodResponse.getKey(); | ||
| if (!"default".equals(code)) { | ||
| op.successCode = Integer.parseInt(code); | ||
| } | ||
|
|
||
| for (Entry<String, Response> entry : operation.getResponses().entrySet()) { | ||
| Response response = entry.getValue(); | ||
| CodegenResponse r = fromResponse(entry.getKey(), response); | ||
| r.hasMore = true; | ||
| if (r.baseType != null && | ||
| !defaultIncludes.contains(r.baseType) && | ||
| !languageSpecificPrimitives.contains(r.baseType)) { | ||
| imports.add(r.baseType); | ||
| } | ||
| r.isDefault = response == methodResponse.getValue(); | ||
| op.responses.add(r); | ||
| if (Boolean.TRUE.equals(r.isBinary) && Boolean.TRUE.equals(r.isDefault)){ | ||
| op.isResponseBinary = Boolean.TRUE; | ||
| } | ||
| if (Boolean.TRUE.equals(r.isFile) && Boolean.TRUE.equals(r.isDefault)){ | ||
| op.isResponseFile = Boolean.TRUE; | ||
| } | ||
| } | ||
| op.responses.get(op.responses.size() - 1).hasMore = false; | ||
|
|
||
| Response response = methodResponse.getValue(); | ||
| if (response != null) { | ||
| if (response.getSchema() != null) { | ||
| CodegenProperty cm = fromProperty("response", response.getSchema()); | ||
|
|
||
| Property responseProperty = response.getSchema(); | ||
|
|
||
| if (responseProperty instanceof ArrayProperty) { | ||
| ArrayProperty ap = (ArrayProperty) responseProperty; | ||
| CodegenProperty innerProperty = fromProperty("response", ap.getItems()); | ||
| op.returnBaseType = innerProperty.baseType; | ||
| } else if (responseProperty instanceof MapProperty) { | ||
| MapProperty ap = (MapProperty) responseProperty; | ||
| CodegenProperty innerProperty = fromProperty("response", ap.getAdditionalProperties()); | ||
| op.returnBaseType = innerProperty.baseType; | ||
| } else { | ||
| op.returnBaseType = cm.baseType; | ||
| } | ||
| } | ||
| op.examples = new ExampleGenerator(definitions).generate(methodResponse.getExamples(), operation.getProduces(), responseProperty); | ||
| op.defaultResponse = toDefaultValue(responseProperty); | ||
| op.returnType = cm.datatype; | ||
| op.hasReference = definitions != null && definitions.containsKey(op.returnBaseType); | ||
|
|
||
| // lookup discriminator | ||
| if (definitions != null) { | ||
| Model m = definitions.get(op.returnBaseType); | ||
| if (m != null) { | ||
| CodegenModel cmod = fromModel(op.returnBaseType, m, definitions); | ||
| op.discriminator = cmod.discriminator; | ||
| op.examples = new ExampleGenerator(definitions).generate(response.getExamples(), operation.getProduces(), responseProperty); | ||
| op.defaultResponse = toDefaultValue(responseProperty); | ||
| op.returnType = cm.datatype; | ||
| op.hasReference = definitions != null && definitions.containsKey(op.returnBaseType); | ||
|
|
||
| // lookup discriminator | ||
| if (definitions != null) { | ||
| Model m = definitions.get(op.returnBaseType); | ||
| if (m != null) { | ||
| CodegenModel cmod = fromModel(op.returnBaseType, m, definitions); | ||
| op.discriminator = cmod.discriminator; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (cm.isContainer) { | ||
| op.returnContainer = cm.containerType; | ||
| if ("map".equals(cm.containerType)) { | ||
| op.isMapContainer = true; | ||
| } else if ("list".equalsIgnoreCase(cm.containerType)) { | ||
| op.isListContainer = true; | ||
| } else if ("array".equalsIgnoreCase(cm.containerType)) { | ||
| op.isListContainer = true; | ||
| if (cm.isContainer) { | ||
| op.returnContainer = cm.containerType; | ||
| if ("map".equals(cm.containerType)) { | ||
| op.isMapContainer = true; | ||
| } else if ("list".equalsIgnoreCase(cm.containerType)) { | ||
| op.isListContainer = true; | ||
| } else if ("array".equalsIgnoreCase(cm.containerType)) { | ||
| op.isListContainer = true; | ||
| } | ||
| } else { | ||
| op.returnSimpleType = true; | ||
| } | ||
| if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null) { | ||
| op.returnTypeIsPrimitive = true; | ||
| } | ||
| } else { | ||
| op.returnSimpleType = true; | ||
| } | ||
| if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null) { | ||
| op.returnTypeIsPrimitive = true; | ||
| } | ||
| addHeaders(response, op.responseHeaders); | ||
| } | ||
| addHeaders(methodResponse, op.responseHeaders); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,14 +158,21 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation | |
| CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger); | ||
|
|
||
| if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { | ||
| Response methodResponse = findMethodResponse(operation.getResponses()); | ||
| Map.Entry<String, Response> methodResponse = findMethodResponse(operation.getResponses()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since your are changing stuff in many other generators, did you make sure to generate all theses generators? Does it create any changes to the samples? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change affects to other generators but only changes code generated for java play framework, because |
||
|
|
||
| if (methodResponse != null) { | ||
| if (methodResponse.getSchema() != null) { | ||
| CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); | ||
| op.vendorExtensions.put("x-codegen-response", cm); | ||
| if(cm.datatype == "HttpContent") { | ||
| op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); | ||
| String successCode = methodResponse.getKey(); | ||
| if (!"default".equals(successCode)) { | ||
| op.successCode = Integer.parseInt(successCode); | ||
| } | ||
| Response response = methodResponse.getValue(); | ||
| if (response != null) { | ||
| if (response.getSchema() != null) { | ||
| CodegenProperty cm = fromProperty("response", response.getSchema()); | ||
| op.vendorExtensions.put("x-codegen-response", cm); | ||
| if ("HttpContent".equals(cm.datatype)) { | ||
| op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||