swagger编辑器中的多行文字?

问题描述 投票:9回答:3

我试图在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编辑器中的错误?

yaml swagger indentation swagger-editor
3个回答
29
投票

我相信问题是你在描述块上启动文本的方式。它必须在描述的右边缩进一级:这是一个适合我的东西的例子:

/{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

在我的实际代码中,描述是三行长。


2
投票

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

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

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


0
投票

这是缩进。应该是这样的:

  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.
© www.soinside.com 2019 - 2024. All rights reserved.