【问题标题】:Getting syntax error in swagger code在招摇代码中出现语法错误
【发布时间】:2017-06-23 12:16:21
【问题描述】:

我有以下 YAML 文件,其中出现以下错误

YAML 语法错误第 44 行的映射条目缩进错误, 第8栏:描述:获取电影列表^

swagger: "2.0"
info:
  version: "0.0.1"
  title: Hello World App
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths 
basePath: /
# 
schemes:
  # tip: remove http to make production-grade
  - http
  - https
# format of bodies a client can send (Content-Type)
consumes:
  - application/json
# format of the responses to the client (Accepts)
produces:
  - application/json
paths:
  /movie:
    # our controller name
    x-swagger-router-controller: movie
    get:
    post:
      description: add a new movie to the list
      # movie info to be stored
      parameters:
        - name: title
          description: Movie properties
          in: body
          required: true
          schema:
            $ref: "#/definitions/Movie"
      responses:
        "200":
          description: Success
          schema:
            $ref: "#/definitions/GeneralResponse"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
       description: get the movies list
      # define the type of response for Success "200" and Error
        responses:
          "200":
          description: Success
          schema:
            $ref: "#/definitions/GetMoviesListResponse"
          default:
            description: Error
            schema:
              $ref: "#/definitions/ErrorResponse"
  /swagger:
    x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
  GetMoviesListResponse:
    required:
      - movies
    properties:
      # The array of movies
      movies:
        type: array
        items: 
          type: object
          properties:
            id:
              type: string
            title:
              type: string
            year:
              type: number
            month:
              type: string
  GeneralResponse:
    type: object
    properties:
      success:
        type: number
        description: returns 1 if successful
      description:
        type: string
        description: a short comment 
    required:
      - success
      - description
  ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string

【问题讨论】:

  • 将您的代码粘贴到editor.swagger.io 并按照提示操作。它具有缩进指示器,可以帮助您对齐代码。
  • 这也可以在我们本地托管的 Swagger UI 中看到。我能够确定发生错误的行,但我不知道如何解决它。没有 editor.swagger.io 就已经解决了。谢谢!

标签: yaml swagger swagger-ui swagger-2.0


【解决方案1】:

你的线路

       description: get the movies list

应该与:

        default:

在它上面,或与线

      responses:

以上。但它只是在这两者之间缩进。

【讨论】:

    猜你喜欢
    • 2021-08-16
    • 2020-10-23
    • 1970-01-01
    • 2023-03-10
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2018-01-27
    相关资源
    最近更新 更多