Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Editor shows the "Schema error: should NOT have additional properties" error for a path parameter

I'm using http://editor.swagger.io to design an API and I get an error which I don't know how to address:

Schema error at paths['/employees/{employeeId}/roles'].get.parameters[0] should NOT have additional properties additionalProperty: type, format, name, in, description Jump to line 24 

I have other endpoints defined in a similar way, and don't get this error. I wondered if I had some issue with indentation or unclosed quotes, but that doesn't seem to be the case. Google also did not seem to provide any useful results.

swagger: "2.0" info:   description: Initial draft of the API specification   version: '1.0'   title: App 4.0 API host: api.com basePath: /v1 tags:   - name: employees     description: Employee management schemes:   - https paths:   /employees/{employeeId}/roles:     get:       tags:         - employees       summary: "Get a specific employee's roles"       description: ''       operationId: findEmployeeRoles       produces:         - application/json       parameters:         - name: employeeId   <====== Line 24           in: path           description: Id of employee whose roles we are fetching           type: integer           format: int64       responses:         '200':           description: successful operation           schema:             type: array             items:               $ref: '#/definitions/Role'         '403':           description: No permission to see employee roles         '404':           description: EmployeeId not found 

Any Hints?

like image 274
Emanuel Ey Avatar asked Aug 07 '17 14:08

Emanuel Ey


People also ask

What is a schema object in Swagger?

Schema Objects in particular provide the models for request and response message payloads: They can be defined in-context, as the schema value of a body parameter or response; or They can appear in the definitions section and included by reference . Swagger's Schema Object provides limited support for JSON Schema's...

Are path parameters always required in Swagger?

Path parameters are always required, so remember to add required: true to them. I have required: true in my definition and I'm still getting that error. Had the same problem. I accidentally mixed up the syntax from Swagger 2.0 with Openapi 3.0.x.

What is additionalproperties in Swagger?

Used within an object schema, additionalProperties allows objects conforming to the schema to include properties that are not explicitly named in the properties section of the schema. However, Swagger's core libraries deviate from the specification in subtle ways that can cause unexpected behavior.

Should Swagger allow additional properties in JSON Schema?

Some comments suggest that the default behavior in Swagger should be to disallow additional properties, but this is not in the Swagger 2.0 spec. Aside from boolean true and false values, JSON Schema also allows additionalProperties to specify a schema as its value.


1 Answers

The error message is misleading. The actual error is that your path parameter is missing required: true. Path parameters are always required, so remember to add required: true to them.

like image 183
Helen Avatar answered Sep 21 '22 14:09

Helen