Skip to content

Commit 834528a

Browse files
author
Vishal Shingala
committed
Merge branch 'develop' of github.com:postmanlabs/openapi-to-postman into release/v4.0.0
2 parents cc02438 + 2f2de44 commit 834528a

File tree

8 files changed

+448
-118
lines changed

8 files changed

+448
-118
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# OpenAPI-Postman Changelog
22

3+
#### v3.2.0 (May 02, 2022)
4+
* Fixed some of critical and high level severity vulnerabilities.
5+
* Fixed issue [#10752](https://github.com/postmanlabs/postman-app-support/issues/10752) where deepObject style parameters were not generated correctly.
6+
* Fixed issue [#485](https://github.com/postmanlabs/openapi-to-postman/issues/485) where validateTransaction() returns result where mismatch path for transaction are incorrect.
7+
* Fixed issue [#485](https://github.com/postmanlabs/openapi-to-postman/issues/485) where validateTransaction() returns result where mismatch path for transaction are incorrect.
8+
39
#### v3.1.0 (March 04, 2022)
410
* Removed usage of schema resolution cache to avoid incorrect resolution.
511
* Fixed issue where newly converted collection had mismatches from validateTransaction() API.

lib/schemaUtils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,6 @@ module.exports = {
14161416
}
14171417
}
14181418
bodyData = bodyObj.example;
1419-
// return example value if present else example is returned
1420-
if (bodyData.hasOwnProperty('value')) {
1421-
bodyData = bodyData.value;
1422-
}
14231419
}
14241420
else if (!_.isEmpty(bodyObj.examples) && (resolveTo === 'example' || !bodyObj.schema)) {
14251421
// take one of the examples as the body and not all

package-lock.json

Lines changed: 190 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118
"dependencies": {
119119
"ajv": "8.1.0",
120120
"ajv-formats": "2.1.1",
121-
"async": "3.2.1",
121+
"async": "3.2.3",
122122
"commander": "2.20.3",
123123
"js-yaml": "3.14.1",
124124
"json-schema-merge-allof": "0.8.1",
125125
"lodash": "4.17.21",
126-
"oas-resolver-browser": "2.5.2",
126+
"oas-resolver-browser": "2.5.6",
127127
"path-browserify": "1.0.1",
128128
"postman-collection": "4.0.0",
129129
"swagger2openapi": "7.0.8",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets/{petId}:
11+
get:
12+
summary: Info for a specific pet
13+
operationId: showPetById
14+
tags:
15+
- pets
16+
parameters:
17+
- name: petId
18+
in: path
19+
required: true
20+
description: The id of the pet to retrieve
21+
schema:
22+
type: object
23+
properties:
24+
value:
25+
type:
26+
- integer
27+
example:
28+
value: 1
29+
- name: user
30+
in: query
31+
required: true
32+
style: deepObject
33+
schema:
34+
type:
35+
- object
36+
properties:
37+
id:
38+
type:
39+
- integer
40+
value:
41+
type:
42+
- string
43+
example:
44+
id: 1
45+
value: Vani
46+
responses:
47+
'200':
48+
description: Expected response to a valid request
49+
content:
50+
application/json:
51+
schema:
52+
$ref: "#/components/schemas/Pets"
53+
components:
54+
schemas:
55+
Pet:
56+
required:
57+
- id
58+
- name
59+
properties:
60+
id:
61+
type: integer
62+
format: int64
63+
name:
64+
type: string
65+
tag:
66+
type: string
67+
Pets:
68+
type: array
69+
items:
70+
$ref: "#/components/schemas/Pet"
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
openapi: 3.0.0
2+
info:
3+
version: '1.1.1'
4+
title: 'ExampleYaml'
5+
license:
6+
name: MIT
7+
servers:
8+
- url: 'localhost:3000'
9+
paths:
10+
/user:
11+
get:
12+
summary: 'Sample endpoint: Returns details about a particular user'
13+
operationId: listUser
14+
tags:
15+
- user
16+
parameters:
17+
- name: id
18+
in: query
19+
description: ID of the user
20+
required: true
21+
schema:
22+
type: integer
23+
format: int32
24+
responses:
25+
'200':
26+
description: 'Sample response: Details about a user by ID'
27+
headers:
28+
x-next:
29+
description: A link to the next page of responses
30+
schema:
31+
type: string
32+
content:
33+
application/json:
34+
schema:
35+
$ref: '#/components/schemas/User'
36+
example:
37+
id: "5789-6378-6372-6372"
38+
name: Vani
39+
tag: true
40+
value: QA
41+
lastmodifieddate: "2022-03-30T07:01:46"
42+
lastmodifiedBy: VM
43+
default:
44+
description: Unexpected error
45+
content:
46+
application/json:
47+
schema:
48+
$ref: '#/components/schemas/Error'
49+
/pet:
50+
get:
51+
summary: 'Sample endpoint: Returns details about a particular pet'
52+
operationId: listPet
53+
tags:
54+
- pet
55+
parameters:
56+
- name: id
57+
in: query
58+
description: ID of the pet
59+
required: true
60+
schema:
61+
type: integer
62+
format: int32
63+
responses:
64+
'200':
65+
description: 'Sample response: Details about a pet by ID'
66+
headers:
67+
x-next:
68+
description: A link to the next page of responses
69+
schema:
70+
type: string
71+
content:
72+
application/json:
73+
schema:
74+
type: object
75+
properties:
76+
id:
77+
type: integer
78+
format: int64
79+
value:
80+
type: string
81+
example:
82+
id: "5789-6378-6372-6372"
83+
value: QA
84+
default:
85+
description: Unexpected error
86+
content:
87+
application/json:
88+
schema:
89+
$ref: '#/components/schemas/Error'
90+
components:
91+
schemas:
92+
User:
93+
type: object
94+
required:
95+
- id
96+
- name
97+
- tag
98+
- value
99+
- lastmodifieddate
100+
- lastmodifiedBy
101+
properties:
102+
id:
103+
type: integer
104+
format: int64
105+
name:
106+
type: string
107+
tag:
108+
type: string
109+
value:
110+
type: string
111+
lastmodifieddate:
112+
type: integer
113+
format: int64
114+
lastmodifiedBy:
115+
type: string
116+
Error:
117+
type: object
118+
required:
119+
- code
120+
- message
121+
properties:
122+
code:
123+
type: integer
124+
format: int32
125+
message:
126+
type: string
127+
securitySchemes:
128+
BasicAuth:
129+
type: http
130+
scheme: basic
131+
security:
132+
- BasicAuth: []

test/unit/base.test.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
4848
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json'),
4949
parameterExamples = path.join(__dirname, VALID_OPENAPI_PATH + '/parameteres_with_examples.yaml'),
5050
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
51-
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml');
51+
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
52+
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
53+
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml');
5254

5355

5456
it('Should add collection level auth with type as `bearer`' +
@@ -469,7 +471,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
469471
expect(rootRequest.body.raw).to
470472
.equal('{\n "a": "<string>",\n "b": "<string>"\n}');
471473
expect(exampleRequest.body.raw).to
472-
.equal('{\n "a": "example-b",\n "b": "example-c"\n}');
474+
.equal('{\n "value": {\n "a": "example-b",\n "b": "example-c"\n }\n}');
473475
done();
474476
});
475477
});
@@ -1111,6 +1113,34 @@ describe('CONVERT FUNCTION TESTS ', function() {
11111113
done();
11121114
});
11131115
});
1116+
1117+
it('Should convert value property in example' +
1118+
valuePropInExample, function(done) {
1119+
var openapi = fs.readFileSync(valuePropInExample, 'utf8');
1120+
Converter.convert({ type: 'string', data: openapi },
1121+
{ schemaFaker: true, requestParametersResolution: 'Example' }, (err, conversionResult) => {
1122+
expect(err).to.be.null;
1123+
expect(conversionResult.result).to.equal(true);
1124+
expect(conversionResult.output[0].data.item[0].response[0]
1125+
.body).to.include('"value": "QA"');
1126+
expect(conversionResult.output[0].data.item[1].response[0]
1127+
.body).to.include('"value": "QA"');
1128+
done();
1129+
});
1130+
});
1131+
1132+
it('Should convert example in parameters' +
1133+
petstoreParamExample, function(done) {
1134+
var openapi = fs.readFileSync(petstoreParamExample, 'utf8');
1135+
Converter.convert({ type: 'string', data: openapi },
1136+
{ schemaFaker: true, requestParametersResolution: 'Example' }, (err, conversionResult) => {
1137+
expect(err).to.be.null;
1138+
expect(conversionResult.result).to.equal(true);
1139+
expect(conversionResult.output[0].data.item[0].request.url.variable[0].value).to.equal('value,1');
1140+
expect(conversionResult.output[0].data.item[0].request.url.query[1].key).to.equal('user[value]');
1141+
done();
1142+
});
1143+
});
11141144
});
11151145
describe('Converting swagger 2.0 files', function() {
11161146
it('should convert path paramters to postman-compatible paramters', function (done) {

test/unit/util.test.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,23 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
690690
});
691691

692692
it('should work for example', function() {
693+
var bodyWithExample = {
694+
example: 'This is a sample value'
695+
},
696+
retValExample = SchemaUtils.convertToPmBodyData(bodyWithExample, 'application/json');
697+
698+
expect(retValExample).to.equal('This is a sample value');
699+
});
700+
701+
it('should work for example with value property', function() {
693702
var bodyWithExample = {
694703
example: {
695704
value: 'This is a sample value'
696705
}
697706
},
698707
retValExample = SchemaUtils.convertToPmBodyData(bodyWithExample, 'application/json');
699708

700-
expect(retValExample).to.equal('This is a sample value');
709+
expect(retValExample.value).to.equal('This is a sample value');
701710
});
702711

703712
it('should work for examples', function() {
@@ -1678,10 +1687,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
16781687
description: 'body description',
16791688
content: {
16801689
'text/plain': {
1681-
example: {
1682-
summary: 'A list containing two items',
1683-
value: 'text/plain description'
1684-
}
1690+
example: 'text/plain description'
16851691
}
16861692
}
16871693
},
@@ -1690,7 +1696,8 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
16901696
exampleParametersResolution: 'example'
16911697
});
16921698
resultBody = result.body.raw;
1693-
expect(resultBody).to.equal('"text/plain description"');
1699+
expect(resultBody)
1700+
.to.equal('"text/plain description"');
16941701
expect(result.contentHeader).to.deep.include(
16951702
{ key: 'Content-Type', value: 'text/plain' });
16961703
done();
@@ -1701,10 +1708,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
17011708
description: 'body description',
17021709
content: {
17031710
'text/html': {
1704-
example: {
1705-
summary: 'A list containing two items',
1706-
value: '<html><body><ul><li>item 1</li><li>item 2</li></ul></body></html>'
1707-
}
1711+
example: '<html><body><ul><li>item 1</li><li>item 2</li></ul></body></html>'
17081712
}
17091713
}
17101714
},
@@ -1857,10 +1861,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
18571861
description: 'body description',
18581862
content: {
18591863
'text/plain': {
1860-
example: {
1861-
summary: 'A list containing two items',
1862-
value: 'text/plain description'
1863-
}
1864+
example: 'text/plain description'
18641865
}
18651866
}
18661867
},
@@ -1877,10 +1878,7 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
18771878
description: 'body description',
18781879
content: {
18791880
'text/html': {
1880-
example: {
1881-
summary: 'A list containing two items',
1882-
value: '<html><body><ul><li>item 1</li><li>item 2</li></ul></body></html>'
1883-
}
1881+
example: '<html><body><ul><li>item 1</li><li>item 2</li></ul></body></html>'
18841882
}
18851883
}
18861884
},

0 commit comments

Comments
 (0)