swagger-api/swagger-codegen

[Python] spec 1.2 resourcePath breaks class filenames

Open

#5,312 建立於 2017年4月3日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)HTML (12,701 star) (5,474 fork)batch import
Client: PythonGeneral: Suggestionhelp wanted

描述

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.

貢獻者指南