Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.1.13 #205

Merged
merged 36 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
59ccea4
Avoid storing in schema resolution cache if schema not resolved previ…
umeshp7 Mar 18, 2020
b767986
Merge branch 'develop' into feature/fix-schema-res-cache
umeshp7 Mar 27, 2020
471b87f
Fix failing tests
umeshp7 Mar 31, 2020
2203813
Add handling for escaped characters in deref.resolveRefs
umeshp7 Mar 31, 2020
2391764
Add unit test for path ref not found error
umeshp7 Apr 6, 2020
7b5caaa
Added support for resolving refs for VALIDATION with default being fo…
VShingala Apr 7, 2020
8aa67e5
Added tests for confirming change
VShingala Apr 7, 2020
8da0adf
Fixed URIError for invalid Uri in transaction
VShingala Apr 7, 2020
1afad53
Merge pull request #197 from postmanlabs/feature/fix-uri-error
abhijitkane Apr 8, 2020
7cf4217
Addressed comments regarding renaming RESOLVE_REFS_FOR to PROCESSING_…
VShingala Apr 8, 2020
1585a1e
Add handling for correct baseUrl formation
umeshp7 Apr 13, 2020
5072e87
Merge pull request #190 from postmanlabs/feature/resolve-ref-path
abhijitkane Apr 13, 2020
eb5cc8e
Merge pull request #196 from postmanlabs/feature/support-resolveref-f…
abhijitkane Apr 13, 2020
6e9a7af
Fixed invalid transaction paths and changed REQUEST_BODY to BODY for …
VShingala Apr 14, 2020
8bd37ae
Fixed typo
VShingala Apr 14, 2020
7ca547a
Added support for detaied validation errors with option detailedBlobV…
VShingala Apr 14, 2020
61d1b55
Updated getOptions structure tests for detailedValidationBlob option
VShingala Apr 14, 2020
6648f9d
Merge branch 'develop' into feature/fix-schema-res-cache
umeshp7 Apr 15, 2020
fecf172
Resolve refs for processing type VALIDATION upon request body validation
VShingala Apr 15, 2020
ce054e4
Added quotes ariund property names and use protactive lodash get
VShingala Apr 15, 2020
f2a56b4
Use bracket resolution for application/json
VShingala Apr 15, 2020
3a8a824
Use bracket resolution for application/json
VShingala Apr 15, 2020
28932e1
Add unit test for too many refs fix
umeshp7 Apr 15, 2020
7e67562
Merge pull request #198 from postmanlabs/feature/fixed-transactionpat…
abhijitkane Apr 15, 2020
f11caa5
Add safe check avoid undef error
umeshp7 Apr 16, 2020
bfc6d55
Merge branch 'develop' of github.com:postmanlabs/openapi-to-postman i…
VShingala Apr 17, 2020
5276a0d
Remove unnecessary handling for path level servers in convertRequestT…
umeshp7 Apr 17, 2020
7f7b7a1
Show detailed messages for request/response body only and Removed non…
VShingala Apr 17, 2020
39b76f6
Fixed getOptions test for detailedBlobValidation option
VShingala Apr 17, 2020
4b569de
Add special handling for local server urls
umeshp7 Apr 17, 2020
8718e7d
Merge pull request #188 from postmanlabs/feature/fix-schema-res-cache
umeshp7 Apr 17, 2020
1f2b518
Merge pull request #199 from postmanlabs/feature/show-body-mismatches
abhijitkane Apr 21, 2020
facbee8
Merge pull request #201 from postmanlabs/feature/server-url-bug-fix
abhijitkane Apr 21, 2020
aab6b77
Changelog for v1.1.13
umeshp7 Apr 21, 2020
a1b74ef
1.1.13
umeshp7 Apr 21, 2020
55c6586
Update changelog for v1.1.13
umeshp7 Apr 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# OpenAPI-Postman Changelog
#### v1.1.13 (April 21, 2020)
* Added support for detailed validation body mismatches with option detailedBlobValidation.
* Fixed unable to validate schema with type array. [#8098](https://github.com/postmanlabs/postman-app-support/issues/8098)
umeshp7 marked this conversation as resolved.
Show resolved Hide resolved
* Fixed URIError for invalid Uri in transaction.
umeshp7 marked this conversation as resolved.
Show resolved Hide resolved
* Fixed an issue where link in same file was not being resolved. [#152](https://github.com/postmanlabs/openapi-to-postman/issues/152)
* Added proper handling for path variables in path and local servers. [#160](https://github.com/postmanlabs/openapi-to-postman/issues/160)
umeshp7 marked this conversation as resolved.
Show resolved Hide resolved
* Unresolved refs will not be stored in schemaResolutionCache.

#### v1.1.12 (Mar 26, 2020)
* Fix for https://github.com/postmanlabs/openapi-to-postman/issues/133 and https://github.com/postmanlabs/openapi-to-postman/issues/101
Expand Down
49 changes: 49 additions & 0 deletions lib/ajvValidationError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var _ = require('lodash');

/**
* This function generates reason and reasonCodes (used in mismatch objects) using Ajv Validation Error
*
* @param {Object} ajvValidationErrorObj Ajv Validation Error Object (reference: https://ajv.js.org/#validation-errors)
* @param {Object} data data needed for generation of mismatch Object
*
* @returns {Object} mismatchObj with reason and reasonCode properties
*/
function ajvValidationError(ajvValidationErrorObj, data) {
var mismatchPropName = _.get(ajvValidationErrorObj, 'dataPath', '').slice(1),
mismatchObj = {
reason: `The ${data.humanPropName} property "${mismatchPropName}" ` +
`${ajvValidationErrorObj.message}`,
reasonCode: 'INVALID_TYPE'
};

switch (ajvValidationErrorObj.keyword) {

case 'additionalProperties':
mismatchObj.reasonCode = 'MISSING_IN_SCHEMA';
break;

case 'dependencies':
mismatchObj.reason = `The ${data.humanPropName} property "${mismatchPropName}" ` +
`should have property "${_.get(ajvValidationErrorObj, 'params.missingProperty')}" when property ` +
`"${_.get(ajvValidationErrorObj, 'params.property')}" is present`;
break;

case 'required':
mismatchObj.reasonCode = 'MISSING_IN_REQUEST';
mismatchObj.reason = `The ${data.humanPropName} property "${mismatchPropName}" should have required ` +
`property "${_.get(ajvValidationErrorObj, 'params.missingProperty')}"`;
break;

case 'propertyNames':
mismatchObj.reason = `The ${data.humanPropName} property "${mismatchPropName}" contains invalid ` +
`property named "${_.get(ajvValidationErrorObj, 'params.propertyName')}"`;
break;

default:
break;
}

return mismatchObj;
}

module.exports = ajvValidationError;
76 changes: 55 additions & 21 deletions lib/deref.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,28 @@ module.exports = {
* @param {string} parameterSourceOption tells that the schema object is of request or response
* @param {*} components components in openapi spec.
* @param {object} schemaResolutionCache stores already resolved references
* @param {*} resolveFor - resolve refs for validation/conversion (value to be one of VALIDATION/CONVERSION)
* @param {*} stack counter which keeps a tab on nested schemas
* @param {*} seenRef References that are repeated. Used to identify circular references.
* @returns {*} schema - schema that adheres to all individual schemas in schemaArr
*/
resolveAllOf: function (schemaArr, parameterSourceOption, components, schemaResolutionCache, stack = 0, seenRef) {
resolveAllOf: function (schemaArr, parameterSourceOption, components, schemaResolutionCache,
resolveFor = 'CONVERSION', stack = 0, seenRef) {

if (!(schemaArr instanceof Array)) {
return null;
}

if (schemaArr.length === 1) {
// for just one entry in allOf, don't need to enforce type: object restriction
return this.resolveRefs(schemaArr[0], parameterSourceOption, components, schemaResolutionCache, stack, seenRef);
return this.resolveRefs(schemaArr[0], parameterSourceOption, components, schemaResolutionCache, resolveFor,
stack, seenRef);
}

// generate one object for each schema
let indivObjects = schemaArr.map((schema) => {
return this.resolveRefs(schema, parameterSourceOption, components, schemaResolutionCache, stack, seenRef);
return this.resolveRefs(schema, parameterSourceOption, components, schemaResolutionCache, resolveFor,
stack, seenRef);
}).filter((schema) => {
return schema.type === 'object';
}),
Expand Down Expand Up @@ -107,33 +112,39 @@ module.exports = {
* @param {string} parameterSourceOption tells that the schema object is of request or response
* @param {*} components components in openapi spec.
* @param {object} schemaResolutionCache stores already resolved references
* @param {*} resolveFor - resolve refs for validation/conversion (value to be one of VALIDATION/CONVERSION)
* @param {*} stack counter which keeps a tab on nested schemas
* @param {*} seenRef - References that are repeated. Used to identify circular references.
* @returns {*} schema satisfying JSON-schema-faker.
*/
resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache, stack = 0, seenRef = {}) {
var resolvedSchema, prop, splitRef;

resolveRefs: function (schema, parameterSourceOption, components, schemaResolutionCache,
resolveFor = 'CONVERSION', stack = 0, seenRef = {}) {
var resolvedSchema, prop, splitRef,
ERR_TOO_MANY_LEVELS = '<Error: Too many levels of nesting to fake this schema>';

stack++;
schemaResolutionCache = schemaResolutionCache || {};

if (stack > 20) {
return { value: '<Error: Too many levels of nesting to fake this schema>' };
return { value: ERR_TOO_MANY_LEVELS };
}

if (!schema) {
return { value: '<Error: Schema not found>' };
}

if (schema.anyOf) {
return this.resolveRefs(schema.anyOf[0], parameterSourceOption, components, schemaResolutionCache, stack,
_.cloneDeep(seenRef));
return this.resolveRefs(schema.anyOf[0], parameterSourceOption, components, schemaResolutionCache, resolveFor,
stack, _.cloneDeep(seenRef));
}
if (schema.oneOf) {
return this.resolveRefs(schema.oneOf[0], parameterSourceOption, components, schemaResolutionCache, stack,
_.cloneDeep(seenRef));
return this.resolveRefs(schema.oneOf[0], parameterSourceOption, components, schemaResolutionCache, resolveFor,
stack, _.cloneDeep(seenRef));
}
if (schema.allOf) {
return this.resolveAllOf(schema.allOf, parameterSourceOption, components, schemaResolutionCache, stack,
_.cloneDeep(seenRef));
return this.resolveAllOf(schema.allOf, parameterSourceOption, components, schemaResolutionCache, resolveFor,
stack, _.cloneDeep(seenRef));
}
if (schema.$ref && _.isFunction(schema.$ref.split)) {
let refKey = schema.$ref;
Expand All @@ -160,12 +171,27 @@ module.exports = {
// will be resolved - we don't care about anything after the components part
// splitRef.slice(1) will return ['components', 'schemas', 'PaginationEnvelope', 'properties', 'page']
// not using _.get here because that fails if there's a . in the property name (Pagination.Envelope, for example)
resolvedSchema = this._getEscaped(components, splitRef.slice(1));

splitRef = splitRef.slice(1).map((elem) => {
// https://swagger.io/docs/specification/using-ref#escape
// since / is the default delimiter, slashes are escaped with ~1
return decodeURIComponent(
elem
.replace(/~1/g, '/')
.replace(/~0/g, '~')
);
});

resolvedSchema = this._getEscaped(components, splitRef);

if (resolvedSchema) {
let refResolvedSchema = this.resolveRefs(resolvedSchema, parameterSourceOption,
components, schemaResolutionCache, stack, _.cloneDeep(seenRef));
schemaResolutionCache[refKey] = refResolvedSchema;
components, schemaResolutionCache, resolveFor, stack, _.cloneDeep(seenRef));

if (refResolvedSchema && refResolvedSchema.value !== ERR_TOO_MANY_LEVELS) {
schemaResolutionCache[refKey] = refResolvedSchema;
}

return refResolvedSchema;
}
return { value: 'reference ' + schema.$ref + ' not found in the OpenAPI spec' };
Expand Down Expand Up @@ -196,7 +222,7 @@ module.exports = {
}
/* eslint-enable */
tempSchema.properties[prop] = this.resolveRefs(property,
parameterSourceOption, components, schemaResolutionCache, stack, _.cloneDeep(seenRef));
parameterSourceOption, components, schemaResolutionCache, resolveFor, stack, _.cloneDeep(seenRef));
}
}
return tempSchema;
Expand All @@ -207,15 +233,19 @@ module.exports = {
}
else if (schema.type === 'array' && schema.items) {

// This nonsense is needed because the schemaFaker doesn't respect options.maxItems/minItems
schema.maxItems = 2;
schema.minItems = 2;
// For VALIDATION - keep minItems and maxItems properties defined by user in schema as is
// FOR CONVERSION - need to set both properties to 2 for schema faking
if (resolveFor === 'CONVERSION') {
// This is needed because the schemaFaker doesn't respect options.maxItems/minItems
schema.maxItems = 2;
schema.minItems = 2;
}
// have to create a shallow clone of schema object,
// so that the original schema.items object will not change
// without this, schemas with circular references aren't faked correctly
let tempSchema = _.omit(schema, 'items');
tempSchema.items = this.resolveRefs(schema.items, parameterSourceOption,
components, schemaResolutionCache, stack, _.cloneDeep(seenRef));
components, schemaResolutionCache, resolveFor, stack, _.cloneDeep(seenRef));
return tempSchema;
}
else if (!schema.hasOwnProperty('default')) {
Expand Down Expand Up @@ -251,7 +281,11 @@ module.exports = {
if (!schema.type) {
schema.type = 'string';
}
delete schema.format;

// For VALIDATION - Keep format as is to perform ajv validation on format
if (resolveFor !== 'VALIDATION') {
delete schema.format;
}
}

return schema;
Expand Down
9 changes: 9 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ module.exports = {
description: 'MISSING_IN_SCHEMA indicates that an extra parameter was included in the request. For most ' +
'use cases, this need not be considered an error.',
external: true
},
{
name: 'Show detailed body validation messages',
id: 'detailedBlobValidation',
type: 'boolean',
default: false,
description: 'Determines whether to show detailed mismatch information for application/json content ' +
'in the request/response body',
external: true
}
];

Expand Down
Loading