oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

allow coexistence of anyOf and oneOf fields in single schema definition

Open masu-mi opened this issue 3 years ago • 0 comments

allow coexistence of anyOf and oneOf fields in single schema definition

If some schema has anyOf, oneOf field, generating code get failed. (A while ago (before of commit:5a1784a), generating get success, but generated code didn't work) Its reason is that created internal type name for additional type related to anyOf or oneOf.

I want to fix it, but have no idea how to escape the name conflict, using Any and One suffixes for them?

example

We can reproduce it executing go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml with following files.

config.yml

---
package: issue_any_w_one
generate:
  models: true
output: issue.gen.go
output-options:
  skip-prune: true

spec.yaml

openapi: 3.0.2
info:
  version: "0.0.1"
components:
  schemas:
    Orange:
      desription: anyOf with oneOf
      oneOf:
      - required:
        - attrA0
      - required:
        - attrA1
      anyOf:
      - required:
        - attrB
      - required:
        - attrC
      properties:
        attrA0: {type: string}
        attrA1: {type: string}
        attrB: {type: string}
        attrC: {type: string}
      type: object

masu-mi avatar Nov 04 '22 08:11 masu-mi