0

是否可以定义某种常量参数,我们可以在多个请求中重用?例如,如果我有多个端点并且在所有端点中我需要相同的 id(例如书 id),是否有机会在文档中定义一次该 id 并在请求定义所需的示例值中引用它?

一些:

bookId := `563`
...........

书籍 [/books/{book_id}]

  • 参数
    • book_id(必填,数字,{bookId})

提前致谢。

4

1 回答 1

0

听起来您想使用MSON。MSON 允许您描述对象(如一本书),并在请求/响应中使用该对象。对象可以相互继承,并且可以在其他对象中或直接在请求/响应属性部分中覆盖值。

例子:

## Example Object(object) - Comment about Example Object
+ 'someKey': `someValue` (string, required) - Required String value

例如书:

# Data Structures
## Page (object) - A page in a book
+ `pageNumber` (number, required) - The number of the page

## Book (object) - A book
+ `numPages` (number, required) - The number of pages in the book
+ `title` (string, required) - The title of the book
+ `author` (string, required) - The author of the book
+ `pages` (array[object], required) - The pages in the book

## Book Collection (object) - A collection of books
+ books (array[object]) - The books in the collection

# API calls
## Example call [exaple/endpoint]
## Add new book (POST)
+ Request 200 (application/json; charset=utf-8)
    + Attributes (Book)
+ Response 201 (application/json; charset=utf-8)
    + Attributes (Book)
### Get all books (GET)
+ Request 200 (application/json; charset=utf-8)
+ Response 200 (application/json; charset=utf-8)
    + Attributes (Book Collection)
于 2017-05-31T00:10:40.893 回答