mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
support for value prop in example
Add support for value prop in example
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
* utils.js contains other util functions
|
||||
*/
|
||||
|
||||
const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
|
||||
const { formatDataPath, checkIsCorrectType, isKnownType,
|
||||
formatSchemaPathFromAJVErrorToConvertToDataPath } = require('./common/schemaUtilsCommon.js'),
|
||||
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
|
||||
async = require('async'),
|
||||
sdk = require('postman-collection'),
|
||||
@@ -1360,6 +1361,28 @@ module.exports = {
|
||||
return example;
|
||||
},
|
||||
|
||||
useExampleValueAsValue(schema, example, components) {
|
||||
let isCandidate = true,
|
||||
schemaProperties = [],
|
||||
schemaObject,
|
||||
schemaDataPath = '',
|
||||
exampleProperties = [];
|
||||
if (!schema) {
|
||||
return isCandidate;
|
||||
}
|
||||
if (schema.$ref) {
|
||||
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(schema.$ref));
|
||||
schemaObject = _.get(components, schemaDataPath);
|
||||
}
|
||||
else {
|
||||
schemaObject = schema;
|
||||
}
|
||||
|
||||
schemaProperties = Object.keys(schemaObject.properties).sort();
|
||||
exampleProperties = Object.keys(example.value).sort();
|
||||
return JSON.stringify(schemaProperties) === JSON.stringify(exampleProperties);
|
||||
},
|
||||
|
||||
/**
|
||||
* converts one of the eamples or schema in Media Type object to postman data
|
||||
* @param {*} bodyObj is MediaTypeObject
|
||||
@@ -1410,7 +1433,8 @@ module.exports = {
|
||||
}
|
||||
bodyData = bodyObj.example;
|
||||
// return example value if present else example is returned
|
||||
if (bodyData.hasOwnProperty('value')) {
|
||||
if (bodyData.hasOwnProperty('value') &&
|
||||
this.useExampleValueAsValue(bodyObj.schema, bodyObj.example, components)) {
|
||||
bodyData = bodyData.value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user