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

[BUG][C++][QT5] OneOf, AnyOf and AllOf Handling Erroneous #6378

Open
4 of 6 tasks
ghost opened this issue May 20, 2020 · 2 comments
Open
4 of 6 tasks

[BUG][C++][QT5] OneOf, AnyOf and AllOf Handling Erroneous #6378

ghost opened this issue May 20, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented May 20, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The generated code when using OneOf, AnyOf or AllOf contain errors, i.e.:

  1. AllOf: When a schema A for example uses AllOf together with > 1 subschemes (B, C, ...), only the first defined scheme (B) within AllOf is used within the generated client code for the scheme A.
  2. AnyOf and OneOf: Some included files are not generated.
openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 0.0.1
  title: Test
paths:
  /endpointAllOf:
    put:
      operationId: allOf
      description: "-"
      requestBody:
        description: Content All Of
        content:
          application/json:
            schema:
                $ref: '#/components/schemas/SchemaAllOf'
      responses:
        200:
          description: Success
  /endpointOneOf:
    put:
      operationId: oneOf
      description: "-"
      requestBody:
        description: Content One Of
        content:
          application/json:
            schema:
                $ref: '#/components/schemas/SchemaOneOf'
      responses:
        200:
          description: Success
  /endpointAnyOf:
    put:
      operationId: anyOf
      description: "-"
      requestBody:
        description: Content Any Of
        content:
          application/json:
            schema:
                $ref: '#/components/schemas/SchemaAnyOf'
      responses:
        200:
          description: Success

components:
  schemas:
    SchemaAllOf:
      type: object
      description: 'All Of Example'
      properties:
        information:
          type: string
          description: 'Some information field'
        additionalInfo:
          allOf:
          - $ref: '#/components/schemas/OptionA'
          - $ref: '#/components/schemas/OptionB'

    SchemaAnyOf:
      type: object
      description: 'Any Of Example'
      properties:
        information:
          type: string
          description: 'Some information field'
        additionalInfo:
          anyOf:
          - $ref: '#/components/schemas/OptionA'
          - $ref: '#/components/schemas/OptionB'

    SchemaOneOf:
      type: object
      description: 'One Of Example'
      properties:
        information:
          type: string
          description: 'Some information field'
        additionalInfo:
          oneOf:
          - $ref: '#/components/schemas/OptionA'
          - $ref: '#/components/schemas/OptionB'

    OptionA:
      type: object
      description: 'Option A'
      properties:
        data1:
          type: string
          description: 'Data'
    OptionB:
      type: object
      description: 'Option B'
      properties:
        data2:
          type: number
          description: 'Data'
Command line used for generation

java -cp openapi-generator-cli-4.3.1.jar org.openapitools.codegen.OpenAPIGenerator generate -i ${SPEC_FILE} -g cpp-qt5-client -o gen/ --model-name-prefix Test

Steps to reproduce

Execute code generation and take a look at the files (SchemaOneOf.h, SchemaAllOf.h, SchemaAnyOf.h, etc.).

Related issues/PRs

E.g. for oneOf: #15

Suggest a fix
@etherealjoy
Copy link
Contributor

etherealjoy commented Jun 22, 2020

@muttleyxd @stkrwork @ravinikam @MartinDelille
There seems to be a problem to handle in C++

std::variant/std::any

  • cannot handle c++ containers
  • in case of AnyOf/AllOf members of multiple classes are needed

OneOf

  • Exactly one class/type

AnyOf

  • Multiple classes/types

AllOf

  • All of the classes/types

Easiest way would be to generate separate members for the OneOf/AllOf/AnyOf refs
Then set the class to be valid for the ones for which data arrived.

Do you have some ideas and better proposals?

@wing328
Copy link
Member

wing328 commented Jun 22, 2020

I think it's an issue with the inline model resolver. As a workaround, please define the schemas (oneOf, anyOf, allOf) separately instead, e.g.

    SchemaAllOf:
      type: object
      description: 'All Of Example'
      properties:
        information:
          type: string
          description: 'Some information field'
        additionalInfo:
          $ref: '#/components/schemas/AllOfOptionAB'
    AllOfOptionAB:
      allOf:
      - $ref: '#/components/schemas/OptionA'
      - $ref: '#/components/schemas/OptionB'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants