swagger-api/swagger-js

OpenAPI 2.x: undefined body and path parameters are included in requests

glowcloud opened this issue · 1 comments

Content & configuration

Swagger/OpenAPI definition:

{
  host: 'swagger.io',
  basePath: '/v1',
  paths: {
    '/pets/find/{pathParam}': {
      get: {
        operationId: 'getMe',
        parameters: [
          {
            in: 'path',
            name: 'pathParam',
            type: 'string',
            required: false,
          },
          {
            in: 'body',
            name: 'bodyParam',
            type: 'string',
            required: false,
          },
        ],
        responses: {
          200: {
            description: 'ok',
          },
        },
      },
    },
  },
}

Swagger-Client usage:

SwaggerClient.buildRequest({
  spec,
  operationId: 'getMe',
  parameters: { bodyParam: undefined, pathParam: undefined },
})

Describe the bug you're encountering

Swagger Client adds undefined values to path and body parameters.

{
  url: 'http://swagger.io/v1/pets/find/undefined',
  credentials: 'same-origin',
  headers: {},
  method: 'GET',
  body: undefined
}

Expected behavior

Swagger Client should not add anything to the body when provided with undefined values and should not replace the parameter with undefined string in the path.

{
  url: 'http://swagger.io/v1/pets/find/{pathParam}',
  credentials: 'same-origin',
  headers: {},
  method: 'GET'
}

Addressed in #3439