Open
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
In the openAPI spec, if a schema has oneOf
but does not have a discriminator
and the config useOneOfDiscriminatorLookup
is set to True
, the unmarshalJson function is incorrectly generated. Such a scenario can arise when the schema looks as follows:
Pet:
description: a pet
oneOf:
- type: 'null'
- $ref: "#/components/schemas/dog"
- $ref: "#/components/schemas/cat"
Considering the fact that there are other schemas in this spec that may have oneOf
without type: 'null'
, the configuration useOneOfDiscriminatorLookup: True
is required. As a result, the unmarshal function for the above object is as follows:
func (dst *Pet) UnmarshalJSON(data []byte) error {
var err error
// this object is nullable so check if the payload is null or empty string
if string(data) == "" || string(data) == "{}" {
return nil
}
return nil
}
Building this generates an error because the variable err
is declared but not used.
openapi-generator version
Master build with last commit id 023e6dd
Suggest a fix
Allow unmarshalling of data even if nodiscriminator
is mentioned whenuseOneOfDiscriminatorLookup: True