25

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

4

4 回答 4

47

我认为问题在于您在描述块上开始文本的方式。它必须在描述右侧缩进一级:这是一个对我有用的示例:

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

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

于 2015-01-27T16:32:26.503 回答
8

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

  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.
于 2019-02-15T15:28:23.420 回答
4

想要添加 JSON 方法。我在 Swagger 编辑器中使用纯 JSON 以避免双重语法问题(学习、调试、解析Web 文档等)。

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

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

于 2016-12-02T08:24:19.327 回答
0

在我的情况下,它只是一个/,我应该在我的category.md中放入永久链接的开头:

permalink: /{{ blog.catPermalinkPrefix }}/{{ category.slug }}/ 
于 2021-02-18T14:25:03.963 回答