Closed glowcloud closed 4 months ago
Swagger/OpenAPI definition:
{ host: 'swagger.io', basePath: '/v1', paths: { '/pets/findByStatus': { get: { operationId: 'getMe', parameters: [ { in: 'formData', name: 'status', type: 'boolean', required: false, }, ], responses: { 200: { description: 'ok', }, }, }, }, }, }
Swagger-Client usage:
SwaggerClient.buildRequest({ spec, operationId: 'getMe', parameters: { status: false }, });
Swagger Client does not add the status parameter with false value to the request.
status
false
{ url: 'http://swagger.io/v1/pets/findByStatus', credentials: 'same-origin', headers: {}, method: 'GET' }
Swagger Client should add status=false to the request body
status=false
{ url: 'http://swagger.io/v1/pets/findByStatus', credentials: 'same-origin', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, method: 'GET', body: 'status=false' }
This behaviour is correct for query parameters as we convert falsy values to string there https://github.com/swagger-api/swagger-js/blob/0883d2ddeb1feaf60f8e9480c6a801db0c72a8d9/src/execute/swagger2/parameter-builders.js#L46-L52 The same logic should be applied to form data.
string
Addressed in https://github.com/swagger-api/swagger-js/commit/7e1cf7b4af0545eb296f4bde3bddabfd6280352e
Content & configuration
Swagger/OpenAPI definition:
Swagger-Client usage:
Describe the bug you're encountering
Swagger Client does not add the
status
parameter withfalse
value to the request.Expected behavior
Swagger Client should add
status=false
to the request bodyAdditional context or thoughts
This behaviour is correct for query parameters as we convert falsy values to
string
there https://github.com/swagger-api/swagger-js/blob/0883d2ddeb1feaf60f8e9480c6a801db0c72a8d9/src/execute/swagger2/parameter-builders.js#L46-L52 The same logic should be applied to form data.