【问题标题】:Use of variables in blueprint with apiary在带有 apiary 的蓝图中使用变量
【发布时间】:2017-02-13 08:11:37
【问题描述】:

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

某种:

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

书籍 [/books/{book_id}]

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

提前致谢。

【问题讨论】:

    标签: apiary.io apiary


    【解决方案1】:

    听起来您想使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 2018-10-21
      相关资源
      最近更新 更多