GeezerVison is showing github.com — Generated API code no longer compiles after upgrade form 1.12.4 to 1.13.2 · Issue #1168 · oapi-codegen/oapi-codegen
Generated API code no longer compiles after upgrade form 1.12.4 to 1.13.2 #1168DescriptionTo 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 #1146 was talking about. Hopefully my reproducible test case will help. Activityreinkrul commented on Aug 2, 2023 We also encountered this issue upgrading from 1.13.1 to 1.13.2
The generated Problem response types (Body) don't implement bytes.Reader
nuts-foundation/nuts-node#2388 reinkrul commented on Aug 3, 2023 I suspect the change/bug is caused by #1159 (since that's the only functional change between 1.13.1 and 1.13.2) reinkrul commented on Aug 3, 2023 added a commit that references this issue on Aug 3, 2023This issue will close once commit f20166f is merged into the 'main' branch.f20166f jamietanna commented on Aug 3, 2023 danielbprice commented on Aug 3, 2023 ContributorAuthor More actions Thank you for your hard work @jamietanna @reinkrul ! However, this morning I downloaded the 1.13.3 release and I face the same problem:
$ oapi-codegen --version
github.com/deepmap/oapi-codegen/cmd/oapi-codegen
v1.13.3
$ oapi-codegen -o fails-1-13-3/api.gen.go openapi.yaml
$ go build ./fails-1-13-3/
# example.com/test/fails-1-13-3
fails-1-13-3/api.gen.go:336:29: undefined: Misc400Error
fails-1-13-3/api.gen.go:337:29: undefined: Misc404Error
fails-1-13-3/api.gen.go:380:12: undefined: Misc400Error
fails-1-13-3/api.gen.go:387:12: undefined: Misc404Error
I've checked a couple of times and I don't think I've made some stupid mistake (like, wrong version of the tools). I updated https://github.com/danielbprice/oapi-codegen-problem with my reproduction of the bug. For me, there is no difference in the output of the generated code except for the version number:
$ diff fails-1-13-2/api.gen.1.13.2.go fails-1-13-3/api.gen.go
3c3
< // Code generated by github.com/deepmap/oapi-codegen version v1.13.2 DO NOT EDIT.
---
> // Code generated by github.com/deepmap/oapi-codegen version v1.13.3 DO NOT EDIT.
Update: based on reading the fix that was integrated, I tried both strict and regular mode, and I have the same results. reinkrul commented on Aug 3, 2023 Then your case is probably different. I must say I quickly assumed it is the same situation since I encountered the same issue with an application/problem+json response looking similar, but it looks it's really a different issue. jamietanna commented on Aug 3, 2023 Thanks, I'll try and have a look later or tomorrow 🤞🏽 jamietanna commented on Aug 3, 2023 @danielbprice looks like this may be due to the i.e. Misc400Error being newly generated in the v1.13.x release, as I don't see it present in v1.12.x - I can reproduce with:
go run github.com/deepmap/oapi-codegen/cmd/[email protected] -o tmp/a.gen.go -package f openapi.yaml
That - as with your example - we see:
type GetV1TestResponse struct {
Body []byte
HTTPResponse *http.Response
JSON400 *ProblemDetails
JSON404 *ProblemDetails
}
Slight tangent
What's odd about this is that we're missing the HTTP 200 response. Looks like this is due to:
- using
text/plain which doesn't provide any bindings in the resulting response
- not having a
schema set correctly
With this change:
diff --git openapi.yaml openapi.yaml
index 51800bc..11b2f28 100644
--- openapi.yaml
+++ openapi.yaml
@@ -23,8 +23,9 @@ paths:
'200':
description: Successful response
content:
- text/plain:
- type: string
+ application/json:
+ schema:
+ type: string
'400':
$ref: '#/components/responses/Misc400Error'
'404':
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 = ProblemDetails so just putting that inline, but now we're expecting the Misc400Error to be there, but it's not
Investigation 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+json jamietanna commented on Aug 4, 2023 danielbprice commented on Aug 4, 2023 ContributorAuthor More actions I'm on the road at the moment but should be able to get to testing this in
the next 48 hrs. The text/plain problem is from me reducing the test
case. The original endpoint returns JSON on the 200 response. Thanks!
…danielbprice commented on Aug 4, 2023 ContributorAuthor More actions @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 commented on Aug 5, 2023 ContributorAuthor More actions @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. Reacted by Jamie Tanna Reacted by Jamie Tanna oh0123 commented on Aug 5, 2023
@danielbprice looks like this may be due to the i.e. Misc400Error being newly generated in the v1.13.x release, as I don't see it present in v1.12.x - I can reproduce with:
go run github.com/deepmap/oapi-codegen/cmd/[email protected] -o tmp/a.gen.go -package f openapi.yaml
That - as with your example - we see:
type GetV1TestResponse struct {
Body []byte
HTTPResponse *http.Response
JSON400 *ProblemDetails
JSON404 *ProblemDetails
}
Slight tangent
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 = ProblemDetails so just putting that inline, but now we're expecting the Misc400Error to be there, but it's not
Investigation 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+json
yep, meet same problem, and that's why. Hope to fix is soon. jamietanna commented on Aug 5, 2023 Thanks @oh0123 are you able to check if #1177 works for you too?
I've got some family over at the moment so will try and get the PR fixed up later today or tomorrow🤞🏽 oh0123 commented on Aug 5, 2023
Thanks @oh0123 are you able to check if #1177 works for you too?
I've got some family over at the moment so will try and get the PR fixed up later today or tomorrow🤞🏽
sure, just test your PR in my case which only generate client,types code, and works fine. GOOD JOB. jamietanna commented on Aug 7, 2023 added 2 commits that reference this issue on Aug 31, 2024This issue will close once commit 315b135 is merged into the 'main' branch.315b135 This issue will close once commit 8dc31f9 is merged into the 'main' branch.8dc31f9 added 2 commits that reference this issue on May 12, 2025This issue will close once commit 0222b43 is merged into the 'master' branch.0222b43 This issue will close once commit 5d84c7c is merged into the 'master' branch.5d84c7c added 2 commits that reference this issue on Nov 7, 2025This issue will close once commit 7b2eb30 is merged into the 'master' branch.7b2eb30 This issue will close once commit 1869152 is merged into the 'master' branch.1869152
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|