【发布时间】: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