Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #500
Closed
Open
Issue created Jul 07, 2018 by Administrator@rootContributor

[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

#15

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.

Assignee
Assign to
Time tracking