一般来说,我对Wordnik和Swagger比较陌生。我正在通过Node.js JS module与它交互。
当查看生成的swagger ui页面时,例如示例Petstore Swagger页面:
在查询服务器时,很难判断javascript函数应该是什么。
我指的javascript函数类似于petstore示例(来自swagger js文档):
var Swagger = require('swagger-client');
var client = new Swagger({
url: 'http://petstore.swagger.io/v2/swagger.json',
success: function() {
client.pet.getPetById({petId:7},{responseContentType: 'application/json'},function(pet){
console.log('pet', pet);
});
}
});
连接到
swagger.json
后,当文档只显示getPetById()
时,他们如何知道查询GET /pet/{petId}
函数的函数?在使用wordnik api时,我发现使用
get{DATATYPE}()
函数是一个普遍的经验法则(当然,{DATATYPE}
会被一个适当的值替换),但是模式已经被getPronunciation()
破坏了——它不起作用。我不相信医生说的。我怎样才能找到用于狂妄自大的api的js函数呢?
最佳答案
javascript方法名与swagger文档中每个操作的nickname
和/或operationId
字段相同,具体取决于哪个操作可用。
这是Wordnik中的一个例子:
"path": "/word.{format}/{word}/pronunciations",
"description": "",
"operations": [
{
...
"nickname": "getTextPronunciations",
"responseClass": "List[TextPron]"
}
]
},
在本例中
getTextPronunciations
是js方法名。在wordnik中,您可以通过单击文档的word部分(expand operations按钮旁边)上的raw按钮来获得swagger.json。您可以在这里找到所有其他swagger.json文件:http://developer.wordnik.com/v4/