swagger-api / swagger-api/swagger-codegen

[PYTHON] List types not handled correctly

Open
#10,592 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

List types in the Python generated models are not handled correctly. Please see details below.

Swagger-codegen version

swagger-codegen-cli 3.0.23

Swagger declaration file content or url
openapi: 3.0.0
paths:
  /pets:
    get:
      tags:
        - pet
      summary: Get pets
      operationId: getPets
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pets'
components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
          description: 'Pet name'
    Pets:
      type: array
      items:
        $ref: '#/components/schemas/Pet'
Command line used for generation

java -jar swagger-codegen-cli-3.0.23.jar generate -i model.yaml -l python -o python_client

Steps to reproduce

java -jar swagger-codegen-cli-3.0.23.jar generate -i model.yaml -l python -o python_client
Notice:

    attribute_map = {
    }

in python_client/swagger_client/models/pets.py.

However the java client seems to work:
java -jar swagger-codegen-cli-3.0.23.jar generate -i model.yaml -l java -o java_client

public class Pets extends ArrayList<Pet> {

in java_client/src/main/java/io/swagger/client/model/Pets.java.

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/9664. I do not agree with the conclusion drawn in that issue, the spec is valid and the java generator handles it correctly. Following the suggested solution of wrapping the array in an object will break existing clients and introduce unnecessary complexity in the spec.

Suggest a fix/enhancement

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided OpenAPI YAML and Python generation command, then inspect python_client/swagger_client/models/pets.py and compare it with the Java output. Trace how the Python generator handles the array schema and verify that the generated list model represents its Pet items correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.