Skip to content

Commit

Permalink
fix(execute): align form data builder with query builder behavior for…
Browse files Browse the repository at this point in the history
… OpenAPI 2.0 (#3437)

Refs #3436
  • Loading branch information
glowcloud committed Mar 25, 2024
1 parent 0fb65af commit 1f39b90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/execute/swagger2/parameter-builders.js
Expand Up @@ -24,13 +24,17 @@ function formDataBuilder({ req, value, parameter }) {
value = '0';
}

if (value || parameter.allowEmptyValue) {
if (value) {
req.form = req.form || {};
req.form[parameter.name] = {
value,
allowEmptyValue: parameter.allowEmptyValue,
collectionFormat: parameter.collectionFormat,
value,
};
} else if (parameter.allowEmptyValue && value !== undefined) {
req.form = req.form || {};
const paramName = parameter.name;
req.form[paramName] = req.form[paramName] || {};
req.form[paramName].allowEmptyValue = true;
}
}

Expand Down
9 changes: 7 additions & 2 deletions test/execute/main.js
Expand Up @@ -424,7 +424,7 @@ describe('execute', () => {
});

describe('formData', () => {
test('should add an empty query param if the value is empty and allowEmptyValue: true', () => {
test('should not add an empty query param if the value is empty and allowEmptyValue: true', () => {
// Given
const spec = {
host: 'swagger.io',
Expand All @@ -449,7 +449,12 @@ describe('execute', () => {
const req = buildRequest({ spec, operationId: 'deleteMe', parameters: {} });

// Then
expect(req.body).toEqual('petId=');
expect(req).toEqual({
url: 'http://swagger.io/v1/one',
method: 'DELETE',
credentials: 'same-origin',
headers: {},
});
});

test('should support collectionFormat', () => {
Expand Down

0 comments on commit 1f39b90

Please sign in to comment.