【问题标题】:swagger-codegen: java.io.FileNotFoundException: Unable to read APIswagger-codegen:java.io.FileNotFoundException:无法读取 API
【发布时间】:2014-04-16 16:53:52
【问题描述】:

我正在尝试使用swagger-codegen 来根据我的 Swagger 资源文件生成代码。但是,我在尝试生成代码时遇到了以下错误:

base path is http://my.documentation.com/api/docs/v1.json
java.io.FileNotFoundException: http://my.documentation.com/api/docs/v1.json/authenticateUser

似乎swagger-codegen 试图通过在v1.json 之后附加操作名称来读取方法定义,但我不确定为什么,因为操作名称是在v1.json 本身内部定义的:

{
    "basePath":"https://my.api.com/v1",
    "swaggerVersion":"1.2",
    "apiVersion":"1.0.0",
    "resourcePath":"v1",
    "apis":[
        {
            "path":"/authenticateUser",
            "description":"Authenticates a user into the API",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Authenticates a user into the API",
                    "nickname":"authenticateUser",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"username",
                            "type":"string",
                            "required":true,
                            "description":"Name of of user to authenticate"
                        },
                        {
                            "paramType":"query",
                            "name":"password",
                            "type":"string",
                            "required":true,
                            "description":"User's password"
                        }
                    ],
                    "notes":"Returns access token in the response object"
                }
            ]
        },
    ...
    ]
}

我不完全确定 swagger-codegen 期待什么格式。 API 的 basePath 和 API 的文档是否需要相同?请注意,文档的文档托管在与 API 本身不同的 basePath 上。我不确定这是否重要。

我还会注意到我的 swagger 资源文件 v1.json 是使用 swagger-php 生成的,并且使用 swagger-ui 可以正常工作。

【问题讨论】:

  • 看来文档basePath 需要设置为http://my.documentation.com/api/docs/。这解决了问题。

标签: json code-generation swagger swagger-php


【解决方案1】:

将 basePath 更改为 http://my.documentation.com/api/docs/ 而不是 http://my.documentation.com/api/docs/v1.json 解决了该问题。

【讨论】:

    猜你喜欢
    • 2014-09-26
    • 1970-01-01
    • 2014-06-08
    • 2017-11-11
    • 1970-01-01
    • 2022-01-21
    • 2018-05-22
    • 1970-01-01
    • 2016-04-21
    相关资源
    最近更新 更多