OpenAPITools / OpenAPITools/openapi-generator
[BUG][GO] Incorrect field name (syntax error) in generated code with `oneOf` and empty object.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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
We would like a field to map to either (= oneOf) a defined object or an empty type: object subschema so that the generated code does not json-decode the field depending on circumstances.
In this case, the openapi-generator currently will generate code with compilation (syntax) errors similar to what's described in the related issue:
// FooPostRequestBaz - struct for FooPostRequestBaz
type FooPostRequestBaz struct {
FooPostRequestBazOneOf *FooPostRequestBazOneOf
MapmapOfStringinterface{} *map[string]interface{}
where MapmapOfStringinterface{} is not a valid field name.
Note 1: if the empty oneOf subschema is defined without a type (= undefined), the generated code will look like this:
// FooPostRequestBaz - struct for FooPostRequestBaz
type FooPostRequestBaz struct {
FooPostRequestBazOneOf *FooPostRequestBazOneOf
Interface{} *interface{}
}
where Interface{} is not a valid field name and *interface{} is not desired (should be interface{} instead).
Note 2: without the oneOf the generated request body is correct.
openapi-generator version
openapitools/openapi-generator-cli:latest sha256:aa8b02c8cdaef08f9478d967a5ea2640e94e6d63f34892ec72ef9458cf7ed305
OpenAPI declaration file content or url
https://gist.github.com/cooltea713705/6d94ac40546bc4ddef1ac34f7034e3c8
Generation Details
generatorName: go
generateInterfaces: true
validateSpec: false
Steps to reproduce
- Generate client
Related issues/PRs
Suggest a fix
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked OpenAPI declaration and reproduce the issue using the Go generator with the reported settings. Inspect the generated request model and the generator path handling oneOf schemas with empty or undefined object subschemas; done means the generated Go code has valid field names, compiles, and represents the empty case as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100