Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ignaciomolina
Copy link
Contributor

@ignaciomolina ignaciomolina commented Feb 16, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger

Description of the PR

  • Add attribute to CodegenOperations to obtain the response code
  • Add response code to Java Play Framework Controller template

@tzimisce012
Copy link
Contributor

#7583 @JFCote

Copy link
Contributor

@JFCote JFCote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It look good and with proper review from the core team, I think it will be a very good addition to swagger-codegen. We need to make sure to generate the samples of every generator affected by this and make sure they still compile and run test properly.

@@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@ignaciomolina ignaciomolina Feb 16, 2018

Choose a reason for hiding this comment

The 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 successCode is used nowhere else

@@ -1975,20 +1975,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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!

@@ -307,7 +306,7 @@
"type" : "file"
} ],
"responses" : {
"200" : {
"201" : {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised the json changed... If I'm not mistaken, this is simply a dump from swagger-parser in json format. Why is it now using the 201 code instead of 200. Did I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my mistake, I did a few tests and I add the file to the commit without notice it

@ignaciomolina
Copy link
Contributor Author

How is it going? @wing328 😅

@wing328
Copy link
Contributor

wing328 commented Feb 27, 2018

@ignaciomolina let me review tomorrow. Sorry for the delay.

@wing328 wing328 added this to the v2.4.0 milestone Feb 27, 2018
@wing328
Copy link
Contributor

wing328 commented Feb 28, 2018

@ignaciomolina the change breaks the Pistache generator:

[main] INFO io.swagger.parser.Swagger20Parser - reading from modules/swagger-codegen/src/test/resources/2_0/petstore.yaml
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/ApiResponse.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/ApiResponse.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Category.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Category.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Order.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Order.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Pet.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Pet.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Tag.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/Tag.cpp
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/User.h
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /root/src/github.com/swagger-api/swagger-codegen/samples/server/petstore/pistache-server/model/User.cpp
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: Tag {
	name: user
	description: Operations about user
	externalDocs: io.swagger.models.ExternalDocs@e1e57bab
	extensions:{}}
  Operation: createUser
  Resource: post /user
  Definitions: {Order=io.swagger.models.ModelImpl@6b904c51, Category=io.swagger.models.ModelImpl@ba13e696, User=io.swagger.models.ModelImpl@9db581f0, Tag=io.swagger.models.ModelImpl@d651f3db, Pet=io.swagger.models.ModelImpl@c9d5d174, ApiResponse=io.swagger.models.ModelImpl@16a9e5a9}
  Exception: For input string: "default"
	at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:935)
	at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:814)
	at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:434)
	at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:749)
	at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
	at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: java.lang.NumberFormatException: For input string: "default"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:580)
	at java.lang.Integer.parseInt(Integer.java:615)
	at io.swagger.codegen.languages.PistacheServerCodegen.fromOperation(PistacheServerCodegen.java:166)
	at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:884)
	... 5 more

For the full log, please click on the link to the Shippable CI job.

@wing328
Copy link
Contributor

wing328 commented Feb 28, 2018

I was able to repeat the issue locally by running ./bin/pistache-server-petstore.sh.

@ignaciomolina
Copy link
Contributor Author

Shippable doesn't show me the logs, it says that I have to download it but I don't see any download button

@wing328
Copy link
Contributor

wing328 commented Feb 28, 2018

@ignaciomolina can you try https://app.shippable.com/download/jobConsoles?jobId=5a965e1b9e550508008cef87? You will need to register an account at shippable and log in to obtain a valid token.

@ignaciomolina
Copy link
Contributor Author

@wing328 solved!

@wing328
Copy link
Contributor

wing328 commented Mar 1, 2018 via email

@wing328
Copy link
Contributor

wing328 commented Mar 1, 2018

cc the following technical committees as the change affects multiple generators:

@wing328
Copy link
Contributor

wing328 commented Mar 8, 2018

If no further question/feedback, I"ll merge this PR on coming Friday.

@edrevo
Copy link
Contributor

edrevo commented Apr 26, 2018

@wing328 , it would be great if we could merge this PR :)

@ignaciomolina there is a merge conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants