首页 > 解决方案 > swagger 不应该有使用 OpenAPI (3.0.0) 的附加属性

问题描述

我查看了已经提出的问题,但没有一个能够解决我的问题。

https://stackoverflow.com/questions/45534187/path-and-formdata-paramter-at-the-same-time

https://stackoverflow.com/questions/50562971/swagger-editor-shows-the-schema-error-should-not-have-additional-properties-e

https://stackoverflow.com/questions/48283801/swagger-3-0-schema-error-should-not-have-additional-properties

我正在使用OpenAPI 3.0.0. 我在 line 收到以下问题6。我经历了多次缩进,移动了一些东西,然后重新开始。我已经使用了,swagger documentation但我仍然遇到这个问题。我将在yaml下面发布。任何提示将不胜感激。

Error: should not have additional properties: additionalProperty: /author/author{id}

# openapi: 3.0.0

#   info:
#   version: 0.0.1
#   title: Author API
#   description: Author API documentation
openapi: 3.0.0
info:
  title: Author API
  description: Author API
  version: 0.0.1

servers:
  - url: 'http://localhost:8080/'
    description: Local dev server

    # post new author      done
    # find author {id}     done
    # get all author       done
    # update author {id}   done
    # delete author {id}   done


paths:
  /author:
    post:
      summary: Add a author to database
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Author'
      responses:
        '201':
          description: return the author to the user with the id attached
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Author'
    get:
      summary: Get all the authors in the database
      responses:
        '200':
          description: Return all the authors in the database
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Author'

/author/{authorId}:
    update:
      summary: update the author with the id
      parameters:
        - name: authorId
          in: path
          required: true
          description: Id of the author to update
          schema:
            type: integer
      responses:
        '200':
          description: Return just the author at that id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Author'

      get:
        summary: get the author with the specific id
        paramaters:
          - name: authorId
            in : path
            required: true
            description: Id of the author to retrieve
            schema:
              type: integer
        responses:
          '200':
            description: Return just the author at that id
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/Author'

      delete:
        summary: Remove a author by the given Id
        parameters: 
          - name: authorId
            in: path
            required: true
            description: Id of the author to delete
            schema:
              type: integer
        responses:
          '200':
            description: The author was successfully removed

components:
  schemas:
    Author:
      type: object
      properties:
        authorId:
          type: integer
        firstName:
          type: string
        lastName:
          type: string
        street:
          type: string
        city:
          type: string
        state:
          type: string
        postalCode:
          type: string
        phone:
          type: string
        email: 
          type : string

标签: yamlswaggeropenapi

解决方案


在前面添加两个空格/author/{authorId},使这一行的缩进与/author. YAML 需要正确缩进嵌套项。

paths:
  /author:
    ...
  /author/{authorId}:
    ...

推荐阅读