Skip to content

Commit 7915060

Browse files
Merge pull request #635 from postmanlabs/release/4.3.0
Release/4.3.0
2 parents 707e42e + 0d8b8c4 commit 7915060

File tree

11 files changed

+950
-15
lines changed

11 files changed

+950
-15
lines changed

CHANGELOG.md

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

3+
#### v4.3.0 (October 17, 2022)
4+
* Fixed issue with nullable keywords getting validated incorrectly.
5+
36
#### v4.2.0 (August 10, 2022)
47
* Improved the way to detect a circular reference by adding a new condition
58
* A schema that comes from an allOf parent then we now return the same schema instead of defaulting to a schema with type as object, and no other properties

lib/deref.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const _ = require('lodash'),
2828
'double'
2929
],
3030
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
31-
traverseUtility = require('traverse');
31+
traverseUtility = require('traverse'),
32+
PROPERTIES_TO_ASSIGN_ON_CASCADE = ['type', 'nullable'];
3233

3334
/**
3435
* @param {*} currentNode - the object from which you're trying to find references
@@ -171,6 +172,11 @@ module.exports = {
171172
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
172173
}
173174
return { anyOf: _.map(schema.anyOf, (schemaElement) => {
175+
PROPERTIES_TO_ASSIGN_ON_CASCADE.forEach((prop) => {
176+
if (_.isNil(schemaElement[prop]) && !_.isNil(schema[prop])) {
177+
schemaElement[prop] = schema[prop];
178+
}
179+
});
174180
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache, resolveFor,
175181
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
176182
}) };
@@ -181,8 +187,14 @@ module.exports = {
181187
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
182188
}
183189
return { oneOf: _.map(schema.oneOf, (schemaElement) => {
184-
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache, resolveFor,
185-
resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
190+
PROPERTIES_TO_ASSIGN_ON_CASCADE.forEach((prop) => {
191+
if (_.isNil(schemaElement[prop]) && !_.isNil(schema[prop])) {
192+
schemaElement[prop] = schema[prop];
193+
}
194+
});
195+
196+
return this.resolveRefs(schemaElement, parameterSourceOption, components, schemaResolutionCache,
197+
resolveFor, resolveTo, stack, _.cloneDeep(seenRef), stackLimit);
186198
}) };
187199
}
188200
if (schema.allOf) {

lib/schemaUtils.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,26 +2015,28 @@ module.exports = {
20152015
}
20162016
else {
20172017
let getXmlVersionContent = (bodyContent) => {
2018-
const regExp = new RegExp('([<\\?xml]+[\\s{1,}]+[version="\\d.\\d"]+[\\sencoding="]+.{1,15}"\\?>)');
2019-
let xmlBody = bodyContent;
2018+
const regExp = new RegExp('([<\\?xml]+[\\s{1,}]+[version="\\d.\\d"]+[\\sencoding="]+.{1,15}"\\?>)');
2019+
let xmlBody = bodyContent;
20202020

2021-
if (!bodyContent.match(regExp)) {
2022-
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n';
2023-
xmlBody = versionContent + xmlBody;
2024-
}
2025-
return xmlBody;
2026-
};
2021+
if (!bodyContent.match(regExp)) {
2022+
const versionContent = '<?xml version="1.0" encoding="UTF-8"?>\n';
2023+
xmlBody = versionContent + xmlBody;
2024+
}
2025+
return xmlBody;
2026+
},
2027+
headerFamily;
20272028

20282029
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
20292030
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
20302031

2031-
bodyData = (bodyType === TEXT_XML || bodyType === APP_XML) ?
2032+
headerFamily = this.getHeaderFamily(bodyType);
2033+
bodyData = (bodyType === TEXT_XML || bodyType === APP_XML || headerFamily === HEADER_TYPE.XML) ?
20322034
getXmlVersionContent(bodyData) :
20332035
bodyData;
20342036

20352037
updateOptions = {
20362038
mode: rDataMode,
2037-
raw: bodyType !== APP_JSON ?
2039+
raw: !_.isObject(bodyData) && _.isFunction(_.get(bodyData, 'toString')) ?
20382040
bodyData.toString() :
20392041
JSON.stringify(bodyData, null, options.indentCharacter)
20402042
};

package-lock.json

Lines changed: 1 addition & 1 deletion
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.2.0",
3+
"version": "4.3.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: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://petstore.swagger.io/v1"
13+
}
14+
],
15+
"paths": {
16+
"/pets": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"tags": [
21+
"pets"
22+
],
23+
"parameters": [
24+
{
25+
"name": "limit",
26+
"in": "query",
27+
"description": "How many items to return at one time (max 100)",
28+
"required": false,
29+
"schema": {
30+
"type": "integer",
31+
"format": "int32"
32+
}
33+
}
34+
],
35+
"responses": {
36+
"200": {
37+
"description": "A paged array of pets",
38+
"headers": {
39+
"x-next": {
40+
"description": "A link to the next page of responses",
41+
"schema": {
42+
"type": "string"
43+
}
44+
}
45+
},
46+
"content": {
47+
"application/json": {
48+
"schema": {
49+
"$ref": "#/components/schemas/Pets"
50+
}
51+
}
52+
}
53+
},
54+
"default": {
55+
"description": "unexpected error",
56+
"content": {
57+
"application/json": {
58+
"schema": {
59+
"$ref": "#/components/schemas/Error"
60+
}
61+
}
62+
}
63+
}
64+
}
65+
},
66+
"post": {
67+
"summary": "Create a pet",
68+
"operationId": "createPets",
69+
"tags": [
70+
"pets"
71+
],
72+
"responses": {
73+
"201": {
74+
"description": "Null response"
75+
},
76+
"default": {
77+
"description": "unexpected error",
78+
"content": {
79+
"application/json": {
80+
"schema": {
81+
"$ref": "#/components/schemas/Error"
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
},
89+
"/pets/{petId}": {
90+
"get": {
91+
"summary": "Info for a specific pet",
92+
"operationId": "showPetById",
93+
"tags": [
94+
"pets"
95+
],
96+
"parameters": [
97+
{
98+
"name": "petId",
99+
"in": "path",
100+
"required": true,
101+
"description": "The id of the pet to retrieve",
102+
"schema": {
103+
"type": "string"
104+
}
105+
}
106+
],
107+
"responses": {
108+
"200": {
109+
"description": "Expected response to a valid request",
110+
"content": {
111+
"application/json": {
112+
"schema": {
113+
"$ref": "#/components/schemas/Pet"
114+
}
115+
}
116+
}
117+
},
118+
"default": {
119+
"description": "unexpected error",
120+
"content": {
121+
"application/json": {
122+
"schema": {
123+
"$ref": "#/components/schemas/Error"
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
},
132+
"components": {
133+
"schemas": {
134+
"Pet": {
135+
"type": "object",
136+
"required": [
137+
"id",
138+
"name"
139+
],
140+
"properties": {
141+
"id": {
142+
"type": "integer",
143+
"format": "int64"
144+
},
145+
"name": {
146+
"type": "string"
147+
},
148+
"actualDelivery": {
149+
"type": "string",
150+
"nullable": true,
151+
"oneOf": [
152+
{
153+
"enum": [
154+
""
155+
]
156+
},
157+
{
158+
"format": "date-time",
159+
"pattern": "^\\d{4}-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12]\\d)(T| )(2[0-3]|[01][0-9]):[0-5]\\d(|(:[0-5]\\dZ?)|(:[0-5]\\d\\.\\d{3})|(:[0-5]\\d\\.\\d{3}[+-]\\d{2}:\\d{2}))$"
160+
}
161+
]
162+
}
163+
}
164+
},
165+
"Pets": {
166+
"type": "array",
167+
"items": {
168+
"$ref": "#/components/schemas/Pet"
169+
}
170+
},
171+
"Error": {
172+
"type": "object",
173+
"required": [
174+
"code",
175+
"message"
176+
],
177+
"properties": {
178+
"code": {
179+
"type": "integer",
180+
"format": "int32"
181+
},
182+
"message": {
183+
"type": "string"
184+
}
185+
}
186+
}
187+
}
188+
}
189+
}

0 commit comments

Comments
 (0)