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,
|
const { formatDataPath, formatSchemaPathToConverToDataPath } = require('../common/schemaUtilsCommon');
|
||||||
formatSchemaPathFromAJVErrorToConvertToDataPath,
|
|
||||||
typesMap } = require('../common/schemaUtilsCommon');
|
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
const IGNORED_KEYWORDS = ['propertyNames', 'const', 'additionalItems', 'dependencies'],
|
const IGNORED_KEYWORDS = ['propertyNames', 'const', 'additionalItems', 'dependencies'],
|
||||||
{ validateSchemaAJV } = require('./ajvValidator'),
|
{ validateSchemaAJV } = require('./ajvValidator'),
|
||||||
{ validateSchemaAJVDraft04 } = require('./ajvValidatorDraft04'),
|
{ 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
|
* Checks if value is postman variable or not
|
||||||
@@ -96,7 +112,6 @@ function checkValueTypesAndFormat(value, types, format) {
|
|||||||
}
|
}
|
||||||
return defaultValue === value;
|
return defaultValue === value;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -210,10 +225,11 @@ function validateSchema (schema, valueToUse, options = {}, jsonSchemaDialect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (validationError.keyword === 'type') {
|
if (validationError.keyword === 'type') {
|
||||||
let schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(validationError.schemaPath)),
|
let schemaDataPath = formatDataPath(formatSchemaPathToConverToDataPath(validationError.schemaPath)),
|
||||||
schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,
|
schemaToUse = schemaDataPath ? _.get(schema, schemaDataPath) : schema,
|
||||||
valueToValidate = dataPath ? _.get(valueToUse, dataPath) : valueToUse;
|
valueToValidate = dataPath ? _.get(valueToUse, dataPath) : valueToUse;
|
||||||
return !isTypeValue(valueToValidate, schemaToUse);
|
return !isTypeValue(valueToValidate,
|
||||||
|
schemaToUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,25 +2,7 @@
|
|||||||
* This file contains util functions that are common between versions
|
* This file contains util functions that are common between versions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const parse = require('../parse.js'),
|
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>'
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the # character from the beginning of a schema path
|
* Remove the # character from the beginning of a schema path
|
||||||
@@ -149,14 +131,9 @@ module.exports = {
|
|||||||
return min;
|
return min;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
formatSchemaPathToConverToDataPath: function (schemaPath) {
|
||||||
* 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) {
|
|
||||||
return removeTypeFromLastPosition(removeSharpAndSlashFromFirstPosition(schemaPath));
|
return removeTypeFromLastPosition(removeSharpAndSlashFromFirstPosition(schemaPath));
|
||||||
},
|
}
|
||||||
|
|
||||||
|
|
||||||
typesMap
|
|
||||||
};
|
};
|
||||||
|
|||||||
23
lib/deref.js
23
lib/deref.js
@@ -1,6 +1,23 @@
|
|||||||
const _ = require('lodash'),
|
const _ = require('lodash'),
|
||||||
mergeAllOf = require('json-schema-merge-allof'),
|
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 = {
|
PARAMETER_SOURCE = {
|
||||||
REQUEST: 'REQUEST',
|
REQUEST: 'REQUEST',
|
||||||
RESPONSE: 'RESPONSE'
|
RESPONSE: 'RESPONSE'
|
||||||
@@ -311,8 +328,8 @@ module.exports = {
|
|||||||
if (!schema.hasOwnProperty('format')) {
|
if (!schema.hasOwnProperty('format')) {
|
||||||
schema.default = '<' + schema.type + '>';
|
schema.default = '<' + schema.type + '>';
|
||||||
}
|
}
|
||||||
else if (typesMap.hasOwnProperty(schema.type)) {
|
else if (type.hasOwnProperty(schema.type)) {
|
||||||
schema.default = typesMap[schema.type][schema.format];
|
schema.default = type[schema.type][schema.format];
|
||||||
|
|
||||||
// in case the format is a custom format (email, hostname etc.)
|
// in case the format is a custom format (email, hostname etc.)
|
||||||
// https://swagger.io/docs/specification/data-models/data-types/#string
|
// https://swagger.io/docs/specification/data-models/data-types/#string
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const schemaUtilsCommon = require('../../lib/common/schemaUtilsCommon'),
|
const schemaUtilsCommon = require('../../lib/common/schemaUtilsCommon');
|
||||||
{ formatDataPath, formatSchemaPathFromAJVErrorToConvertToDataPath } = require('../../lib/common/schemaUtilsCommon'),
|
const { formatDataPath, formatSchemaPathToConverToDataPath } = require('../../lib/common/schemaUtilsCommon'),
|
||||||
expect = require('chai').expect;
|
expect = require('chai').expect;
|
||||||
|
|
||||||
describe('formatData method', function() {
|
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 ' +
|
it('should return properties/automatic/items/properties/configs/items ' +
|
||||||
'when entry is #/properties/automatic/items/properties/configs/items/type', function () {
|
'when entry is #/properties/automatic/items/properties/configs/items/type', function () {
|
||||||
const result =
|
const result = formatSchemaPathToConverToDataPath('#/properties/automatic/items/properties/configs/items/type');
|
||||||
formatSchemaPathFromAJVErrorToConvertToDataPath('#/properties/automatic/items/properties/configs/items/type');
|
|
||||||
expect(result).to.equal('properties/automatic/items/properties/configs/items');
|
expect(result).to.equal('properties/automatic/items/properties/configs/items');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user