【问题标题】:A string in Data Structures in the Api Blueprint documentApi Blueprint 文档中 Data Structures 中的字符串
【发布时间】:2020-02-26 14:22:02
【问题描述】:

如果有人能告诉我是否可以在数据结构中描述一个字符串,我将非常感激,因为我正在编写的内容(在下面的示例中)无法正常工作。 “日期”和“点”在我的文档中以不同的响应重复了很多次,这就是为什么我考虑将它带到数据结构中的原因。 在这种情况下,甚至有可能得到一个字符串而不是对象吗?

+ Response 200 (application/json)
    + Attributes
        + Date (Date)
        + Point (Point)
        + id: 123 (number)

# Data Structures 

## Date 
+ Date: `01.01.2019` (string) - or "2019-01-01"

## Point
+ Point: `(35.7545174,38.9170445)` (string)

这给了我在正文中的以下结构:

{
    "Date": {
              "Date": "01.01.2019"
    },
    "Point": {
              "Point": "(35.7545174,38.9170445)"
    },
    "id": 123
}

但我需要这个:

{
    "Date": "01.01.2019",
    "Point": "(35.7545174,38.9170445)",
    "id": 123
}

【问题讨论】:

    标签: api blueprint apiblueprint apiary.io apiary


    【解决方案1】:

    您需要将 Date 和 Point 定义为字符串:

    ## Date (string)
    

    这是你的例子:

    FORMAT: 1A
    
    # Stackoverflow 60415996
    
    ## Path [/]
    
    ### Verb [GET]
    
    + Response 200 (application/json)
        + Attributes
            + Date (Date)
            + Point (Point)
            + id: 123 (number)
    
    # Data Structures 
    
    ## Date (string)
    
    ### Sample
    
    2019-05-12T04:55:00-01
    
    ### Sample
    
    01.01.2019
    
    ### Sample
    
    2019-01-01
    
    ## Point (string)
    
    ### Sample
    
    (35.7545174,38.9170445)
    

    这是一个结果: https://stackoverflow60415996.docs.apiary.io/

    你可以在https://github.com/apiaryio/msonhttps://github.com/apiaryio/mson-zoo/找到很多例子

    【讨论】:

    • 非常感谢!在 Body 中看起来像 "2019-05-12T04:55:00-01\n\n" 和那些 \n\n 可以吗?
    • 不幸的是,这是 API 蓝图解析器 Drafter 中的一个错误(跟踪于 github.com/apiaryio/drafter/issues/607
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 2018-08-09
    相关资源
    最近更新 更多