swagger 编辑器中的多行字符串

sag*_*aga 6 yaml swagger swagger-ui

如果我将以下规范粘贴到 editor.swagger.io 中:

openapi: 3.0.0
info:
  title: Callback Example
  version: 1.0.0
paths:
  /streams:
    post:
      description: |
        first line
        second line
        third line
      responses:
        '201':
          description: subscription successfully created
          content:
            application/json:
              schema:
                description: subscription information
                required:
                  - subscriptionId
                properties:
                  subscriptionId:
                    description: this unique identifier allows management of the subscription
                    type: string
                    example: 2531329f-fb09-4ef7-887e-84e648214436

Run Code Online (Sandbox Code Playgroud)

描述呈现在一行上:

first line second line third line
Run Code Online (Sandbox Code Playgroud)

尽管 yaml 规范规定块样式字符串保留换行符:https://yaml-multiline.info/

如何在 swagger 编辑器中使用多行字符串?

小智 6

您可以使用下面提到的解决方案之一来获得多行招摇。

解决方案一:

description: |
  first line \
  second line \
  third line
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

解决方案2:

description: |
  first line <br>
  second line <br>
  third line
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


小智 0

您可以尝试通过以下方式使用br标签:

  description: |
    First line. <br> Second line.<br> Third line
Run Code Online (Sandbox Code Playgroud)

或者这也有效:

  description: First line. <br> Second line.<br> Third line
Run Code Online (Sandbox Code Playgroud)