Do not check status code for default response#3322
Do not check status code for default response#3322wing328 merged 2 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
This counts on the fact that the wildcard response will be the last one. My (limited) testing confirmed this, but will that always be the case?
There was a problem hiding this comment.
Ideally this should catch any error code so the error model is returned if one is specified. It may need to catch the default/wildcard in these cases.
If i remember correct, this should be an interface so it could be possible to make this completely generic without specifically checking each code?
There was a problem hiding this comment.
Ideally this should catch any error code so the error model is returned if one is specified. It may need to catch the default/wildcard in these cases.
My approach here was supressing the status code check for the default case so that it handles any error code. But that may overcatch if the wildcard response isn't the last one. Hence my original question.
If i remember correct, this should be an interface so it could be possible to make this completely generic without specifically checking each code?
Sorry, I don't understand. Are you suggesting removing that check completely and just trying to unmarshall the error model based on datatype?
|
Can you regenerate the test client? |
|
Done in 942f65f. I was saving that for when the PR got closer to finishing. |
|
I'm getting this double return on the generated code: // ...
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
return localVarReturnValue, localVarHttpResponse, newErr
}I'd like to avoid it, but my mustache-fu is weak. Any ideas? |
c881fad to
34df003
Compare
|
I've rebased this to latest master and ported the change to |
|
cc @bkabrda for review as the change targets |
|
Hmm, it's weird that this is something that happens only in the |
|
So my understanding of the issue is this:
However, I think the solution presented here is not entirely correct. The problem, I think, is that if there was e.g. also a 400 response defined, it could theoretically be listed after the default response in the I guess the correct solution is to both:
If the above problem is also in templates for other languages, having the responses sorted would also help all of them. Does this sound reasonable? |
|
Minor clarification of the above comment: it seems that the wildcard response numbers such as "4XX" actually produce invalid code (at least for Go), as they're treated as numbers, so there will be literal @thiagoarrais do you want to work on the points that I mentioned? I think I could find some time within ~1 week to get these fixed if you can't/don't want to work on them. |
I can work on that, but I haven't looked into the Java code yet. Can you point me into the right direction? Re: treating numbered wildcard responses ("4xx"): I'd prefer to keep this PR focused on literal default responses ("default"). |
|
@thiagoarrais so you'll need to modify To modify the order of responses, you'll need to do sorting on I'm somewhat new to openapi-generator myself, but I think this would be all that you need to do to get this done. |
|
Once CI finishes this is done by me. The other wildcards (1xx, 2xx, and so on) needed a little more investigation and were left for a later PR. Please let me know if you need anything else. |
|
Right, so even though we haven't reached a complete solution yet, we certainly improved the situation here, so 👍 for me to merge it. @thiagoarrais will you be interested in taking this further in a followup PR? I can work on it if you're not interested (I'd like to solve this now to get a complete solution to the problem). @wing328 feel free to review, I have no further comments here. |
|
Can't work on that right now, but maybe in a near future. Maybe we can open an issue as a placeholder for whomever finds the time first? |
|
Once this is merged, I'll open a followup issue and work on it, time permitting. |
|
Found some potential issues with this. Please avoid merging for the time being. By the way: can't figure how to mark a PR as draft after it is already opened... |
|
My problem seems to raise in OpenAPI 3 specs. Still digging, but it seems like the sorting code in |
|
OK. This is ready. I had switched the sorting comparation around. |
|
Can't tell if the Travis failure is related to the PR. Any pointers? |
|
@wing328: anything else needed for going forward with this? |
There was a problem hiding this comment.
@thiagoarrais I notice that you've updated the test to replace 2xx with 4xx status code.
Does it mean the original "201" status code test fail?
There was a problem hiding this comment.
No. 422 just seemed more realistic. 201 is a success and more likely to be equated to the default case.
There was a problem hiding this comment.
Changes in DefaultCodegen
cc @OpenAPITools/generator-core-team
e8e572a to
9e21d96
Compare
|
Squashed and rebased. Anything else needed for merging? |
|
Folks, anything else that needs to be addressed here? |
|
@thiagoarrais Let me review by tomorrow ... |
|
Sorry for the delay. Please resolve the conflicts and I'll merge after that 🙏 |
c9688af to
09d1b5e
Compare
|
Hey, @wing328, no need to apologize. We all understand that. Anyway... resolved conflicts and rebased. Should be good to go. |
Because Circle CI said > Please run 'bin/utils/ensure-up-to-date' locally and commit > changes (UNCOMMITTED CHANGES ERROR)
|
Ran update as requested by CircleCI. Regarding the Travis failure, I'm not sure it is related to this PR, since a similar build already ran successfully for my fork. |
|
CircleCI issue not related to this PR. Tests passed locally: |
|
@thiagoarrais PR merged into master. Thanks for your contribution. |
|
@thiagoarrais thanks for the PR, which has been included in v4.2.0 release: https://twitter.com/oas_generator/status/1189824932345069569 |
|
Awesome! It's been a pleasure! |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif 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\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master,4.1.x,5.0.x. Default:master.Description of the PR
Fixes #3321 by not checking HTTP status when generating code for a default response.
Reviewers, please check review comments.
cc @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09)