[Go] Heterogeneous array with oneOf
Created by: langston-barrett
Description
Structs are not properly generated to handle arrays with item schema using oneOf
. For instance, for the swagger.yml
in the next section, an empty struct is generated:
type Bar struct {
}
This is what should be generated:
type Bar struct {
Obj1 []string `xml:"Obj1"`
Obj2 []bool `xml:"Obj2"`
}
See the following Go playground: https://play.golang.org/p/rdNNL6nUUl1
openapi-generator version
Docker container version
OpenAPI declaration file content or url
---
openapi: 3.0.0
info:
title: oneof
version: 0.1.0
paths:
"/foo":
get:
summary: foo
responses:
'200':
description: OK
content:
application/xml:
schema:
"$ref": "#/components/schemas/Bar"
components:
schemas:
Bar:
type: array
items:
oneOf:
- $ref: '#/components/schemas/Obj1'
- $ref: '#/components/schemas/Obj2'
Obj1:
type: string
Obj2:
type: bool
Command line used for generation
sudo docker run --rm -v ${PWD}:/local \
openapitools/openapi-generator-cli generate \
-i /local/swagger.yml \
-g go \
-o /local/generated/ \
-D withXml=true | grep -v INFO
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
The Go codegen should support arrays with oneOf
schemata by integrating both/all types as list properties of the generated struct
as in the above example.