首页 文章

如何获得Swagger API JS函数名称?

提问于
浏览
2

我是WordnikSwagger的新手 . 我通过Node.js JS module与它进行互动 .

查看生成的Swagger UI页面时,例如示例Petstore Swagger

enter image description here

查询服务器时很难说出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 后,当文档只显示 GET /pet/{petId} 时,他们如何知道查询 getPetById() 函数的函数?

当使用Wordnik API时,我发现使用 get{DATATYPE}() 函数(当然用 {DATATYPE} 替换为适当的值)是一般的经验法则,但是模式已经打破了 getPronunciation() - 它不相信文档说在任何地方 .

我怎样才能找到Swagger API的JS函数?

1 回答

  • 3

    JavaScript方法名称与Swagger文档中每个操作的 nickname 和/或 operationId 字段相同,具体取决于哪个可用 .

    这是Wordnik的一个例子:

    "path": "/word.{format}/{word}/pronunciations",
    "description": "",
    "operations": [
        {
        ...
        "nickname": "getTextPronunciations",
        "responseClass": "List[TextPron]"
        }
      ]
    },
    

    在此示例中, getTextPronunciations 是JS方法名称 .

    在Wordnik中,您可以通过单击文档单词部分上的“原始”按钮(“展开操作”按钮旁边)来获取swagger.json . 你可以在这里找到所有其他的swagger.json文件:http://developer.wordnik.com/v4/

相关问题