Skip to content

Commit

Permalink
#40: remove error for cases where resource isn't standard
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit-s96 committed Oct 13, 2023
1 parent 4bb3cef commit e85399f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/schema/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const Ajv = require('ajv');
const addFormats = require('ajv-formats');
const chalk = require('chalk');
const { getReferenceMetadata } = require('@reso/reso-certification-etl');
const ajvErrors = require('ajv-errors');
const _ = require('lodash');

Expand Down Expand Up @@ -98,17 +97,16 @@ const validate = ({ jsonSchema = {}, resourceName = 'Property', jsonPayload, err

ddVersion = isValidDdVersion(version) ? version : DEFAULT_DD_VERSION;

const referenceMetadata = getReferenceMetadata(ddVersion);
if (!referenceMetadata?.resources?.find(r => r.resourceName.toLowerCase() === resource.toLocaleLowerCase())) {
console.log(chalk.redBright(`Found invalid resource: ${resource}`));
addPayloadError(resource, fileName, 'Invalid resource', payloadErrors);
}

const { definitions } = schema;
const singleValueSchema = schema?.oneOf?.find(s => !s.properties.value);
const multiValueSchema = schema?.oneOf?.find(s => s.properties.value);

const formattedResourceName = Object.keys(definitions ?? {}).find(r => r.toLowerCase() === resource.toLowerCase());
if (!formattedResourceName) {
console.log(chalk.redBright(`Found invalid resource: ${formattedResourceName}`));
addPayloadError(formattedResourceName, fileName, 'Invalid resource', payloadErrors);
return errorMap;
}
resourceName = formattedResourceName;
if (!payload.value) {
schema.oneOf = [singleValueSchema];
Expand Down

0 comments on commit e85399f

Please sign in to comment.