swagger-api / swagger-api/swagger-codegen

[Python] spec 1.2 resourcePath breaks class filenames

Open
#5,312 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python General: Suggestion help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

For a swagger 1.2 spec file, if the element resourcePath exists, swagger-codegen does not properly create api class files.

Swagger-codegen version

[x] 2.2.2

Swagger declaration file content or url
{
    "apiVersion": "0.1",
    "apis": [
        {
            "description": "Testing auth.",
            "operations": [
                {
                    "method": "get",
                    "nickname": "authtest_get",
                    "notes": null,
                    "parameters": [],
                    "summary": "Get auth.",
                    "type": "object"
                }
            ],
            "path": "/authtest"
        }
   ],
    "description": "anything",
    "resourcePath": "/",
    "swaggerVersion": "1.2",
    "x-api-prefix": "/api/v1"
}
Command line used for generation

swagger-codegen generate -i bareminimum.json -l python -o bm1

Steps to reproduce
  1. Create a file bareminimum.json as shown.
  2. Run the swagger-codegen command.
  3. The bm1/swagger_client/apis/ directory will have a file called _api.py. This file should be default_api.py.
  4. Remove the "resourcePath": "/", from the json and re-run the command. bm1/swagger_client/apis/default_api.py will be generated.

There is no difference in logging output, no additional errors produced when resourcePath is present.

Suggest a Fix

I am new to swagger, and I'm using flask-restful-swagger to generate documentation from our flask application. This module only produces spec 1.2 files, though they are working on a 2.0 version. I have no option to control what gets placed in resourcePath other than to modify their code. If this is a bug with their module, I can open an issue with them.

I don't know how many people are using swagger-codegen with 1.2 spec files (I see resourcePath goes away in 2.0), but for those users, either catching this error and correcting it to generate the correct files, or failing with an obvious error message would be a suggested fix.

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 bareminimum.json and the swagger-codegen generate command using the python language target. Trace how the Swagger 1.2 resourcePath value affects the generated API filename, comparing output with and without that field. Done means the example generates default_api.py or reports a clear error instead of creating _api.py.

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.