Change deepObject generation

Change deepObject generation
This commit is contained in:
Luis Tejeda
2022-04-12 11:31:34 -05:00
parent df174ebe5f
commit a34abfd649
3 changed files with 52 additions and 3 deletions

View File

@@ -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 + ']'));
}

View File

@@ -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

View File

@@ -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`' +
@@ -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() {