oapi-codegen: Generated API code no longer compiles after upgrade form 1.12.4 to 1.13.2
To make a long story short, my code doesn’t compile after the upgrade (after many releases which were drama free). I have put up a demonstration of the problem here:
https://github.com/danielbprice/oapi-codegen-problem
I found that by changing application/problem+json to application/json in my openapi.yaml file, the problem goes away, so I suspect it’s related in some way to changes there. Thanks!
Possibly this could be related to what the user in https://github.com/deepmap/oapi-codegen/issues/1146 was talking about. Hopefully my reproducible test case will help.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (8 by maintainers)
Commits related to this issue
- fix: correct marshalling for alternative JSON types (+json) for strict servers (#1171) Closes #1168 — committed to deepmap/oapi-codegen by reinkrul a year ago
- Fix: Generate models for all JSON media types As highlighted in #1168, we have some cases where JSON-compatible media types aren't having their respective models generated, as we previously only look... — committed to deepmap/oapi-codegen by jamietanna a year ago
- Fix: Generate models for all JSON media types As highlighted in #1168, we have some cases where JSON-compatible media types aren't having their respective models generated, as we previously only look... — committed to deepmap/oapi-codegen by jamietanna a year ago
- Fix: Generate models for all JSON media types As highlighted in #1168, we have some cases where JSON-compatible media types aren't having their respective models generated, as we previously only look... — committed to breuHQ/oapi-codegen by jamietanna a year ago
- fix: correct marshalling for alternative JSON types (+json) for strict servers (#1171) Closes #1168 — committed to breuHQ/oapi-codegen by reinkrul a year ago
@jamietanna, I can confirm that this passes the reduced test case, and also builds our in-house code correctly, as before, with all tests passing.
Many thanks to you and @deepmap-marcinr , I really get a lot out of having this tool available.
sure, just test your PR in my case which only generate client,types code, and works fine. GOOD JOB.
@jamietanna I updated the LICENSE for the repository to Apache 2.0 and marked the file as Apache 2.0 licensed, except the included portion which is under MIT license.
@danielbprice looks like this may be due to the i.e.
Misc400Errorbeing newly generated in the v1.13.x release, as I don’t see it present in v1.12.x - I can reproduce with:That - as with your example - we see:
Slight tangent
What’s odd about this is that we’re missing the HTTP 200 response. Looks like this is due to:
text/plainwhich doesn’t provide any bindings in the resulting responseschemaset correctlyWith this change:
We then get a
JSON200.This tangent ☝️ doesn’t seem to be the issue, just something I spotted and started investigating - still investigating
It looks like in v1.12.x we were determining that
Misc400Error = ProblemDetailsso just putting that inline, but now we’re expecting theMisc400Errorto be there, but it’s notInvestigation seems to lead to https://github.com/deepmap/oapi-codegen/blob/f20166f0021f9784ede134799bc01e73e1c39e58/pkg/codegen/templates/client-with-responses.tmpl#L47-L53 being the root cause.
Further investigation shows that maybe it’s that we’re not correctly generating types from
#/components/responses/So yup, this is down to https://github.com/deepmap/oapi-codegen/blob/f20166f0021f9784ede134799bc01e73e1c39e58 pkg/codegen/codegen.go#L546 not triggering for
application/problem+jsonThanks for catching and fixing! Now released as https://github.com/deepmap/oapi-codegen/releases/tag/v1.13.3