Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

openapi - Swagger Editor - Additional Properties Error

I'm just starting to use Swagger Editor/OpenAPI 3 spec and so it's not going good so far. I have installed and running Swagger Editor v. 3.15.2 on my local machine.

This is the yaml I have so far:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test
paths:
  /object:
    post:
      summary: Create an object
      operationId: createObject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Object"
    responses:
      '201':
        description: Created
components:
  schemas:
    Object:
      required:
        - name
        - description
      properties:
        name:
          type: string
        description:
          type: string

And it's displaying this error:

Errors


Resolver error
e is undefined
Structural error at paths./object
should NOT have additional properties
additionalProperty: responses
Jump to line 6
Structural error at paths./object.post
should have required property 'responses'
missingProperty: responses
Jump to line 7

I have ensured that I am using two spaces for all the indents. When I copied the yaml from the editor and put it into Notepad++ it looked fine. I also pasted it into another editor and noticed that it only used line feeds and not carriage returns. I updated it to use both and still get the same error.

I have looked at other questions with the same problem but none of the solutions worked for me. So, not sure what I'm doing wrong. Any guidance is greatly appreciated.

question from:https://stackoverflow.com/questions/65923580/swagger-editor-additional-properties-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have a small indentation problem.

Add one indentation level to

responses:
  '201':
    description: Created

So that you then have:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test
paths:
  /object:
    post:
      summary: Create an object
      operationId: createObject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Object"
      responses:
        '201':
          description: Created
components:
  schemas:
    Object:
      required:
        - name
        - description
      properties:
        name:
          type: string
        description:
          type: string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...