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

Change deepObject generation #502

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1550,9 +1550,9 @@ module.exports = {
*/
extractDeepObjectParams: function (deepObject, objectKey) {
let extractedParams = [];
// console.log(deepObject);

_.forEach(deepObject, (value, key) => {
Object.keys(deepObject).forEach((key) => {
let value = deepObject[key];
if (typeof value === 'object') {
extractedParams = _.concat(extractedParams, this.extractDeepObjectParams(value, objectKey + '[' + key + ']'));
}
Expand Down
34 changes: 34 additions & 0 deletions test/data/valid_openapi/deepObjectLengthProperty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.1
info:
title: Demo
version: "1.0"
paths:
/get:
get:
operationId: someRequest
parameters:
- $ref: '#/components/parameters/DeepObjectNestedList'
- $ref: '#/components/parameters/DeepObjectLengthParameter'
responses:
'200':
description: Response on success.
components:
parameters:
DeepObjectLengthParameter:
name: deepObjectLengthParameter
in: query
required: false
style: deepObject
schema:
$ref: '#/components/schemas/DeepObjectLengthParameter'
explode: true
schemas:
DeepObjectLengthParameter:
type: object
properties:
length:
nullable: true
type: integer
format: int32
minimum: 1
example: 20
17 changes: 16 additions & 1 deletion test/unit/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
emptySecurityTestCase = path.join(__dirname, VALID_OPENAPI_PATH + '/empty-security-test-case.yaml'),
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json'),
parameterExamples = path.join(__dirname, VALID_OPENAPI_PATH + '/parameteres_with_examples.yaml'),
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json');
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml');


it('Should add collection level auth with type as `bearer`' +
Expand Down Expand Up @@ -1094,6 +1095,20 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});

it('[Github #10752]: Should convert deepObject length property' +
deepObjectLengthProperty, function(done) {
var openapi = fs.readFileSync(deepObjectLengthProperty, 'utf8');
Converter.convert({ type: 'string', data: openapi },
{ schemaFaker: true, requestParametersResolution: 'Example' }, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.result).to.equal(true);
expect(conversionResult.output[0].data.item[0].request.url.query[0].key)
.to.equal('deepObjectLengthParameter[length]');
expect(conversionResult.output[0].data.item[0].request.url.query[0].value).to.equal('20');
done();
});
});
});

describe('requestNameSource option', function() {
Expand Down