Skip to content

Feature Request/Discussion: Golang string types for discriminator #49

@delaneyj

Description

@delaneyj

A definition of

 "foo": {
      "discriminator": "type",
      "mapping": {
        "a": {
          "properties": {}
        },
        "b": {
          "properties": {}
        },
        "c": {
          "properties": {}
        }
      }
    }

Generates a Go struct of

type Foo struct {
	Type string

	A FooA

	B FooB

	C FooC
}

Where it should be more acccurately be the same as an enum and look more like...

type FooTypeDiscriminator string

const (
	FooTypeDiscriminatorA FooTypeDiscriminator = "a"

	FooTypeDiscriminatorB FooTypeDiscriminator = "b"

	FooTypeDiscriminatorC FooTypeDiscriminator = "c"
)

type Foo struct {
	FooTypeDiscriminator string

	A FooA

	B FooB

	C FooC
}

This would improve auto-completion and validation.

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