Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11,746 changes: 11,746 additions & 0 deletions assets/json-schema-faker-bundle.js

Large diffs are not rendered by default.

25,050 changes: 0 additions & 25,050 deletions assets/json-schema-faker.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/30XUtils/schemaUtils30X.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ module.exports = {
return currentType === typeToValidate;
},

/**
* This method is to make this module matches with schemaUtilsXXX interface content
* It only returns the provided schema
* @param {object} schema a provided schema
* @returns {object} it returns the same schema
*/
fixExamplesByVersion(schema) {
return schema;
},

/**
* Check if request body type is binary type
* @param {string} bodyType the bodyType provided in a request body content
Expand Down
43 changes: 0 additions & 43 deletions lib/31XUtils/schemaUtils31X.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,49 +90,6 @@ module.exports = {
return { foundType, foundExample };
},

/**
* Takes the first element from 'examples' property in a schema and adds a new 'example' property.
* This method is used before faking the schema. (Schema faker uses the example property to fakle the schema)
* @param {object} schema a provided schema
* @returns {object} it returns the schema with a new example property
*/
fixExamplesByVersion(schema) {
// This method could be removed when schema faker gets upgraded
const hasExamplesInRoot = _.has(schema, 'examples'),
hasChildItems = _.has(schema, 'type') &&
_.has(schema, 'items'),
hasProperties = _.has(schema, 'properties'),
typeIsAnArray = _.has(schema, 'type') &&
Array.isArray(schema.type);

if (hasExamplesInRoot && typeIsAnArray) {
let typeAndExample = this.findTypeByExample(schema.examples, schema.type),
foundType = typeAndExample.foundType,
foundExample = typeAndExample.foundExample;
schema.type = foundType ? foundType : schema.type[0];
schema.example = foundExample ? foundExample : schema.examples[0];
}

if (hasExamplesInRoot && !typeIsAnArray) {
schema.example = schema.examples[0];
}

if (!hasExamplesInRoot && typeIsAnArray) {
schema.type = schema.type[0];
}

if (!hasExamplesInRoot && hasChildItems) {
schema.items = this.fixExamplesByVersion(schema.items);
}
else if (hasProperties) {
const schemaProperties = Object.keys(schema.properties);
schemaProperties.forEach((property) => {
schema.properties[property] = this.fixExamplesByVersion(schema.properties[property]);
});
}
return schema;
},

/**
* Check if request body type is binary type.
* Open api 3.1 does not need that a binary content has a schema within. It comes as an empty object
Expand Down
13 changes: 6 additions & 7 deletions lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
{ getConcreteSchemaUtils, isSwagger, validateSupportedVersion } = require('./common/versionUtils.js'),
async = require('async'),
sdk = require('postman-collection'),
schemaFaker = require('../assets/json-schema-faker.js'),
// schemaFaker = require('../assets/json-schema-faker.js'),
schemaFaker = require('../assets/json-schema-faker-bundle.js'),
deref = require('./deref.js'),
_ = require('lodash'),
xmlFaker = require('./xmlSchemaFaker.js'),
Expand Down Expand Up @@ -112,7 +113,9 @@ schemaFaker.option({
maxItems: 20, // limit on maximum number of items faked for (type: arrray)
useDefaultValue: true,
ignoreMissingRefs: true,
avoidExampleItemsLength: true // option to avoid validating type array schema example's minItems and maxItems props.
avoidExampleItemsLength: true, // option to avoid validating type array schema example's minItems and maxItems props.
validationOptions: { ignoreUnresolvedVariables: true }, // validation ignoring Postman variables
pickFirstFromExamples: true // option to pick first example from examples array
});

/**
Expand Down Expand Up @@ -144,13 +147,9 @@ function safeSchemaFaker(oldSchema, resolveTo, resolveFor, parameterSourceOption
var prop, key, resolvedSchema, fakedSchema,
schemaResolutionCache = _.get(schemaCache, 'schemaResolutionCache', {}),
schemaFakerCache = _.get(schemaCache, 'schemaFakerCache', {});
let concreteUtils = components && components.hasOwnProperty('concreteUtils') ?
components.concreteUtils :
DEFAULT_SCHEMA_UTILS;

resolvedSchema = deref.resolveRefs(oldSchema, parameterSourceOption, components, schemaResolutionCache,
resolveFor, resolveTo, 0, {}, stackLimit);
resolvedSchema = concreteUtils.fixExamplesByVersion(resolvedSchema);
key = JSON.stringify(resolvedSchema);

if (resolveTo === 'schema') {
Expand Down Expand Up @@ -197,7 +196,7 @@ function safeSchemaFaker(oldSchema, resolveTo, resolveFor, parameterSourceOption
return fakedSchema;
}
// for JSON, the indentCharacter will be applied in the JSON.stringify step later on
fakedSchema = schemaFaker(resolvedSchema);
fakedSchema = schemaFaker.generate(resolvedSchema, undefined, validateSchema);
schemaFakerCache[key] = fakedSchema;
return fakedSchema;
}
Expand Down
26 changes: 0 additions & 26 deletions test/unit/30Xsupport/schemaUtils30X.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,6 @@ describe('compareTypes method', function() {
});
});

describe('fixExamplesByVersion method', function() {
it('Should return the same schema than the provided', function() {
const providedSchema = {
required: [
'id',
'name'
],
type: 'object',
properties: {
id: {
type: 'integer'
},
name: {
type: 'string',
example: 'this is my fisrt example name in pet'
},
tag: {
type: 'string'
}
}
},
fixedSchemaWithExample = concreteUtils.fixExamplesByVersion(providedSchema);
expect(JSON.stringify(fixedSchemaWithExample)).to.be.equal(JSON.stringify(providedSchema));
});
});

describe('isBinaryContentType method', function() {
it('Should be true if content type is binary type without schema', function() {
const bodyType = 'application/octet-stream',
Expand Down
Loading