mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Revert "Extract typesMap, space and lines issues, improve naming"
This reverts commit 50631020d2.
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
const { formatDataPath,
|
||||
formatSchemaPathFromAJVErrorToConvertToDataPath,
|
||||
typesMap } = require('../common/schemaUtilsCommon');
|
||||
const { formatDataPath, formatSchemaPathToConverToDataPath } = require('../common/schemaUtilsCommon');
|
||||
|
||||
var _ = require('lodash');
|
||||
const IGNORED_KEYWORDS = ['propertyNames', 'const', 'additionalItems', 'dependencies'],
|
||||
{ validateSchemaAJV } = require('./ajvValidator'),
|
||||
{ validateSchemaAJVDraft04 } = require('./ajvValidatorDraft04'),
|
||||
specialDraft = 'http://json-schema.org/draft-04/schema#';
|
||||
specialDraft = 'http://json-schema.org/draft-04/schema#',
|
||||
typesMap = {
|
||||
integer: {
|
||||
int32: '<integer>',
|
||||
int64: '<long>'
|
||||
},
|
||||
number: {
|
||||
float: '<float>',
|
||||
double: '<double>'
|
||||
},
|
||||
string: {
|
||||
byte: '<byte>',
|
||||
binary: '<binary>',
|
||||
date: '<date>',
|
||||
'date-time': '<dateTime>',
|
||||
password: '<password>'
|
||||
},
|
||||
boolean: '<boolean>'
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if value is postman variable or not
|
||||
@@ -96,7 +112,6 @@ function checkValueTypesAndFormat(value, types, format) {
|
||||
}
|
||||
return defaultValue === value;
|
||||
});
|
||||
|
||||
if (found) {
|
||||
return true;
|
||||
}
|
||||
@@ -210,10 +225,11 @@ function validateSchema (schema, valueToUse, options = {}, jsonSchemaDialect) {
|
||||
}
|
||||
|
||||
if (validationError.keyword === 'type') {
|
||||
let schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(validationError.schemaPath)),
|
||||
let schemaDataPath = formatDataPath(formatSchemaPathToConverToDataPath(validationError.schemaPath)),
|
||||
schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,
|
||||
valueToValidate = dataPath ? _.get(valueToUse, dataPath) : valueToUse;
|
||||
return !isTypeValue(valueToValidate, schemaToUse);
|
||||
return !isTypeValue(valueToValidate,
|
||||
schemaToUse);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -2,25 +2,7 @@
|
||||
* This file contains util functions that are common between versions
|
||||
*/
|
||||
|
||||
const parse = require('../parse.js'),
|
||||
typesMap = {
|
||||
integer: {
|
||||
int32: '<integer>',
|
||||
int64: '<long>'
|
||||
},
|
||||
number: {
|
||||
float: '<float>',
|
||||
double: '<double>'
|
||||
},
|
||||
string: {
|
||||
byte: '<byte>',
|
||||
binary: '<binary>',
|
||||
date: '<date>',
|
||||
'date-time': '<dateTime>',
|
||||
password: '<password>'
|
||||
},
|
||||
boolean: '<boolean>'
|
||||
};
|
||||
const parse = require('../parse.js');
|
||||
|
||||
/**
|
||||
* Remove the # character from the beginning of a schema path
|
||||
@@ -149,14 +131,9 @@ module.exports = {
|
||||
return min;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes initial "#/" from a schema path and the last "/type" segment
|
||||
* @param {string} schemaPath - The OAS 3.x specification specified in either YAML or JSON
|
||||
* @returns {string} - The schemaPath with initial #/ and last "/type" removed
|
||||
*/
|
||||
formatSchemaPathFromAJVErrorToConvertToDataPath: function (schemaPath) {
|
||||
formatSchemaPathToConverToDataPath: function (schemaPath) {
|
||||
return removeTypeFromLastPosition(removeSharpAndSlashFromFirstPosition(schemaPath));
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
typesMap
|
||||
};
|
||||
|
||||
23
lib/deref.js
23
lib/deref.js
@@ -1,6 +1,23 @@
|
||||
const _ = require('lodash'),
|
||||
mergeAllOf = require('json-schema-merge-allof'),
|
||||
{ typesMap } = require('./common/schemaUtilsCommon'),
|
||||
type = {
|
||||
integer: {
|
||||
int32: '<integer>',
|
||||
int64: '<long>'
|
||||
},
|
||||
number: {
|
||||
float: '<float>',
|
||||
double: '<double>'
|
||||
},
|
||||
string: {
|
||||
byte: '<byte>',
|
||||
binary: '<binary>',
|
||||
date: '<date>',
|
||||
'date-time': '<dateTime>',
|
||||
password: '<password>'
|
||||
},
|
||||
boolean: '<boolean>'
|
||||
},
|
||||
PARAMETER_SOURCE = {
|
||||
REQUEST: 'REQUEST',
|
||||
RESPONSE: 'RESPONSE'
|
||||
@@ -311,8 +328,8 @@ module.exports = {
|
||||
if (!schema.hasOwnProperty('format')) {
|
||||
schema.default = '<' + schema.type + '>';
|
||||
}
|
||||
else if (typesMap.hasOwnProperty(schema.type)) {
|
||||
schema.default = typesMap[schema.type][schema.format];
|
||||
else if (type.hasOwnProperty(schema.type)) {
|
||||
schema.default = type[schema.type][schema.format];
|
||||
|
||||
// in case the format is a custom format (email, hostname etc.)
|
||||
// https://swagger.io/docs/specification/data-models/data-types/#string
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const schemaUtilsCommon = require('../../lib/common/schemaUtilsCommon'),
|
||||
{ formatDataPath, formatSchemaPathFromAJVErrorToConvertToDataPath } = require('../../lib/common/schemaUtilsCommon'),
|
||||
const schemaUtilsCommon = require('../../lib/common/schemaUtilsCommon');
|
||||
const { formatDataPath, formatSchemaPathToConverToDataPath } = require('../../lib/common/schemaUtilsCommon'),
|
||||
expect = require('chai').expect;
|
||||
|
||||
describe('formatData method', function() {
|
||||
@@ -157,11 +157,10 @@ describe('handleExclusiveMinimum method', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatSchemaPathFromAJVErrorToConvertToDataPath method', function () {
|
||||
describe('formatSchemaPathToConverToDataPath method', function () {
|
||||
it('should return properties/automatic/items/properties/configs/items ' +
|
||||
'when entry is #/properties/automatic/items/properties/configs/items/type', function () {
|
||||
const result =
|
||||
formatSchemaPathFromAJVErrorToConvertToDataPath('#/properties/automatic/items/properties/configs/items/type');
|
||||
const result = formatSchemaPathToConverToDataPath('#/properties/automatic/items/properties/configs/items/type');
|
||||
expect(result).to.equal('properties/automatic/items/properties/configs/items');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user