Skip to content

python-flask model incorrect for multi-level $ref #12541

Open
@jcsammy

Description

@jcsammy

Overview

Testing using v3.0.68, when a schema references another schema which is itself a reference, the resulting python-flask model does not contain all of the expected items.

Example

The following OAD is used to demonstrate the problem:

openapi: 3.0.4
info:
  title: Demo of ref bug
  description: |-
    This demonstrates the multi-ref bug
  version: 1.0.0
  
paths:
  /blobs:
    get:
      summary: Return a list of blobs
      description: Return a list of blob (or sub-class) objects
      operationId: getBlobs
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: "array"
                items:
                  anyOf:
                    - $ref: '#/components/schemas/BlobA'
                    - $ref: '#/components/schemas/BlobB'
                    - $ref: '#/components/schemas/BlobC'
                    - $ref: '#/components/schemas/BlobD'
components:
  schemas:
    BlobA:
      description: A class blob
      type: object
      required: [a_item]
      properties:
        a_item:
          description: Item at A class level
          type: string
    BlobB:
      description: B class blob
      allOf:
        - $ref: "#/components/schemas/BlobA"
        - type: object
          properties:
            b_item:
              description: Item at B class level
              type: string
    BlobC:
      description: C class blob
      allOf:
        - $ref: "#/components/schemas/BlobB"
        - type: object
          properties:
            c_item:
              description: Item at C class level
              type: string
    BlobD:
      description: D class blob
      allOf:
        - $ref: "#/components/schemas/BlobC"
        - type: object
          properties:
            d_item:
              description: Item at D class level
              type: string

Expectation

It is expected that BlobA contains only A class items, BlobB contains A and B class items, BlobC contains A, B, and C class items, and BlobD contains, A, B, C, and D class items.

This expectation works in SwaggerEditor, where the schema matches the above.

Result

The resulting python-flask server stub only seems to contain one parent class worth of items.

For instance BlobD model is as follows:

class BlobD(Model):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    """
    def __init__(self, d_item: str=None, c_item: str=None):  # noqa: E501
        """BlobD - a model defined in Swagger

        :param d_item: The d_item of this BlobD.  # noqa: E501
        :type d_item: str
        :param c_item: The c_item of this BlobD.  # noqa: E501
        :type c_item: str
        """
        self.swagger_types = {
            'd_item': str,
            'c_item': str
        }

        self.attribute_map = {
            'd_item': 'd_item',
            'c_item': 'c_item'
        }
        self._d_item = d_item
        self._c_item = c_item

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions