Skip to content

Make possible use values other than strings as discriminator #1619

Closed

Description

@maks56893

Sometimes I should use boolean value as value for discriminator field. Now when generating union methods for this type I get types errors
Example schema

ConfigHttp:
  type: object
  properties:
    is_http:
      type: boolean
      enum: [true]
    host:
      type: string
    port:
      type: integer
ConfigSsh:
  type: object
  properties:
    is_http:
      type: boolean
      enum: [false]
    host:
      type: string
    key:
      type: string
ConfigSchema:
  oneOf:
  - $ref: "#/components/schemas/ConfigHttp"
  - $ref: "#/components/schemas/ConfigSsh"
  discriminator:
    propertyName: is_http
    mapping:
      false: "#/components/schemas/ConfigSsh"
      true: "#/components/schemas/ConfigHttp"

In result I get method like this. "false" value is don't fit here

func (t *ConfigSchema) FromConfigSsh(v ConfigSsh) error {
	v.IsHttp = "false"
	b, err := json.Marshal(v)
	t.union = b
	return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions