Giter VIP home page Giter VIP logo

Comments (4)

akishichinibu avatar akishichinibu commented on August 15, 2024

I think this issue is related to #1620

from oapi-codegen.

akishichinibu avatar akishichinibu commented on August 15, 2024

I found a temporary workaround by using a user template. In the strict-interface template, check if the response's OpenAPI schema is oneOf when the contentType is JSON.

curl https://raw.githubusercontent.com/oapi-codegen/oapi-codegen/v2.3.0/pkg/codegen/templates/strict/strict-interface.tmpl -o strict-interface.tmpl
patch strict-interface.tmpl -o strict-interface.patched.tmpl  < strict-interface.patch
74a75,81
>             {{if eq .NameTagOrContentType "JSON" -}}
>             {{if or (ne 0 (len .Schema.OAPISchema.OneOf)) (ne 0 (len .Schema.OAPISchema.AnyOf)) (ne 0 (len .Schema.OAPISchema.AllOf)) -}}
>             func (response {{$receiverTypeName}}) MarshalJSON() ([]byte, error) {
>                 return response.union.MarshalJSON()
>             }
>             {{end -}}
>             {{end -}}

config.yaml

# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
package: "api"
generate:
  echo-server: true
  models: true
  strict-server: true
  embedded-spec: false
output: api.gen.go
output-options:
  nullable-type: true
  initialism-overrides: true
  user-templates:
    strict/strict-interface.tmpl: ./strict-interface.patched.tmpl

from oapi-codegen.

dan-j avatar dan-j commented on August 15, 2024

This issue is also discussed here #970. It comes with a PR #1231 but I'm not sure if it should be merged due to my final comment in the issue

from oapi-codegen.

akishichinibu avatar akishichinibu commented on August 15, 2024

Also discussed under #970 (comment)
I seems that there're two ways to fix this bug.

from oapi-codegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.