swagger-api / swagger-api/swagger-codegen

[Python] Codegen for definition with no properties leads to missing models

Open
#5,400 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Bug Swagger-Parser
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Similar to #4804

Models with no property are valid according to swagger 2.0 spec:

...

Unlike previous versions of Swagger, Schema definitions can be used to describe primitive and arrays as well.

{
    "type": "string",
    "format": "email"
}

...

but code generator does not support them. My suggestion is to create classes that extends primitive types in this case. e.g., for something like this:

"MyString": {
"Description": "My string description",
"type": "string",
}

generator should generate something similar to:

...
class MyString(string):
   """My string description"""
   pass
...

Also if there is no type, we should assume it is a free range schema and class should extend "object". An example for something like this is v1.Patch in kubernetes in this issue

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

No source file or test is named. Start by reproducing Python output for Swagger 2.0 definitions with no properties, then trace the definition-handling path and generated-model template; done means primitive and typeless definitions produce valid models rather than being omitted.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.