swagger-api / swagger-api/swagger-codegen

[PYTHON] Problem with Discriminator

Open
#12,089 1 comment 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

I am trying to use polymorphism with discriminator

Swagger-codegen version

3.0.36

Swagger declaration file content or url
"discriminator": {
    "propertyName": "type",
    "mapping": {
      "individualApplication": "#/definitions/IndividualApplication",
      "businessApplication": "#/definitions/BusinessApplication",
      "trustApplication": "#/definitions/TrustApplication"
    }
  }
Command line used for generation

java -jar swagger-codegen-cli-3.0.36.jar generate -i openapi.json -l python -o /output

Error

AttributeError: module 'swagger_client.models' has no attribute '#/components/schemas/IndividualApplication'

Suggest a fix/enhancement

I need the attribute to be "IndividualApplication" without the 'swagger_client.models'
or maybe try to ignore #/components/schemas/

Am I right or am I doing something wrong?

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

Reproduce the issue with swagger-codegen-cli-3.0.36.jar, the supplied OpenAPI discriminator mapping, and the -l python command. Inspect how the generated swagger_client.models lookup handles the mapping references; done means the generated client resolves IndividualApplication, BusinessApplication, and TrustApplication without treating the JSON reference as an attribute name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.