【问题标题】:SwaggerUI/YAML - Parser error bad indentation of a mapping entrySwaggerUI/YAML - 映射条目的解析器错误缩进错误
【发布时间】:2018-09-13 13:14:56
【问题描述】:

Screenshot of Swagger Editor & code 嗨,我是 API 测试和 Swagger 的新手,在 Swagger 编辑器中收到此解析器错误消息,我在定位问题时遇到问题。

下面是代码的复制粘贴。

错误消息是“bad indentation of a mapping entry”,并显示在 --> in: "path"

我遵循了这个 YouTube 教程 --> https://www.youtube.com/watch?v=CoUl9_NWdqQ

swagger: '2.0'
info:
  version: 'v1.0'
  title: 'Random'

# Added by API Auto Mocking Plugin
host: virtserver.swaggerhub.com
basePath: /GroovySalmon/DOITNOW/v1.0
schemes:
  - https

paths:
  /vehicles/{id}/data_request/drive_state:
    get:
      operationId: "drive_state"
      description: "Returns the driving and position state of the vehicle"
      parameters:
      **-name: "id"**
          in: "path"
          description: "The ID number of the car"
          required: true
          type: "String"
      responses:
        200:
          description: "Success"
          schema:
            properties:
              shift_state:
                type: "String"
                example: "sport"
              speed:
                type: "number"
                format: "double"
                example: 94.5
              latitude:
                description: "degrees north of the equator"
                type: "number"
                format: "double"
                example: 37.345
              longitude:
                description: "degrees west of the prime meridian"
                type: "number"
                format: "double"
                example: 122.1243
              heading:
                description: "integer compass heading"
                type: "integer"
                format: "int32"
                minimum: 0
                maximum: 359
                example: 4
              gps_as_of:
                description: "unix timestamp of gps fix"
                example: "1234934991232"

【问题讨论】:

    标签: swagger swagger-2.0 swagger-editor


    【解决方案1】:

    改变

    type: "String"
    

    type: "string"
    

    注意“string”中的小写“s”。

    所有 OpenAPI type 值都是小写且区分大小写的。


    另外,请确保参数定义中- 后面有空格(以及通常在 YAML 列表中),并且缩进是正确的:

    - name: "id"
      in: "path"
      ...
    

    【讨论】:

    • 感谢您指出这一点。虽然没有做到这一点。 :=)
    • @Dan 好像也有缩进和间距的问题,请看更新的答案。
    • 干!是的,这个答案拯救了一天。感谢您的帮助!
    • @Dan 很高兴为您提供帮助!考虑accepting这个答案将您的问题标记为已解决。
    • 完成!再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多