提问者:小点点

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样式换行符,我知道超文本标记语言文本区域可以创建。这是我第一次真正使用YAML,所以只是我做错了什么,还是斯瓦格编辑器中的bug?


共3个答案

匿名用户

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

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

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

匿名用户

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

  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.

匿名用户

我在Swagger编辑器中使用纯JSON来避免双重语法(学习、调试、解析Web留档等)的问题。

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

出于某种原因,似乎需要双换行符\n,至少新行要在Swagger Editor上呈现。然而,当我将官方UberAPIYAML演示导出为JSON(文件-