【问题标题】:swagger-codegen is not correctly generating common parameters for any languageswagger-codegen 未正确生成任何语言的通用参数
【发布时间】:2020-08-03 00:35:41
【问题描述】:

根据swagger documentation,我应该能够拥有所有操作共享的公共参数。问题是在本地运行 codegen 时,生成的代码没有任何 common path 参数。下面的yaml 生成任何语言的代码(我尝试了两种)。

非常令人困惑的是,如果我在https://editor.swagger.io/ 中使用这个确切的yaml,生成的代码确实 有路径参数。我为两种不同的语言运行了这个,打字稿:

和 C#:

左边是editor.swagger.io中生成的代码,右边是我在本地运行codegen生成的代码。

在这两种情况下,.swagger-codegen\VERSION 文件都是3.0.20,这是我正在使用的,但https://editor.swagger.io/ 生成的代码确实有参数路径。

这个简单的 yaml 文件重现了这个问题:

openapi: 3.0.2
info:
    title: title
    version: 1.0.0
paths:
    '/instances/{id}':
        summary: Manipulate a particular instance
        get:
            responses:
                '200':
                    description: Ok
                    content:
                        text/plain:
                          schema:
                            type: string
                            example: pong
            summary: Fetches an instance
        parameters:
            -   in: path
                name: id
                schema:
                    type: integer
                required: true
components:
    securitySchemes:
        bearerAuth:
            scheme: bearer
            bearerFormat: JWT
            type: http

用于生成的命令行:

java   ^
    -classpath bin/swagger-codegen-cli.jar                                      ^
    -DdebugOperations                                                           ^
    io.swagger.codegen.v3.Codegen                                               ^
    generate                                                                    ^
    -i enterpos-api.yaml                                                        ^
    -l typescript-angular                                                       ^
    -o generated-code/typescript-angular-builtin

这产生了这个输出:https://gist.github.com/alanboy/45ce792255e079dd0de4f70449ebf455。我觉得这可能是错误的用法或我的 yaml 有问题,但我不知道是什么。

【问题讨论】:

标签: swagger swagger-codegen swagger-editor


【解决方案1】:

问题是主类。我注意到使用 io.swagger.codegen.v3.Codegen 类会产生不正确的结果:

java -classpath bin/swagger-codegen-cli.jar  io.swagger.codegen.v3.Codegen  <more>
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

但这有效:

java -jar bin/swagger-codegen-cli.jar <more>

这导致我在 jar 中打开 MANIFEST.MF 并注意到主类实际上是这样的:

Main-Class: io.swagger.codegen.v3.cli.SwaggerCodegen

然后我像这样运行命令,一切都按预期工作。

java -classpath bin/swagger-codegen-cli.jar  io.swagger.codegen.v3.cli.SwaggerCodegen  <more>
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

【讨论】:

    猜你喜欢
    • 2022-01-22
    • 2015-05-07
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2021-05-14
    • 2020-06-15
    相关资源
    最近更新 更多