a-h / generate

Generates Go (golang) Structs from JSON schema.
MIT License
444 stars 137 forks source link

Treat oneOf(a, null) as optional #70

Open cbndr opened 4 years ago

cbndr commented 4 years ago

Would it be possible to treat a oneOf of 2 types where one is null as optional? Example:

          "oneOf": [
            {
              "type": "integer",
              "format": "int32"
            },
            {
              "type": "null"
            }
          ]

currently generates an interface{} type in Go. IMO it would be preferable to generate a *int instead. I know this could be coded differently in JSON schema to generate the desired output, but unfortunately, the schema is not under our control.