Skip to content

Commit 95dc680

Browse files
authored
Merge branch 'develop' into 817-enum
2 parents 1cfe4fc + f0a23b1 commit 95dc680

File tree

12 files changed

+799
-79
lines changed

12 files changed

+799
-79
lines changed

CHANGELOG.md

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

33
## [Unreleased]
44

5+
## [v4.24.0] - 2024-08-13
6+
7+
### Added
8+
9+
- [#98](https://github.com/postmanlabs/openapi-to-postman/issues/98) [12255](https://github.com/postmanlabs/postman-app-support/issues/12255) Added support for readOnly and writeOnly properties to be correctly present in generated collection.
10+
11+
### Chore
12+
13+
- Replaced traverse with neotraverse.
14+
515
## [v4.23.1] - 2024-07-22
616

717
### Added
@@ -637,7 +647,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com/en/1.0.0
637647

638648
- Base release
639649

640-
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.23.1...HEAD
650+
[Unreleased]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.24.0...HEAD
651+
652+
[v4.24.0]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.23.1...v4.24.0
641653

642654
[v4.23.1]: https://github.com/postmanlabs/openapi-to-postman/compare/v4.22.0...v4.23.1
643655

libV2/schemaUtils.js

Lines changed: 189 additions & 37 deletions
Large diffs are not rendered by default.

libV2/utils.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const _ = require('lodash'),
2+
jsonPointer = require('json-pointer'),
23
{ Item } = require('postman-collection/lib/collection/item'),
34
{ Response } = require('postman-collection/lib/collection/response'),
45

@@ -200,6 +201,48 @@ module.exports = {
200201
return title;
201202
},
202203

204+
/**
205+
* Adds provided property array to the given JSON path
206+
*
207+
* @param {string} jsonPath - JSON path to which properties should be added
208+
* @param {array} propArray - Array of properties to be added to JSON path
209+
* @returns {string} - Combined JSON path
210+
*/
211+
addToJsonPath: function (jsonPath, propArray) {
212+
const jsonPathArray = jsonPointer.parse(jsonPath),
213+
escapedPropArray = _.map(propArray, (prop) => {
214+
return jsonPointer.escape(prop);
215+
});
216+
217+
return jsonPointer.compile(jsonPathArray.concat(escapedPropArray));
218+
},
219+
220+
/**
221+
* Merges two JSON paths. i.e. Parent JSON path and Child JSON path
222+
*
223+
* @param {string} parentJsonPath - Parent JSON path
224+
* @param {string} childJsonPath - Child JSON path
225+
* @returns {string} - Merged JSON path
226+
*/
227+
mergeJsonPath: function (parentJsonPath, childJsonPath) {
228+
let jsonPathArray = jsonPointer.parse(parentJsonPath);
229+
230+
// Merges childJsonPath with parentJsonPath
231+
jsonPathArray = jsonPathArray.concat(jsonPointer.parse(childJsonPath));
232+
233+
return jsonPointer.compile(jsonPathArray);
234+
},
235+
236+
/**
237+
* Gets JSON path in array from string JSON path
238+
*
239+
* @param {string} jsonPath - input JSON path
240+
* @returns {array} - Parsed JSON path (each part is distributed in an array)
241+
*/
242+
getJsonPathArray: function (jsonPath) {
243+
return jsonPointer.parse(jsonPointer.unescape(jsonPath));
244+
},
245+
203246
generatePmResponseObject,
204247
generateRequestItemObject
205248
};

