Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Go] Heterogeneous array with oneOf #500

Open
langston-barrett opened this issue Jul 7, 2018 · 5 comments
Open

[Go] Heterogeneous array with oneOf #500

langston-barrett opened this issue Jul 7, 2018 · 5 comments
Labels
Client: Go Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf

Comments

@langston-barrett
Copy link

langston-barrett commented Jul 7, 2018

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.

@grokify
Copy link
Member

grokify commented Jul 9, 2018

oneOf is not yet supported in the core project. OAS3 features are being supported on a one by one basis right now.

A couple questions:

  • Are you working on a public or private API? If it's public, can you share the spec?
  • Is this model for a request, response, or both?

I'm tracking a number of specs here:

https://github.com/grokify/api-specs

So far, only one uses oneOf but it's a 2.0 spec, so not official.

https://github.com/grokify/api-specs/blob/master/salesforce/iot/v43.0.0/salesforce-iot-api-v43.0.0_swagger-v2.0.yaml#L3114-L3125

@langston-barrett
Copy link
Author

Unfortunately, the API and spec are private. Both.

@grokify
Copy link
Member

grokify commented Jul 9, 2018

I see this is for a response in your example. Do you also use oneOf for request schemas?

@langston-barrett
Copy link
Author

Yes, sorry I meant "both" to answer your second question.

@grokify
Copy link
Member

grokify commented Jul 9, 2018

Thanks for the clarification.

I've added a oneOf example schema to our example specs so we will be ready for testing when we have it.

#511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client: Go Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf
Projects
None yet
Development

No branches or pull requests

4 participants