1
我正在嘗試使用swagger-codegen
來根據我的Swagger資源文件生成代碼。但是,試圖生成代碼的時候我遇到了以下錯誤:swagger-codegen:java.io.FileNotFoundException:無法讀取API
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的基礎路徑和API的文檔需要相同嗎?請注意,文檔的文檔託管在獨立的basePath上,而不是API本身。我不確定這是否重要。
我還會注意到我的招搖資源文件v1.json
是使用swagger-php
生成的,並且與swagger-ui
一起工作正常。
它似乎需要將文檔basePath設置爲'http:// my.documentation.com/api/docs /'。這解決了這個問題。 – dtg