[BUG][GO] Generating golang models from openapi 3.3 containing oneOf results in undefined struct
See original GitHub issueBug 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
Using the generator to generate models for golang it generates models that are not defined. I am unsure if this is configuration or limitation.
openapi-generator version
Openapi-generator-cli docker-hub: Digest:sha256:829f0b601005c28950ed55c65d853f2caead265730782b2c7c48812bf8135222
OpenAPI declaration file content or url
{
"openapi": "3.0.3",
"info": {
"title": "Exampleapi",
"version": "2.0.0"
},
"paths": {
"/temp": {
"get": {
"responses": {
"200": {
"description":"Tmp",
}
}
}
}
},
"components": {
"schemas": {
"Foo": {
"type": "object",
"properties": {
"Bar": {
"oneOf": [
{"$ref": "#/components/schemas/FooBar"},
{"$ref": "#/components/schemas/BarFoo"}
]
}
}
},
"FooBar": {
"type": "object",
"title": "FooBar",
"properties": {
"example": {
"type": "string"
}
}
},
"BarFoo": {
"type": "object",
"title": "BarFoo",
"properties": {
"example": {
"type": "string"
}
}
}
}
}
}
Generation Details
Generation command
openapi-generator-cli generate \
-i "/swagger.json" \
-g go \
--global-property models,supportingFiles=utils.go,modelDocs=false \
--additional-properties \
--minimal-update \
-p enumClassPrefix=true \
--enable-post-process-file \
--additional-properties packageName="Some Name" \
-o "/Some_Location"
Steps to reproduce
Run above code on above swagger to replicate. The result given the expectations will result in:
type Foo struct {
Bar *OneOfFooBarBarFoo `json:"Bar,omitempty"` <-- Undefined
}
Where OneOfFooBarBarFoo is not defined.
Related issues/PRs
No
Suggest a fix
Given go does not support generics a resonable response would be:
type Foo struct {
Bar *interface{} `json:"Bar,omitempty"`
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:11
Top Results From Across the Web
Generating from openapi to golang using ... - Stack Overflow
Generating golang code using openapi-generator-cli on an openapi 3.3 spec containing oneOf keyword results broken and uncompilable code.
Read more >Generating Go structs from OpenAPI schemas - Jamie Tanna
How to generate Go structs really quickly and easily, with no manual work, using the oapi-codegen project.
Read more >Go Code Generation from OpenAPI spec - Habr
OpenAPI specification is a modern industrial standard for REST API. This standard has fantastic tooling support and allows you to conveniently ...
Read more >REST API implementations in Golang with OpenAPI ...
Tools to generate code and documentation for Go API servers and use a gRPS-gateway to build a server using gRPC, REST API, WebSocket, ......
Read more >openapi3 - Go Packages
Validate returns an error if Components does not comply with the OpenAPI spec. type Contact ¶. type Contact struct { ExtensionProps `json:"-" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue, any progress seen on this?
Leaving this in case anyone else runs into this bug (top result from google), since it’s unclear.
Using
oneOf
directly causes problems when generating the sdkHowever, this can be fixed by placing the above into a separate object