swagger-api / swagger-api/swagger-codegen

[Python] JSON reference in $ref isn't acknowledged

Open
#7,119 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Invalid spec
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

It looks like I am having a couple issues.

  1. $ref: '#/definitions/Tenant/properties/name' gets rendered in the Tenant model with type Tenantpropertiesname
  2. The rendered Tenant model only has a name property. The Tenant definition below has 6 total properties which do not make it into the rendered model.
  3. Replacing $ref: '#/definitions/Tenant/properties/name' with a simple type: string fixes the type issue but still leaves a relatively empty Template model.
@property
    def name(self):
        """
        Gets the name of this Tenant.

        :return: The name of this Tenant.
        :rtype: Tenantpropertiesname
        """
        return self._name
Swagger-codegen version

2.2.3

Swagger declaration file content or url
patch:
      description: Update a tenant record.
      operationId: update
      tags:
      - tenants
      parameters:
      - $ref: "#/parameters/id"
      - in: body
        name: tenant
        description: The tenant properties to update
        schema:
          type: object
          required:
            - name
          properties:
            name:
              $ref: '#/definitions/Tenant/properties/name'

Tenant:
    type: object
    required:
      - name
      - handle
    properties:
      id:
        type: integer
        format: int32
        readOnly: true
      name:
        type: string
      handle:
        type: string
        pattern: '^[a-zA-Z0-9-]{0,62}$'
      createdAt:
        type: string
        format: date-time
        readOnly: true
      updatedAt:
        type: string
        format: date-time
        readOnly: true
      deletedAt:
        type: string
        format: date-time
        readOnly: true
Command line used for generation

swagger-codegen generate --input-spec fetched/tenant-service.yaml --lang python --output sdk

Steps to reproduce
Related issues/PRs

I am not able to find a related issue.

Suggest a fix/enhancement

Unsure.

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 running the reported swagger-codegen command with the supplied YAML declaration and inspect the generated Python Tenant model. Trace handling of the nested $ref to Tenant/properties/name and compare the result with all six properties in the Tenant definition. Done means the reference has the correct type and the generated model retains the complete Tenant property set.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.