swagger-api / swagger-api/swagger-codegen

[Python] Generated python code doesn't show all the fields in the response in case of nested fields

Open
#9,373 2 comments 0 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

Hi,
We are facing issues with the response via generated python code. If the response schema contains fields like:

getSomeItems:
    type: object
    required:
      - count
    properties:
     someItems:
        description: List of some items available for your account
        type: array
        items:
          type: object
          $ref: '#/definitions/getSomeItem'
      count:
        type: integer
        format: int64
        description : Number of items available for your account
        example: 5

Then it works fine. But if the response schema is somewhat like this:

getCampaigns:
    type: object
    required:
      - count
    properties:
      campaigns:
        type: array
        items:
          type: object
          allOf:
            - $ref: '#/definitions/getExtendedCampaignOverview'
            - type: object
              required:
                - recipients
                - statistics
              properties:
                recipients:
                  allOf:
                   - $ref: '#/definitions/getCampaignRecipients'
                statistics:
                  allOf:
                  - $ref: '#/definitions/getExtendedCampaignStats'
                shareLink:
                  type: string
                  format: url
                  description: Link to share the campaign on social medias
                  example: 'http://dhh.sendinblue.com/fhsgccc.html?t=9865448900'
      count:
        type: integer
        format: int64
        description: Number of Email campaigns retrieved
        example: 24

Then it doesn't show fields listed in getExtendedCampaignOverview at all. It just shows recipients and statistics

Can you please look into the same. Its breaking most of the response schemas at our end.

Swagger-codegen version

3.0.5

We also tried for 3.0.7 but things are no better there.

Swagger declaration file content or url

Here is a link to our swagger file:
https://api.sendinblue.com/v3/swagger_definition.yml

Command line used for generation

Following command was used to generate python code:
swagger-codegen generate -i projects/projectA/swagger_definition.yml -l python -o projects/python-sib-wrapper/ -c Desktop/python_config.json

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 with the linked swagger_definition.yml and reproduce generation using the documented swagger-codegen command with the Python language target. Compare output for the simple nested response and the getCampaigns schema using allOf references. Done means generated Python models expose the fields inherited from getExtendedCampaignOverview as well as recipients and statistics.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.