ogen icon indicating copy to clipboard operation
ogen copied to clipboard

oneOf inside allOf not working

Open Liooo opened this issue 3 years ago • 6 comments

What version of ogen are you using?

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

Can this issue be reproduced with the latest version?

Yes

What did you do?

  schemas:
    Pet:
      allOf:
        - type: object
          required:
            - name
          properties:
            name:
              type: string
        - oneOf:
            - $ref: "#/components/schemas/Cat"
            - $ref: "#/components/schemas/Dog"
          discriminator:
            propertyName: type
            mapping:
              cat: "#/components/schemas/Cat"
              dog: "#/components/schemas/Dog"
    Cat:
      type: object
      properties:
        meow:
          type: string
    Dog:
      type: object
      properties:
        bark:
          type: string

What did you expect to see?

type Pet struct {
	Name string `json:"name"`
	Type: PetType
	PetCat Cat
	PetDog Dog
}

// ...

What did you see instead?

// Merged schema.
// Ref: #/components/schemas/Pet
type Pet struct {
	Name string `json:"name"`
}

Liooo avatar Jun 21 '23 14:06 Liooo

I've just run into this same issue. Would be nice to support this so I don't have to repeat common fields into all discriminated types.

mattoni avatar Jun 29 '23 20:06 mattoni

This one is crucial for inheritance pattern when u have e.g. a Base model, and want to use allOf to extend it. Please implement this 🙏

GienekGenin avatar Jul 11 '23 06:07 GienekGenin

Hi, I love your work! We are happy to use it but we have the same Problem here. Do you plan to fix this soon?

roberth1988 avatar Jul 18 '23 06:07 roberth1988

Thanks @tdakkota 🎉

Liooo avatar Jul 26 '23 15:07 Liooo

Just tried to upgrade to 0.72.0 and running into big breaking changes with the generated code with the solution to this issue.

Say you have Vehicle which can be oneOf, Car or Bicycle, in 0.71.1 the generated Vehicle struct would be as follows:

type Vehicle struct {
  Type VehicleType
  Car Car
  Bicycle Bycycle
}

Whereas in 0.72.0 this is output:

type Vehicle struct {
  OneOf VehicleSum
}

Was this intended? We're not even 20% through developing a new API, and whilst I appreciate breaking changes are acceptable being pre-1.0, this is a worrying sign for our adoption of the library.

Also I'm seeing another bug in this version around conflicting types, which I'm going to create a separate issue for

dan-j avatar Jul 27 '23 21:07 dan-j

Not sure what notifications would be sent on a closed issue, so just tagging people to alert them to my comment above (I should have tagged in the first place)

@ernado @tdakkota - thanks

dan-j avatar Jul 27 '23 21:07 dan-j