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

ValueByDiscriminator is missinng when use allOf with ref struct with another fied

Open maks56893 opened this issue 1 year ago • 1 comments

I'm trying to generate model ConfigSaveReq from this spec

    ConfigHttp:
      type: object
      properties:
        host:
          type: string
        port:
          type: integer
    ConfigSsh:
      type: object
      properties:
        host:
          type: string
        key:
          type: string
    ConfigSchema:
      oneOf:
      - $ref: "#/components/schemas/ConfigHttp"
      - $ref: "#/components/schemas/ConfigSsh"
      discriminator:
        propertyName: config_type
        mapping:
          ssh_server: "#/components/schemas/ConfigSsh"
          apache_server: "#/components/schemas/ConfigHttp"
          web_server: "#/components/schemas/ConfigHttp"
          another_server: "#/components/schemas/ConfigHttp"
    ConfigSaveReq:
      allOf:
      - $ref: "#/components/schemas/ConfigSchema"
      - type: object
        properties:
          field_only_for_save:
            type: string

But in result I get this type without method ValueByDiscriminator and I can't use union field in other packages

type ConfigSaveReq struct {
	FieldOnlyForSave *string `json:"field_only_for_save,omitempty"`
	union            json.RawMessage
}

Maybe better way to combine ref struct and another field will be use embedding instead direct use json.RawMessage in struct?

maks56893 avatar Apr 17 '24 12:04 maks56893

Duplication? https://github.com/oapi-codegen/oapi-codegen/issues/666

maranqz avatar May 21 '25 12:05 maranqz