Designing an API using editor.swagger.io I find myself unable to add a requestBody attribute, getting an error I cannot address:
Schema error at paths['/projects/{projectId}/user'].post
should NOT have additional properties
additionalProperty: requestBody
Jump to line 91
I don't understand what I'm doing wrong, especially after looking at the requestBody documentation. Research has brought me nothing other than the tendency for errors to be misleading.
EDIT: From what the answers here have shown, it looks like the editor is supposed to use OpenAPI 2.0, but actually expects 3.0 while returning errors for both. I'd use some help on what to use, given that I've included a
swagger: "2.0"
line at the beginning of the document.
While testing with openapi: 3.0.0
as shown by @Mike in his answer, I just get more errors about allowed additional properties.
Here's what's generating the error, line 91 being post:
.
/projects/{projectId}/user:
post:
tags:
- projects
summary: Modify project user.
operationId: modifyProjectUser
parameters:
- name: projectId
in: path
description: ID of the project
required: true
type: integer
format: int32
requestBody:
content:
application/json:
schema:
$ref: '#/definitions/User'
responses:
"200":
description: Successful operation
schema:
type: array
items:
$ref: "#/definitions/User"
security:
- api_key: []
I got clarifications from an external source, so here's what I've learned:
Specifying swagger: 2.0
also means that the OpenAPI Specification 2.0.0 is expected by the editor, whereas I thought it used OAS 3.
I'm still unsure about why in: body
did not work in the first place but I've added quotes around "body"
, which made the error disappear. Then I tried removing the quotes and it worked fine.
The editor doesn't seem very reliable when it comes to error reporting.
This error message looked familiar. Try inserting a schema: underneath your parameter's required: line, then indent the type: and format: lines.
Since I have not yet set up my own SwaggerUI server. I took your code snippet and pasted it into SwaggerHub. Then I removed the $ref: lines just to further simplify the codebase. Here's a screenshot of the error-free result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With