libV2/validationUtils.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ function safeSchemaFaker (context, oldSchema, resolveFor, parameterSourceOption,
159159
* i.e. For array it'll add maxItems = 2. This should be avoided as we'll again be needing non-mutated schema
160160
* in further VALIDATION use cases as needed.
161161
*/
162-
resolvedSchema = resolveSchema(context, _.cloneDeep(oldSchema), 0, _.toLower(PROCESSING_TYPE.CONVERSION));
162+
resolvedSchema = resolveSchema(context, _.cloneDeep(oldSchema), {
163+
resolveFor: _.toLower(PROCESSING_TYPE.CONVERSION),
164+
isResponseSchema: parameterSourceOption === PARAMETER_SOURCE.RESPONSE
165+
});
163166

164167
resolvedSchema = concreteUtils.fixExamplesByVersion(resolvedSchema);
165168
key = JSON.stringify(resolvedSchema);
@@ -404,8 +407,10 @@ function getParameterDescription (parameter) {
404407
*/
405408
function getParamSerialisationInfo (param, parameterSource, components, options) {
406409
var paramName = _.get(param, 'name'),
407-
paramSchema = resolveSchema(getDefaultContext(options, components), _.cloneDeep(param.schema),
408-
0, PROCESSING_TYPE.VALIDATION),
410+
paramSchema = resolveSchema(getDefaultContext(options, components), _.cloneDeep(param.schema), {
411+
resolveFor: PROCESSING_TYPE.VALIDATION,
412+
isResponseSchema: parameterSource === PARAMETER_SOURCE.RESPONSE
413+
}),
409414
style, // style property defined/inferred from schema
410415
explode, // explode property defined/inferred from schema
411416
propSeparator, // separates two properties or values
@@ -494,8 +499,10 @@ function getParamSerialisationInfo (param, parameterSource, components, options)
494499
*/
495500
function deserialiseParamValue (param, paramValue, parameterSource, components, options) {
496501
var constructedValue,
497-
paramSchema = resolveSchema(getDefaultContext(options, components), _.cloneDeep(param.schema),
498-
0, PROCESSING_TYPE.VALIDATION),
502+
paramSchema = resolveSchema(getDefaultContext(options, components), _.cloneDeep(param.schema), {
503+
resolveFor: PROCESSING_TYPE.VALIDATION,
504+
isResponseSchema: parameterSource === PARAMETER_SOURCE.RESPONSE
505+
}),
499506
isEvenNumber = (num) => {
500507
return (num % 2 === 0);
501508
},
@@ -1335,7 +1342,10 @@ function checkValueAgainstSchema (context, property, jsonPathPrefix, txnParamNam
13351342
invalidJson = false,
13361343
valueToUse = value,
13371344

1338-
schema = resolveSchema(context, openApiSchemaObj, 0, PROCESSING_TYPE.VALIDATION),
1345+
schema = resolveSchema(context, openApiSchemaObj, {
1346+
resolveFor: PROCESSING_TYPE.VALIDATION,
1347+
isResponseSchema: parameterSourceOption === PARAMETER_SOURCE.RESPONSE
1348+
}),
13391349
compositeSchema = schema.oneOf || schema.anyOf,
13401350
compareTypes = _.get(context, 'concreteUtils.compareTypes') || concreteUtils.compareTypes;
13411351

@@ -1711,7 +1721,9 @@ function checkPathVariables (context, matchedPathData, transactionPathPrefix, sc
17111721
};
17121722

17131723
if (options.suggestAvailableFixes) {
1714-
const resolvedSchema = resolveSchema(context, pathVar.schema, 0, PROCESSING_TYPE.VALIDATION);
1724+
const resolvedSchema = resolveSchema(context, pathVar.schema, {
1725+
resolveFor: PROCESSING_TYPE.VALIDATION
1726+
});
17151727

17161728
mismatchObj.suggestedFix = {
17171729
key: pathVar.name,
@@ -1758,8 +1770,9 @@ function checkQueryParams (context, queryParams, transactionPathPrefix, schemaPa
17581770
// below will make sure for exploded params actual schema of property present in collection is present
17591771
_.forEach(schemaParams, (param) => {
17601772
let pathPrefix = param.pathPrefix,
1761-
paramSchema = resolveSchema(context, _.cloneDeep(param.schema),
1762-
0, PROCESSING_TYPE.VALIDATION),
1773+
paramSchema = resolveSchema(context, _.cloneDeep(param.schema), {
1774+
resolveFor: PROCESSING_TYPE.VALIDATION
1775+
}),
17631776
{ style, explode } = getParamSerialisationInfo(param, PARAMETER_SOURCE.REQUEST, components, options),
17641777
encodingObj = { [param.name]: { style, explode } },
17651778
metaInfo = {
@@ -1862,7 +1875,9 @@ function checkQueryParams (context, queryParams, transactionPathPrefix, schemaPa
18621875
};
18631876

18641877
if (options.suggestAvailableFixes) {
1865-
const resolvedSchema = resolveSchema(context, qp.schema, 0, PROCESSING_TYPE.VALIDATION);
1878+
const resolvedSchema = resolveSchema(context, qp.schema, {
1879+
resolveFor: PROCESSING_TYPE.VALIDATION
1880+
});
18661881

18671882
mismatchObj.suggestedFix = {
18681883
key: qp.name,
@@ -2000,7 +2015,9 @@ function checkRequestHeaders (context, headers, transactionPathPrefix, schemaPat
20002015
};
20012016

20022017
if (options.suggestAvailableFixes) {
2003-
const resolvedSchema = resolveSchema(context, header.schema, 0, PROCESSING_TYPE.VALIDATION);
2018+
const resolvedSchema = resolveSchema(context, header.schema, {
2019+
resolveFor: PROCESSING_TYPE.VALIDATION
2020+
});
20042021

20052022
mismatchObj.suggestedFix = {
20062023
key: header.name,
@@ -2131,15 +2148,18 @@ function checkResponseHeaders (context, schemaResponse, headers, transactionPath
21312148
};
21322149

21332150
if (options.suggestAvailableFixes) {
2134-
const resolvedSchema = resolveSchema(context, header.schema, 0, PROCESSING_TYPE.VALIDATION);
2151+
const resolvedSchema = resolveSchema(context, header.schema, {
2152+
resolveFor: PROCESSING_TYPE.VALIDATION,
2153+
isResponseSchema: true
2154+
});
21352155

21362156
mismatchObj.suggestedFix = {
21372157
key: header.name,
21382158
actualValue: null,
21392159
suggestedValue: {
21402160
key: header.name,
21412161
value: safeSchemaFaker(context, resolvedSchema || {}, PROCESSING_TYPE.VALIDATION,
2142-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
2162+
PARAMETER_SOURCE.RESPONSE, components, SCHEMA_FORMATS.DEFAULT, schemaCache),
21432163
description: getParameterDescription(header)
21442164
}
21452165
};
@@ -2204,8 +2224,9 @@ function checkRequestBody (context, requestBody, transactionPathPrefix, schemaPa
22042224
return param.value !== OAS_NOT_SUPPORTED;
22052225
});
22062226

2207-
urlencodedBodySchema = resolveSchema(context, urlencodedBodySchema,
2208-
0, PROCESSING_TYPE.VALIDATION);
2227+
urlencodedBodySchema = resolveSchema(context, urlencodedBodySchema, {
2228+
resolveFor: PROCESSING_TYPE.VALIDATION
2229+
});
22092230

22102231
resolvedSchemaParams = resolveFormParamSchema(urlencodedBodySchema, '', encodingObj,
22112232
filteredUrlEncodedBody, {}, components, options);
@@ -2313,7 +2334,9 @@ function checkRequestBody (context, requestBody, transactionPathPrefix, schemaPa
23132334
};
23142335

23152336
if (options.suggestAvailableFixes) {
2316-
const resolvedSchema = resolveSchema(context, uParam.schema, 0, PROCESSING_TYPE.VALIDATION);
2337+
const resolvedSchema = resolveSchema(context, uParam.schema, {
2338+
resolveFor: PROCESSING_TYPE.VALIDATION
2339+
});
23172340

23182341
mismatchObj.suggestedFix = {
23192342
key: uParam.name,

package-lock.json

Lines changed: 29 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-to-postmanv2",
3-
"version": "4.23.1",
3+
"version": "4.24.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",
@@ -122,6 +122,7 @@
122122
"async": "3.2.4",
123123
"commander": "2.20.3",
124124
"js-yaml": "4.1.0",
125+
"json-pointer": "0.6.2",
125126
"json-schema-merge-allof": "0.8.1",
126127
"lodash": "4.17.21",
127128
"neotraverse": "0.6.15",

test/data/valid_openapi/readOnly.json

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@
2121
"type": "array",
2222
"items": {
2323
"type": "object",
24-
"$ref": "#/components/schemas/Pet"
24+
"properties": {
25+
"id": {
26+
"type": "integer",
27+
"format": "int64",
28+
"readOnly": true
29+
},
30+
"name": {
31+
"type": "string"
32+
},
33+
"tag": {
34+
"type": "string",
35+
"writeOnly": true
36+
}
37+
}
2538
}
2639
}
2740
}
@@ -59,25 +72,5 @@
5972
}
6073
}
6174
}
62-
},
63-
"components": {
64-
"schemas": {
65-
"Pet": {
66-
"properties": {
67-
"id": {
68-
"type": "integer",
69-
"format": "int64",
70-
"readOnly": true
71-
},
72-
"name": {
73-
"type": "string"
74-
},
75-
"tag": {
76-
"type": "string",
77-
"writeOnly": true
78-
}
79-
}
80-
}
81-
}
8275
}
8376
}

0 commit comments

Comments
 (0)