1

我是 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

4

1 回答 1

1

有几个问题:

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

2)嵌套对象也需要type: objectandproperties关键字。

正确的版本是:

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
于 2018-10-01T11:04:52.347 回答