2015-01-26 34 views
8

我想在Swagger编辑器中获得多行文字(顺便说一下,真棒工具!)。在swagger编辑器中的多行文字?

post: 
    summary: Translate one or more identifiers 
    description: | 
Translate one or more identifiers for one entity into the 
identifiers of another entity. Translate one or more 
identifiers for one entity into the identifiers of another entity. 

    consumes: 
    - application/json 

我试过用|和>,用不同的结局(增加缩进与空行),并且每路我能想到的,但它总是给人同样的错误:

YAML Syntax Error 
Can not read a block mapping entry; a multiline key may not be an implicit 
key at line 24, column 15: consumes:^

我看到JS-YAML错误指示问题最后是一个Windows风格的换行符,我知道HTML textareas可以创建它。这是我第一次真正使用YAML,那么这只是我做错了什么,或者是Swagger编辑器中的错误?

回答

17

我相信问题在于你开始描述块上的文本的方式。它必须缩进一个级别的描述正确的:这里的东西,对我工作的例子:

/{user-id}: 
get: 
    summary: Facebook User 
    description: | 
    Displays all information about a Facebook user, depending on access privileges. Displays all information about a Facebook user, depending on access privileges. 
    parameters: 
    - name: user-id 
     in: path 
     description: The Facebook user ID 
     required: true 
     type: string 

在我实际的代码中,说明三线长。

+1

很好的表演......谢谢!这个细节在YAML规范中并不完全清楚。 – fool4jesus 2015-01-27 19:06:30

1

想要添加JSON方法。我在Swagger Editor中使用纯JSON来避免双语法问题(学习,调试,解析web documentation等)。

"get": { 
    "description": "Hi\n\nThere", 

出于某种原因,双换行符\n似乎是必需的,至少在新线呈现上扬鞭编辑器。但是,当我将官方Uber API YAML demo作为JSON(文件 - >下载为JSON)导出时,生成的JSON只有单行换行字符,其中显示了多行文字。奇怪的。

相关问题