2015-01-26 36 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只有單行換行字符,其中顯示了多行文字。奇怪的。

相關問題