Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI 2.x: make execute parameter builders for query and formData consistent with each other #3436

Closed
glowcloud opened this issue Mar 25, 2024 · 1 comment

Comments

@glowcloud
Copy link
Contributor

The logic for query and formData parameter builders should be the same.

The current form data builder processes truthy values differently than query, adding allowEmptyValue to it. It also adds an empty string as parameter value if the value is undefined and allowEmptyValue is true.

Form data builder:

function formDataBuilder({ req, value, parameter }) {
if (value === false && parameter.type === 'boolean') {
value = 'false';
}
if (value === 0 && ['number', 'integer'].indexOf(parameter.type) > -1) {
value = '0';
}
if (value || parameter.allowEmptyValue) {
req.form = req.form || {};
req.form[parameter.name] = {
value,
allowEmptyValue: parameter.allowEmptyValue,
collectionFormat: parameter.collectionFormat,
};
}
}

Query builder:

function queryBuilder({ req, value, parameter }) {
req.query = req.query || {};
if (value === false && parameter.type === 'boolean') {
value = 'false';
}
if (value === 0 && ['number', 'integer'].indexOf(parameter.type) > -1) {
value = '0';
}
if (value) {
req.query[parameter.name] = {
collectionFormat: parameter.collectionFormat,
value,
};
} else if (parameter.allowEmptyValue && value !== undefined) {
const paramName = parameter.name;
req.query[paramName] = req.query[paramName] || {};
req.query[paramName].allowEmptyValue = true;
}
}

@char0n
Copy link
Member

char0n commented Mar 25, 2024

Addressed in #3437

@char0n char0n closed this as completed Mar 25, 2024
swagger-bot pushed a commit that referenced this issue Mar 25, 2024
## [3.26.3](v3.26.2...v3.26.3) (2024-03-25)

### Bug Fixes

* **execute:** align form data builder with query builder behavior for OpenAPI 2.0  ([#3437](#3437)) ([1f39b90](1f39b90)), closes [#3436](#3436)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants