【问题标题】:should NOT have additional properties不应该有额外的属性
【发布时间】:2018-10-01 10:59:35
【问题描述】:

我是 Open API 规范的新手(ia m 使用 3.0)。我正在使用 swagger Editor 在线工具,我收到一个奇怪的错误:

"不应该有额外的属性 附加属性:Data1、Data2"

这是我正在使用的 YAML 文件示例:

paths:
 /api/assignment:
    post:
      tags:
      - Assignment
      summary: "Endpoint to create Resources in  system"
      description: "This endpoint will create blah blah"
      operationId: CreateResource
 parameters:
    - name: assignment
      in: body
      description: "This is an  object to be sent"
      required: true
      schema:
            type: object
            properties:
              Ganesh:
                type: integer
              Test:
                type: string
              RefClaim:
                Data1:
                  FirstName:
                    type: string
                  LastName:
                    type: string
                Data2:
                  FirstName2:
                    type: string
                  LastName2:
                    type: string

我已经看到了所有的问题并尝试了这些问题,但我无法得到答案。 注意:我使用的是 Open Api 规范 3.0.1

【问题讨论】:

    标签: swagger openapi swagger-editor openapi-generator


    【解决方案1】:

    有几个问题:

    1) in: body 参数是 OpenAPI 2.0 的东西。 OpenAPI 3.0 改用requestBody

    2) Nested objects 还需要 type: objectproperties 关键字。

    正确的版本是:

    paths:
     /api/assignment:
        post:
          tags:
          - Assignment
          summary: "Endpoint to create Resources in  system"
          description: "This endpoint will create blah blah"
          operationId: CreateResource
          requestBody:   # <-----------
            required: true
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    Ganesh:
                      type: integer
                    Test:
                      type: string
                    RefClaim:
                      type: object      # <-----------
                      properties:       # <-----------
                        Data1:
                          type: object  # <-----------
                          properties:   # <-----------
                            FirstName:
                              type: string
                            LastName:
                              type: string
                        Data2:
                          type: object  # <-----------
                          properties:   # <-----------
                            FirstName2:
                              type: string
                            LastName2:
                              type: string
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 2021-04-01
      • 1970-01-01
      • 2019-11-02
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多