如何使用 Swagger 参数化 POST 的 URL? [英] How do I parametrize a URL for POST using Swagger?

查看:114
本文介绍了如何使用 Swagger 参数化 POST 的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Swagger 定义以下路径:

I would like to define the following path using Swagger:

/api/libraries/1234/books

POST一本书到图书馆的图书收藏,其id为1234.

And POST a book to the books collection of library, whose id is 1234.

在示例中,我在这里看到:https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/json/petstore-with-external-docs.json

In the example, I've seen here: https://github.com/swagger-api/swagger-spec/blob/master/examples/v2.0/json/petstore-with-external-docs.json

它显示,例如,您可以指定:libraries/{id}/books,但您必须将其定义为单独的路径对象.

It shows like, you can specify for example: libraries/{id}/books, but you have to define it as a separate path object.

例如,与libraries比较,用于GET目的;这将检索您的库列表.

For example, comparing with libraries, for GET purposes; which will retrieve you a list of libraries.

有没有办法定义一个sub path对象(例如:在libraries定义了一个idsub path,在其下定义了一个bookssub path代码>;或者employees的另一个子路径?

Is there a way to define a sub path object (for example: under libraries define a sub path of id), and under it a sub path of books; and maybe another sub path of employees?

推荐答案

简短的回答是否定的.

根据 swagger 规范 2.0 不支持嵌套路径;你必须独立定义路径(https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#pathItemObject).

Nesting paths is not supported according to the swagger spec 2.0; you have to define paths independently (https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#pathItemObject).

然后您可以使用标签对资源列表进行分组.

You can then group a list of resources using tags.

拥有原子路径的原因在于大摇大摆地严格遵守 REST 规范.在 REST 中,资源链接到独立的原子操作(与 SOAP/RPC 不同).

Reason for having atomic paths lies with swaggers strong compliance with the REST specs. In REST resources are linked to independent atomic operations (unlike SOAP/RPC).

这篇关于如何使用 Swagger 参数化 POST 的 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