oneOf/anyOf support (including discriminator)#471
oneOf/anyOf support (including discriminator)#471deepmap-marcinr merged 13 commits intooapi-codegen:masterfrom
Conversation
|
Looks like the travis build is failing because lestrrat-go/jwx requires go 1.15, while the travis.yml specifies 1.13. So we have to either downgrade that package to v1.1.2 or bump the required version of go |
|
This is great work @Warboss-rus, thank you! Any plans to support arrays whose contents are oneOf / anyOf? For example... {
"type":"array",
"items":{
"oneOf":[
{
"$ref":"#/components/schemas/TypeA"
},
{
"$ref":"#/components/schemas/TypeB"
},
{
"$ref":"#/components/schemas/TypeC"
}
]
}
} |
|
Thanks, added a test for this case, will fix it this week |
…g new type for array items with union or additional properties, added some new tests for union, fixed README
|
I've reworked the code to support oneOf\anyOf along fixed properties, fixed type generation for array items that have additional properties or union parts (thanks @jonasrmichel), added some tests and updated information in README |
|
Brilliant work @Warboss-rus, thank you! @deepmap-marcinr @carmo-evan @karitham -- It'd be wonderful if these contributions could be merged for the next release. 🙏 |
|
Nice! Is there a release schedule? Really looking forward to being able to use this |
|
Nudge. @deepmap-marcinr these changes look good to me. They include new functionality, tests, and necessary documentation updates. What's required for merge approval? It'd be great to see these features in the next minor release. |
# Conflicts: # go.sum # pkg/codegen/templates/templates.gen.go
|
Would appreciate if these changes are merged in the next release. |
# Conflicts: # internal/test/components/components.gen.go
# Conflicts: # internal/test/components/components.gen.go # pkg/codegen/schema.go
# Conflicts: # internal/test/components/components.gen.go # pkg/codegen/schema.go
|
Impressive change, thank you. |
* Implemented oneOf/anyOf support * Fix travis build by regenerating templates.gen.go * go mod tidy after master merge * Reworked code to support fixed properties with oneOf, fixed generating new type for array items with union or additional properties, added some new tests for union, fixed README * Regenerate tests after merge * Fixed type generation for combinations of oneOf and additionalProperties and allOf * Regenerate components.gen.go after merge * Regenerate components.gen.go after merge Co-authored-by: ilya.bogdanov <ilya.bogdanov@ispringsolutions.com> Co-authored-by: ilya.bogdanov <ilya.bogdanov@ispring.com>
* Implemented oneOf/anyOf support * Fix travis build by regenerating templates.gen.go * go mod tidy after master merge * Reworked code to support fixed properties with oneOf, fixed generating new type for array items with union or additional properties, added some new tests for union, fixed README * Regenerate tests after merge * Fixed type generation for combinations of oneOf and additionalProperties and allOf * Regenerate components.gen.go after merge * Regenerate components.gen.go after merge Co-authored-by: ilya.bogdanov <ilya.bogdanov@ispringsolutions.com> Co-authored-by: ilya.bogdanov <ilya.bogdanov@ispring.com>
Implemented using json.RawMessage to delay parsing to concrete type until one of the getter (As...) methods is called. If the schema has a discriminator and its mapping, then ValueByDiscriminator method can be used to get an empty interface that holds one of the union types. Also, when using setters (From... methods), discriminator value will be filled automatically, according to mapping.
This implementation only supports JSON, so will not work in parameters (body only).
Also reverts to generating empty interface if "type" or other special properties are specified (for example, if only required properties differ in each variant)fixed that behavior, will now work properly with fixed propertiesTests for this feature are added to internal/test/components.