openapi-backend icon indicating copy to clipboard operation
openapi-backend copied to clipboard

Array path parameters are not deserialized correctly

Open fardjad opened this issue 3 years ago • 0 comments

Given the following OpenAPI Spec document:

openapi: "3.0.0"
info:
  title: Test API
  version: 1.0.0
servers:
  - url: http://localhost:5000
paths:
  '/items/{ids}':
    get:
      parameters:
        - schema:
            type: array
            items:
              type: string
          name: ids
          in: path
          required: true
          description: 'List of IDs'    
      summary: Get Items
      operationId: getItems
      responses:
        '200':
          description: OK
      description: Return the requested items

The following line throws a validation error as it expects the ids parameter to be an array (but it gets deserialized to a string).

oasBackend.handleRequest({
  method: 'GET',
  path: '/items/1,2,3',
  body: undefined,
  query: {},
  headers: {},
}, req, res);

Additional Details:

openapi-backend version: 4.1.0

Not sure if it should be handled in bath or openapi-backend itself, but seems like the following line needs to be replaced with some deserialization logic:

https://github.com/anttiviljami/openapi-backend/blob/4.1.0/src/router.ts#L284

fardjad avatar Jun 27 '21 18:06 fardjad