ogen-go / ogen

OpenAPI v3 code generator for go
https://ogen.dev
Apache License 2.0
1.44k stars 85 forks source link

Discriminator mapping can't find schemas using allOf #979

Closed johannes-riecken closed 1 year ago

johannes-riecken commented 1 year ago

What version of ogen are you using?

ogen version v0.71.0 (built with go1.20.4) darwin/arm64

$ go list -m github.com/ogen-go/ogen

github.com/ogen-go/ogen v0.70.0

Can this issue be reproduced with the latest version?

I guess so.

What did you do?

I'm trying to figure out what kind of way to avoid duplication in similar schemas works with ogen. When not nesting allOf and oneOf and not using a discriminator mapping (see here), I get decent code generated. However, if I use a mapping that should be semantically identical to not using a mapping (here), code generation fails.

What did you expect to see?

Successful, possibly even unchanged code generation.

What did you see instead?

INFO    convenient  Convenient errors are not available {"reason": "operation has no \"default\" response", "at": "openapi_non-injective.yml:14:9"}
generate:
    main.run
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/cmd/ogen/main.go:304
  - build IR:
    main.generate
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/cmd/ogen/main.go:64
  - make ir:
    github.com/ogen-go/ogen/gen.NewGenerator
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/generator.go:112
  - operations:
    github.com/ogen-go/ogen/gen.(*Generator).makeIR
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/generator.go:130
  - path "/circles": get:
    github.com/ogen-go/ogen/gen.(*Generator).makeOps
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/generator.go:171
  - responses:
    github.com/ogen-go/ogen/gen.(*Generator).generateOperation
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/gen_operation.go:55
  - code 200:
    github.com/ogen-go/ogen/gen.(*Generator).generateResponses
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/gen_responses.go:34
  - contents:
    github.com/ogen-go/ogen/gen.(*Generator).responseToIR
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/gen_responses.go:182
  - media: "application/json":
    github.com/ogen-go/ogen/gen.(*Generator).generateContents
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/gen_contents.go:330
  - generate schema:
    github.com/ogen-go/ogen/gen.(*Generator).generateContents.func1
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/gen_contents.go:271
  - item:
    github.com/ogen-go/ogen/gen.(*schemaGen).generate2
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/schema_gen.go:443
  - oneOf:
    github.com/ogen-go/ogen/gen.(*schemaGen).generate2
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/schema_gen.go:204
  - discriminator: unable to map "Rectangle" to "file:///Users/rieckenj/tmp/my-ogen/openapi_non-injective.yml#/components/schemas/Rectangle":
    github.com/ogen-go/ogen/gen.(*schemaGen).oneOf
        /Users/rieckenj/go/pkg/mod/github.com/ogen-go/ogen@v0.71.0/gen/schema_gen_sum.go:289
dan-j commented 1 year ago

I've also created this issue, #988, which I think is the same issue as this, somehow I missed this when searching.

ernado commented 1 year ago

v0.72.1