GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #1168

New issue
Copy link
New issue
Copy link
Closed
#1177
#1171
Closed
Generated API code no longer compiles after upgrade form 1.12.4 to 1.13.2#1168
#1177
#1171
Copy link

Description

@danielbprice
danielbprice
opened on Aug 2, 2023
Issue body actions

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 #1146 was talking about. Hopefully my reproducible test case will help.

Activity

  1. reinkrul commented on Aug 2, 2023

    @reinkrul
    reinkrul
    on Aug 2, 2023
    Contributor
    More actions

    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

  2. reinkrul commented on Aug 3, 2023

    @reinkrul
    reinkrul
    on Aug 3, 2023
    Contributor
    More actions

    I suspect the change/bug is caused by #1159 (since that's the only functional change between 1.13.1 and 1.13.2)

  3. reinkrul commented on Aug 3, 2023

    @reinkrul
    reinkrul
    on Aug 3, 2023
    Contributor
    More actions

    Fix supplied.

  4. jamietanna
    closed this as completedin #1171on Aug 3, 2023
  5. jamietanna
    added a commit that references this issue on Aug 3, 2023

    fix: correct marshalling for alternative JSON types (+json) for stric…

    This issue will close once commit f20166f is merged into the 'main' branch.
    f20166f
  6. jamietanna commented on Aug 3, 2023

    @jamietanna
    jamietanna
    on Aug 3, 2023
    Member
    More actions

    Thanks for catching and fixing! Now released as https://github.com/deepmap/oapi-codegen/releases/tag/v1.13.3

    Reacted by reinkrul
  7. danielbprice commented on Aug 3, 2023

    @danielbprice
    danielbprice
    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.

  8. reinkrul commented on Aug 3, 2023

    @reinkrul
    reinkrul
    on Aug 3, 2023
    Contributor
    More actions

    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.

  9. jamietanna commented on Aug 3, 2023

    @jamietanna
    jamietanna
    on Aug 3, 2023
    Member
    More actions

    Thanks, I'll try and have a look later or tomorrow 🤞🏽

  10. jamietanna commented on Aug 3, 2023

    @jamietanna
    jamietanna
    on Aug 3, 2023
    Member
    More actions

    @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

    Reacted by OneHow
  11. jamietanna commented on Aug 4, 2023

    @jamietanna
    jamietanna
    on Aug 4, 2023
    Member
    More actions

    @danielbprice mind confirming if #1177 does what it needs for you? I'll look to get a proper PR ready later for Marcin to review (as it's got a chance to introduce some breakage)

    Also would you be happy me vendoring the https://github.com/danielbprice/oapi-codegen-problem/blob/main/openapi.yaml into the repo? I see no LICENSE on the repo, so would like express permission to relicense that file as Apache-2.0

  12. danielbprice commented on Aug 4, 2023

    @danielbprice
    danielbprice
    on Aug 4, 2023 via email
    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!
    …
    On Fri, Aug 4, 2023, 2:02 AM Jamie Tanna ***@***.***> wrote: @danielbprice <https://github.com/danielbprice> mind confirming if #1177 <#1177> does what it needs for you? I'll look to get a proper PR ready later for Marcin to review (as it's got a chance to introduce some breakage) — Reply to this email directly, view it on GitHub <#1168 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAURT36O7PCH7UFAXSBYLWTXTS3EFANCNFSM6AAAAAA3AWIARQ> . You are receiving this because you were mentioned.Message ID: ***@***.***>
  13. danielbprice commented on Aug 4, 2023

    @danielbprice
    danielbprice
    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.

    Reacted by Jamie Tanna
  14. danielbprice commented on Aug 5, 2023

    @danielbprice
    danielbprice
    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
  15. oh0123 commented on Aug 5, 2023

    @oh0123
    oh0123
    on Aug 5, 2023
    More actions

    @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.

  16. jamietanna commented on Aug 5, 2023

    @jamietanna
    jamietanna
    on Aug 5, 2023
    Member
    More actions

    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🤞🏽

  17. oh0123 commented on Aug 5, 2023

    @oh0123
    oh0123
    on Aug 5, 2023
    More actions

    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.

    Reacted by Jamie Tanna
  18. jamietanna
    added 2 commits that reference this issue on Aug 5, 2023

    Fix: Generate models for all JSON media types

    6df40d3

    Fix: Generate models for all JSON media types

    e90f06d
  19. jamietanna commented on Aug 7, 2023

    @jamietanna
    jamietanna
    on Aug 7, 2023
    Member
    More actions

    Released as https://github.com/deepmap/oapi-codegen/releases/tag/v1.13.4 👏

  20. debuggerpk
    added 2 commits that reference this issue on Sep 18, 2023

    Fix: Generate models for all JSON media types

    1b4b1fd

    fix: correct marshalling for alternative JSON types (+json) for stric…

    301ffec
  21. danicc097
    added 2 commits that reference this issue on Aug 31, 2024

    fix: correct marshalling for alternative JSON types (+json) for stric…

    This issue will close once commit 315b135 is merged into the 'main' branch.
    315b135

    Fix: Generate models for all JSON media types

    This issue will close once commit 8dc31f9 is merged into the 'main' branch.
    8dc31f9
  22. dewrich
    added 2 commits that reference this issue on May 12, 2025

    fix: correct marshalling for alternative JSON types (+json) for stric…

    This issue will close once commit 0222b43 is merged into the 'master' branch.
    0222b43

    Fix: Generate models for all JSON media types

    This issue will close once commit 5d84c7c is merged into the 'master' branch.
    5d84c7c
  23. dewrich
    added 2 commits that reference this issue on Nov 7, 2025

    fix: correct marshalling for alternative JSON types (+json) for stric…

    This issue will close once commit 7b2eb30 is merged into the 'master' branch.
    7b2eb30

    fix: correct marshalling for alternative JSON types (+json) for stric…

    This issue will close once commit 1869152 is merged into the 'master' branch.
    1869152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.