Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions libV2/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,23 +1258,45 @@ let QUERYPARAM = 'query',
case 'form':
if (explode && _.isObject(paramValue)) {
const isArrayValue = _.isArray(paramValue);
// Arrays
if (isArrayValue) {
_.forEach(paramValue, (value) => {
pmParams.push({
key: paramName,
value: (value === undefined ? '' : _.toString(value)),
description,
disabled
});
});
return pmParams;
}

// Objects: emit all keys except those that are schema definition keys
const schemaKeys = Object.keys(_.get(param, 'schema', {}));
_.forEach(paramValue, (value, key) => {
if (schemaKeys.includes(key)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case there are properties in the query param that matches the schema, with this current change those properties will not show up in the collection.

Check out the screenshot

The schema contains type and minimum but since the schema also has type defined. The generated request only contains minimum and type was omitted from the request query param.

Image Image

return;
}
pmParams.push({
key: isArrayValue ? paramName : key,
key,
value: (value === undefined ? '' : _.toString(value)),
description,
disabled
});
});

return pmParams;
if (pmParams.length) {
return pmParams;
}
}

break;
case 'deepObject':
if (_.isObject(paramValue) && !_.isArray(paramValue)) {
let extractedParams = extractDeepObjectParams(paramValue, paramName);
// Remove schema keys from the value before extraction
const schemaKeys = Object.keys(_.get(param, 'schema', {})),
filteredValue = _.omit(paramValue, schemaKeys);

let extractedParams = extractDeepObjectParams(filteredValue, paramName);

_.forEach(extractedParams, (extractedParam) => {
pmParams.push({
Expand All @@ -1284,8 +1306,9 @@ let QUERYPARAM = 'query',
disabled
});
});

return pmParams;
if (pmParams.length) {
return pmParams;
}
}
else if (_.isArray(paramValue)) {
isNotSerializable = true;
Expand Down
72 changes: 72 additions & 0 deletions test/unit/convertV2WithTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,78 @@ describe('convertV2WithTypes', function() {
});
});

it('should not emit schema.deprecated as query param key for form+explode and keep original param', function(done) {
const oas = {
openapi: '3.0.0',
info: { title: 'Form Explode Deprecated Test', version: '1.0.0' },
paths: {
'/pets': {
get: {
parameters: [
{
name: 'qp',
in: 'query',
schema: { type: 'object', deprecated: true },
example: { deprecated: true }
}
],
responses: { '200': { description: 'ok' } }
}
}
}
};

Converter.convertV2WithTypes({ type: 'json', data: oas }, {}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);

const items = conversionResult.output[0].data.item;
const request = items[0].item ? items[0].item[0].request : items[0].request;
const query = request.url.query || [];

expect(query.some((p) => { return p.key === 'deprecated'; })).to.equal(false);
expect(query.some((p) => { return p.key === 'qp'; })).to.equal(true);
done();
});
});

it('should not emit qp[deprecated] for deepObject and keep original param', function(done) {
const oas = {
openapi: '3.0.0',
info: { title: 'DeepObject Deprecated Test', version: '1.0.0' },
paths: {
'/pets': {
get: {
parameters: [
{
name: 'qp',
in: 'query',
style: 'deepObject',
explode: true,
schema: { type: 'object', deprecated: true },
example: { deprecated: true }
}
],
responses: { '200': { description: 'ok' } }
}
}
}
};

Converter.convertV2WithTypes({ type: 'json', data: oas }, {}, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);

const items = conversionResult.output[0].data.item;
const request = items[0].item ? items[0].item[0].request : items[0].request;
const query = request.url.query || [];

expect(query.some((p) => { return (/^qp\[deprecated\]/).test(p.key); })).to.equal(false);
expect(query.some((p) => { return p.key === 'qp'; })).to.equal(true);
done();
});
});

it('should resolve nested array and object schema types correctly in extractedTypes', function(done) {
const example = {
name: 'Buddy',
Expand Down
Loading