Skip to content

Commit 8d4d79d

Browse files
authored
Merge branch 'postmanlabs:develop' into Cannot_read_properties_of_undefined_(reading_'type')
2 parents 5cd19e9 + 3c97280 commit 8d4d79d

File tree

8 files changed

+127
-8
lines changed

8 files changed

+127
-8
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
## [Unreleased]
44

5+
## [v4.15.0] - 2023-06-27
6+
7+
### Added
8+
9+
- Added support for usage of XML examples of type string.
10+
11+
### Fixed
12+
13+
- Fixed issue where generated collection contained request and folder in incorrect order for v2 interface.
14+
- Fixed issue where collection generation took very large time.
15+
16+
### Changed
17+
18+
- Reduced collection size by keeping maximum generated elements for array as 1 for definitions with larger schemas.
19+
520
## [v4.14.0] - 2023-06-07
621

722
### Added
@@ -573,7 +588,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0
573588

574589
- Base release
575590

576-
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.14.0...HEAD
591+
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.15.0...HEAD
592+
593+
[v4.15.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.14.0...v4.15.0
577594

578595
[v4.14.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.13.0...v4.14.0
579596

lib/xmlSchemaFaker.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent, resolve
5454
}
5555
}
5656
else if (schema.type === 'object') {
57-
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
57+
// Use mentioned example in string directly as example
58+
if (resolveTo === 'example' && typeof schemaExample === 'string') {
59+
return '\n' + schemaExample;
60+
}
61+
else if (resolveTo === 'example' && typeof schemaExample === 'object') {
5862
const elementName = _.get(schema, 'items.xml.name', name || 'element'),
5963
fakedContent = js2xml({ [elementName]: schemaExample }, indentChar);
6064

@@ -99,7 +103,11 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent, resolve
99103

100104
schemaItemsWithXmlProps.xml = schema.xml;
101105

102-
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
106+
// Use mentioned example in string directly as example
107+
if (resolveTo === 'example' && typeof schemaExample === 'string') {
108+
return '\n' + schemaExample;
109+
}
110+
else if (resolveTo === 'example' && typeof schemaExample === 'object') {
103111
const fakedContent = js2xml({ [arrayElemName]: schemaExample }, indentChar);
104112

105113
contents = '\n' + indentContent(fakedContent, cIndent);

libV2/xmlSchemaFaker.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent, resolve
5454
}
5555
}
5656
else if (schema.type === 'object') {
57-
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
57+
// Use mentioned example in string directly as example
58+
if (resolveTo === 'example' && typeof schemaExample === 'string') {
59+
return '\n' + schemaExample;
60+
}
61+
else if (resolveTo === 'example' && typeof schemaExample === 'object') {
5862
const elementName = _.get(schema, 'items.xml.name', name || 'element'),
5963
fakedContent = js2xml({ [elementName]: schemaExample }, indentChar);
6064

@@ -99,7 +103,11 @@ function convertSchemaToXML(name, schema, attribute, indentChar, indent, resolve
99103

100104
schemaItemsWithXmlProps.xml = schema.xml;
101105

102-
if (resolveTo === 'example' && typeof schemaExample !== 'undefined') {
106+
// Use mentioned example in string directly as example
107+
if (resolveTo === 'example' && typeof schemaExample === 'string') {
108+
return '\n' + schemaExample;
109+
}
110+
else if (resolveTo === 'example' && typeof schemaExample === 'object') {
103111
const fakedContent = js2xml({ [arrayElemName]: schemaExample }, indentChar);
104112

105113
contents = '\n' + indentContent(fakedContent, cIndent);

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-to-postmanv2",
3-
"version": "4.14.0",
3+
"version": "4.15.0",
44
"description": "Convert a given OpenAPI specification to Postman Collection v2.0",
55
"homepage": "https://github.com/postmanlabs/openapi-to-postman",
66
"bugs": "https://github.com/postmanlabs/openapi-to-postman/issues",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
openapi: 3.0.3
2+
info:
3+
title: My API
4+
version: 1.0.0
5+
contact: {}
6+
servers:
7+
- url: "https://api.server.test/v1"
8+
paths:
9+
/test:
10+
post:
11+
summary: /test
12+
description: /test
13+
operationId: test
14+
requestBody:
15+
content:
16+
text/xml:
17+
schema:
18+
type: array
19+
items:
20+
type: object
21+
properties:
22+
issue:
23+
type: string
24+
description: information about the issue
25+
maxLength: 150
26+
action:
27+
type: string
28+
description: what corrective action needs to be taken to resolve the issue.
29+
maxLength: 150
30+
example: |
31+
<Errors>
32+
<error>
33+
<issue>Mandatory field are missing.</issue>
34+
<action>Resend request with valid values, any one of Hello or World.</action>
35+
</error>
36+
</Errors>
37+
responses:
38+
"200":
39+
description: OK
40+
content:
41+
application/json:
42+
examples:
43+
OK:
44+
value:
45+
Data: Postman
46+
tags: []

test/unit/base.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
5555
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
5656
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
5757
xmlrequestBody = path.join(__dirname, VALID_OPENAPI_PATH, '/xmlExample.yaml'),
58+
xmlrequestExampleBody = path.join(__dirname, VALID_OPENAPI_PATH, '/xmlExampleWithString.yaml'),
5859
queryParamWithEnumResolveAsExample =
5960
path.join(__dirname, VALID_OPENAPI_PATH, '/query_param_with_enum_resolve_as_example.json'),
6061
formDataParamDescription = path.join(__dirname, VALID_OPENAPI_PATH, '/form_data_param_description.yaml'),
@@ -1255,6 +1256,25 @@ describe('CONVERT FUNCTION TESTS ', function() {
12551256
});
12561257
});
12571258

1259+
it('Should convert xml request body with complete string example correctly', function(done) {
1260+
const openapi = fs.readFileSync(xmlrequestExampleBody, 'utf8');
1261+
Converter.convert({ type: 'string', data: openapi },
1262+
{ schemaFaker: true, requestParametersResolution: 'Example' }, (err, conversionResult) => {
1263+
expect(err).to.be.null;
1264+
expect(conversionResult.result).to.equal(true);
1265+
expect(conversionResult.output[0].data.item[0].request.body.raw)
1266+
.to.equal(`<?xml version="1.0" encoding="UTF-8"?>
1267+
<Errors>
1268+
<error>
1269+
<issue>Mandatory field are missing.</issue>
1270+
<action>Resend request with valid values, any one of Hello or World.</action>
1271+
</error>
1272+
</Errors>
1273+
`);
1274+
done();
1275+
});
1276+
});
1277+
12581278
it('[Github #518]- integer query params with enum values get default value of NaN' +
12591279
descriptionInBodyParams, function(done) {
12601280
var openapi = fs.readFileSync(queryParamWithEnumResolveAsExample, 'utf8');

test/unit/convertV2.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const expect = require('chai').expect,
4848
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
4949
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
5050
xmlrequestBody = path.join(__dirname, VALID_OPENAPI_PATH, '/xmlExample.yaml'),
51+
xmlrequestExampleBody = path.join(__dirname, VALID_OPENAPI_PATH, '/xmlExampleWithString.yaml'),
5152
queryParamWithEnumResolveAsExample =
5253
path.join(__dirname, VALID_OPENAPI_PATH, '/query_param_with_enum_resolve_as_example.json'),
5354
formDataParamDescription = path.join(__dirname, VALID_OPENAPI_PATH, '/form_data_param_description.yaml'),
@@ -1107,6 +1108,25 @@ describe('The convert v2 Function', function() {
11071108
});
11081109
});
11091110

1111+
it('Should convert xml request body with complete string example correctly', function(done) {
1112+
const openapi = fs.readFileSync(xmlrequestExampleBody, 'utf8');
1113+
Converter.convertV2({ type: 'string', data: openapi },
1114+
{ schemaFaker: true, parametersResolution: 'Example' }, (err, conversionResult) => {
1115+
expect(err).to.be.null;
1116+
expect(conversionResult.result).to.equal(true);
1117+
expect(conversionResult.output[0].data.item[0].item[0].request.body.raw)
1118+
.to.equal(`<?xml version="1.0" encoding="UTF-8"?>
1119+
<Errors>
1120+
<error>
1121+
<issue>Mandatory field are missing.</issue>
1122+
<action>Resend request with valid values, any one of Hello or World.</action>
1123+
</error>
1124+
</Errors>
1125+
`);
1126+
done();
1127+
});
1128+
});
1129+
11101130
it('[Github #518]- integer query params with enum values get default value of NaN' +
11111131
descriptionInBodyParams, function(done) {
11121132
var openapi = fs.readFileSync(queryParamWithEnumResolveAsExample, 'utf8');

0 commit comments

Comments
 (0)