Skip to content

[BUG] codegenModels contain incorrect oneOf info #6143

@spacether

Description

@spacether

Bug Report Checklist

When oneOf + allOf $ref schemas are combined in one composed schema, the oneOf reffed schemas are omitted and the allOf information is put in its place.

  • 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

When ingesting a v3 spec with the below schemas:

When ShapeInterface should be in allOf, and oneOf should contain ComplexQuadrilateral + SimpleQuadrilateral.
The python-experimental template iterates over:

{{#anyOf}}
              {{{.}}},
{{/anyOf}}
          ],
          'allOf': [
{{#allOf}}
              {{{.}}},
{{/allOf}}
          ],
          'oneOf': [
{{#oneOf}}
              {{{.}}},
{{/oneOf}}

So this is probable a core issue or a swagger-parser issue.
My example shows this happening when allOf + oneOf exist with a discriminator.
If the allOf definition is removed, the oneOf classes are correctly output.

This came up while working on #6124

openapi-generator version

master branch

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: >-
    This spec is mainly for testing Petstore server and contains fake endpoints,
    models. Please do not use this for any other purpose. Special characters: "
    \
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
  - name: store
    description: Access to Petstore orders
  - name: user
    description: Operations about user
paths:
  /foo:
    get:
      responses:
        default:
          description: response
          content:
            application/json:
              schema:
                type: object
                properties:
                  string:
                    $ref: '#/components/schemas/Shape'
  schemas:
    Shape:
      oneOf:
        - $ref: '#/components/schemas/Triangle'
        - $ref: '#/components/schemas/Quadrilateral'
      discriminator:
        propertyName: shapeType
    ShapeInterface:
      properties:
        shapeType:
          type: string
      required:
        - shapeType
    TriangleInterface:
      properties:
        triangleType:
          type: string
      required:
        - triangleType
    Triangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
      oneOf:
        - $ref: '#/components/schemas/EquilateralTriangle'
        - $ref: '#/components/schemas/IsoscelesTriangle'
        - $ref: '#/components/schemas/ScaleneTriangle'
      discriminator:
        propertyName: triangleType
    EquilateralTriangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/TriangleInterface'
    IsoscelesTriangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/TriangleInterface'
    ScaleneTriangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/TriangleInterface'
    QuadrilateralInterface:
      properties:
        quadrilateralType:
          type: string
      required:
        - quadrilateralType
    Quadrilateral:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
      oneOf:
        - $ref: '#/components/schemas/SimpleQuadrilateral'
        - $ref: '#/components/schemas/ComplexQuadrilateral'
      discriminator:
        propertyName: quadrilateralType
    SimpleQuadrilateral:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/QuadrilateralInterface'
    ComplexQuadrilateral:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/QuadrilateralInterface'

In the Triangle and Quadrilateral models in python-experimental the oneOf info incorrectly points to the allOf interfaces. So for Quadrilateral it looks like:

{
          'anyOf': [
          ],
          'allOf': [
          ],
          'oneOf': [
              shape_interface.ShapeInterface,
          ],
        }

DdebugModels=true results verify that the data is incorrect in the CodegenModel:

      "parent" : "shape_interface.ShapeInterface",
      "parentSchema" : "ShapeInterface",
      "interfaces" : [ "shape_interface.ShapeInterface" ],
      "anyOf" : [ ],
      "oneOf" : [ "shape_interface.ShapeInterface" ],
      "allOf" : [ ],
      "name" : "Quadrilateral",

DdebugOpenapi=true shows that the document data is correct:

      "Quadrilateral" : {
        "allOf" : [ {
          "$ref" : "#/components/schemas/ShapeInterface"
        } ],
        "discriminator" : {
          "propertyName" : "quadrilateralType"
        },
        "oneOf" : [ {
          "$ref" : "#/components/schemas/SimpleQuadrilateral"
        }, {
          "$ref" : "#/components/schemas/ComplexQuadrilateral"
        } ]
      },
Command line used for generation

add the above schemas to the v3 python-experimental document

generate -t modules/openapi-generator/src/main/resources/python -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml -g python-experimental -o samples/openapi3/client/petstore/python-experimental/ --additional-properties packageName=petstore_api

Steps to reproduce

produce the sample from the above spec
Look at the triangle and quadrilateral models and see that they lack the oneOf info.

Related issues/PRs

None seen

Suggest a fix

No idea

@sebastien-rosset this shows the allOf + oneOf use case that I mentioned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions