Skip to content

Commit

Permalink
Merge pull request #788 from postmanlabs/release/v4.20.1
Browse files Browse the repository at this point in the history
Release version v4.20.1
  • Loading branch information
VShingala committed Mar 27, 2024
2 parents 4f1c537 + 0128b3d commit d366111
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [v4.20.1] - 2024-03-27

### Fixed

- Fixed an issue where schemas under allOf keyword having additionalProperties set to false were not generating bodies correctly.

## [v4.20.0] - 2024-02-15

### Added
Expand Down Expand Up @@ -608,7 +614,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0

- Base release

[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.20.0...HEAD
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.20.1...HEAD

[v4.20.1]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.20.0...v4.20.1

[v4.20.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.19.0...v4.20.0

Expand Down
2 changes: 2 additions & 0 deletions lib/deref.js
Expand Up @@ -131,6 +131,8 @@ module.exports = {
{ stack, seenRef: _.cloneDeep(seenRef), resolveFor, resolveTo, stackLimit, isAllOf: true, analytics });
})
}), {
// below option is required to make sure schemas with additionalProperties set to false are resolved correctly
ignoreAdditionalProperties: true,
resolvers: {
// for keywords in OpenAPI schema that are not standard defined JSON schema keywords, use default resolver
defaultResolver: (compacted) => { return compacted[0]; },
Expand Down
2 changes: 2 additions & 0 deletions libV2/schemaUtils.js
Expand Up @@ -456,6 +456,8 @@ let QUERYPARAM = 'query',
return resolveSchema(context, schema, stack, resolveFor, _.cloneDeep(seenRef));
})
}), {
// below option is required to make sure schemas with additionalProperties set to false are resolved correctly
ignoreAdditionalProperties: true,
resolvers: {
// for keywords in OpenAPI schema that are not standard defined JSON schema keywords, use default resolver
defaultResolver: (compacted) => { return compacted[0]; },
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "openapi-to-postmanv2",
"version": "4.20.0",
"version": "4.20.1",
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",
"homepage": "https://github.com/postmanlabs/openapi-to-postman",
"bugs": "https://github.com/postmanlabs/openapi-to-postman/issues",
Expand Down
157 changes: 157 additions & 0 deletions test/data/valid_openapi/allOfAdditionalProperties.json
@@ -0,0 +1,157 @@
{
"x-generator": "NSwag v14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))",
"openapi": "3.0.0",
"info": {
"title": "Join API",
"version": "1.0.0"
},
"paths": {
"/api/Membership": {
"post": {
"tags": [
"Membership"
],
"operationId": "PostMember",
"requestBody": {
"x-name": "query",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StandardJoinCommand"
}
}
},
"required": true,
"x-position": 1
},
"responses": {
"201": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StandardJoinDto"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"GetMemberDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"memberId": {
"type": "integer",
"format": "int32"
},
"username": {
"type": "string",
"nullable": true
},
"comment": {
"type": "string",
"nullable": true
},
"email": {
"type": "string",
"nullable": true
}
}
},
"StandardJoinDto": {
"allOf": [
{
"$ref": "#/components/schemas/BaseJoinDto"
},
{
"type": "object",
"additionalProperties": false
}
]
},
"BaseJoinDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"memberId": {
"type": "integer",
"format": "int32"
},
"firstName": {
"type": "string",
"nullable": true
},
"lastName": {
"type": "string",
"nullable": true
}
}
},
"StandardJoinCommand": {
"allOf": [
{
"$ref": "#/components/schemas/BaseJoinCommandOfStandardJoinDto"
},
{
"type": "object",
"additionalProperties": false,
"properties": {
"email": {
"type": "string",
"nullable": true
},
"firstName": {
"type": "string",
"nullable": true
},
"lastName": {
"type": "string",
"nullable": true
},
"address1": {
"type": "string",
"nullable": true
},
"city": {
"type": "string",
"nullable": true
},
"state": {
"type": "string"
},
"countryCode": {
"type": "string",
"nullable": true
},
"zipCode": {
"type": "string",
"nullable": true
},
"phoneNumber": {
"type": "string",
"nullable": true
}
}
}
]
},
"BaseJoinCommandOfStandardJoinDto": {
"type": "object",
"x-abstract": true,
"additionalProperties": false,
"properties": {
"campaignId": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}

22 changes: 22 additions & 0 deletions test/unit/convertV2.test.js
Expand Up @@ -2091,6 +2091,28 @@ describe('The convert v2 Function', function() {
});
});

it('[GITHUB #417] - should convert file with allOf schemas containing additionalProperties as false ', function() {
const fileSource = path.join(__dirname, VALID_OPENAPI_PATH, 'allOfAdditionalProperties.json'),
fileData = fs.readFileSync(fileSource, 'utf8'),
input = {
type: 'string',
data: fileData
};

Converter.convertV2(input, {
optimizeConversion: false
}, (err, result) => {
const expectedRequestBody = JSON.parse(result.output[0].data.item[0].item[0].item[0].request.body.raw);

expect(err).to.be.null;
expect(result.result).to.be.true;

expect(expectedRequestBody).to.be.an('object');
expect(expectedRequestBody).to.have.keys(['phoneNumber', 'zipCode', 'countryCode', 'state', 'city',
'address1', 'lastName', 'firstName', 'email', 'campaignId']);
});
});

it('Should convert a swagger document with XML example correctly', function(done) {
const fileData = fs.readFileSync(path.join(__dirname, SWAGGER_20_FOLDER_YAML, 'xml_example.yaml'), 'utf8'),
input = {
Expand Down
70 changes: 70 additions & 0 deletions test/unit/deref.test.js
Expand Up @@ -516,6 +516,76 @@ describe('DEREF FUNCTION TESTS ', function() {
});
done();
});

it('should resolve schemas under allOf keyword with additionalProperties set to false correctly', function (done) {
var schema = {
'allOf': [
{
'type': 'object',
'additionalProperties': false,
'properties': {
'source': {
'type': 'string',
'format': 'uuid'
},
'status': {
'type': 'string',
'enum': ['incomplete', 'completed', 'refunded']
},
'actionId': { 'type': 'integer', 'minimum': 5 },
'result': { 'type': 'object' }
},
'required': ['source', 'actionId', 'result']
},
{
'additionalProperties': false,
'properties': {
'result': {
'type': 'object',
'properties': {
'err': { 'type': 'string' },
'data': { 'type': 'object' }
}
},
'status': {
'type': 'string',
'enum': ['no_market', 'too_small', 'too_large']
}
}
}
]
};

expect(deref.resolveAllOf(
schema,
'REQUEST',
{ concreteUtils: schemaUtils30X },
{ resolveTo: 'example' }
)).to.deep.equal({
type: 'object',
additionalProperties: false,
required: ['source', 'actionId', 'result'],
properties: {
source: {
type: 'string',
format: 'uuid'
},
status: {
type: 'string',
enum: ['incomplete', 'completed', 'refunded', 'no_market', 'too_small', 'too_large']
},
actionId: { 'type': 'integer', 'minimum': 5 },
result: {
type: 'object',
properties: {
err: { 'type': 'string' },
data: { 'type': 'object' }
}
}
}
});
done();
});
});

describe('_getEscaped should', function() {
Expand Down

0 comments on commit d366111

Please sign in to comment.