Add getMetaData function

This commit is contained in:
umeshp7
2020-04-20 14:09:21 +05:30
parent 1afad53ebc
commit 90c555ab58
2 changed files with 26 additions and 1 deletions

View File

@@ -18,6 +18,11 @@ module.exports = {
return schema.validationResult;
},
getMetaData: function (input) {
var schema = new SchemaPack(input);
return schema.metaData;
},
mergeAndValidate: function (input, cb) {
var schema = new SchemaPack(input);
schema.mergeAndValidate(cb);

View File

@@ -81,6 +81,7 @@ class SchemaPack {
);
// hardcoding this option - not exposed to users yet
this.computedOptions.schemaFaker = true;
this.metaData = null;
this.validate();
}
@@ -150,13 +151,32 @@ class SchemaPack {
}
this.openapi = specParseResult.openapi;
this.metaData = this.getMetaData(this.openapi);
this.validated = true;
this.validationResult = {
result: true
result: true,
meta: this.metaData
};
return this.validationResult;
}
getMetaData (openapi) {
if (!openapi) {
return {
result: false,
reason: 'Empty collection'
};
}
return {
result: true,
output: [{
type: 'collection',
data: _.get(openapi, 'info.title', COLLECTION_NAME)
}]
};
}
mergeAndValidate (cb) {
let input = this.input,
validationResult,