当前位置: 首页 > 知识库问答 >
问题:

使用OpenAPI(3.0.0)时,swagger不应具有其他属性

越勇锐
2023-03-14

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

< code > https://stack overflow . com/questions/45534187/path-and-formdata-parameter-at-same-time

< code > https://stack overflow . com/questions/50562971/swagger-editor-shows-the-schema-error-should-not-have-additional-properties-e

< code > https://stack overflow . com/questions/48283801/swagger-3-0-schema-error-should-not-have-additional-properties

我使用的是 3.0.0。我在第6行遇到以下问题。我经历了多次,缩进,移动了一些东西,然后重新开始。我已经使用了摇摆文档,但我仍然遇到这个问题。我将在下面发布山药。任何提示将不胜感激。

错误:不应具有其他属性: 附加属性: /作者/作者{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

共有1个答案

葛威
2023-03-14

在< code>/author/{authorId}前添加两个空格,使这一行与< code>/author具有相同的缩进。YAML要求嵌套项目的适当缩进。

paths:
  /author:
    ...
  /author/{authorId}:
    ...
 类似资料:
  • 请帮我解决这个问题。 错误: 路径处的架构错误不应具有其他属性additionalProperty:sepa/sct/{OriginatorAccount}

  • 我正试图通过使用< code>allOf来解决这个swagger API继承的问题。这是我的swagger yaml文件。 当我将其粘贴到在线编辑器中时,我收到以下错误,我很难弄清楚。

  • 我有一个API,它总是使用关联数组回答,其中只有一个条目包含包含最终结果的键“数据”。结果可以是一个对象或对象数组。这是API输出: 我怎样才能让swagger在文档中显示数据,即键的名称? 至于现在,我只得到大摇大摆的嵌套数组: 我需要数据键在从API返回时以swagger的形式显示。这可行吗?我还没有找到任何解决办法…:/ 我的yaml文件的部分内容: 任何帮助都将不胜感激:) 干杯

  • 我试图使用Swagger UI来创建和部署我的文档以及我用Spring Boot编写的API。我知道Swagger提供了一些注释来帮助在实际的控制器类中编写文档,但是我很难让它们做我需要的事情。 我的问题是我有一个通用的DTO类,每次调用我的API都会返回。此 DTO 具有用于通用对象字段。如果我直接使用这些对象,我知道我可以使用类似的东西 以便给出对象的JSON表示应该是什么样子的规范。但是,因

  • 样本数据 我使用AJV 6.10.0来验证我的数据,但我认为我有一个错误的模式定义。带Ajv选项: 实际上,我有6个错误,警告每个属性的其他属性 在验证allOf(姓名和电话)中的第一个对象时,验证在(地址、邮政编码、城市和州)中发现错误 如果我删除了第一个allOf对象(姓名、电话)的附加属性,在验证地址架构的过程中,验证会在(姓名和电话)上发现错误 如何解决模式定义

  • 我正在我的应用程序中构建一个新的endpoint,它使用作为验证器中间件。 在我的配置 () 文件中,我已将终结点的架构定义为: 我已经使用以下JSON正文使用Postman进行了测试: 但收到以下错误消息: 我不知道它为什么抱怨。我试着在中的配置下放入,但这并没有改变任何事情。我只是想确保body包含所需的字段。