Skip to content

Commit

Permalink
expose current file when encountering validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarti350_comcast committed May 2, 2024
1 parent 1b6484f commit 811985b
Showing 1 changed file with 92 additions and 93 deletions.
185 changes: 92 additions & 93 deletions src/validate/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const run = async ({
}
})

const examples = ajv.compile(exampleSpec)
const examples = ajv.compile(exampleSpec)

let result = validate(json, {}, ajv, jsonschema)
let exampleResult = validate(json, {}, ajv, examples)
Expand All @@ -158,117 +158,116 @@ const run = async ({

// Validate all modules
Object.keys(modules).forEach(key => {
let json = JSON.parse(modules[key])
try {
let json = JSON.parse(modules[key])

if (transformations) {
// Do the firebolt API magic
json = fireboltize(json)
if (transformations) {
// Do the firebolt API magic
json = fireboltize(json)

// pull in external markdown files for descriptions
json = addExternalMarkdown(json, markdown)
// pull in external markdown files for descriptions
json = addExternalMarkdown(json, markdown)

// Make sure we have a place to drop shared schemas
json.components = json.components || {}
json.components.schemas = json.components.schemas || {}
// Make sure we have a place to drop shared schemas
json.components = json.components || {}
json.components.schemas = json.components.schemas || {}

// add externally referenced schemas that are in our shared schemas path
json = addExternalSchemas(json, sharedSchemas)
}
// add externally referenced schemas that are in our shared schemas path
json = addExternalSchemas(json, sharedSchemas)
}

const exampleSpec = {
"$id": "https://meta.rdkcentral.com/firebolt/dynamic/" + (json.info.title) +"/examples",
"title": "FireboltOpenRPCExamples",
"definitions": {
"Document": {
"type": "object",
"properties": {
"methods": {
"type": "array",
"items": {
"allOf": json.methods.map(method => ({
"if": {
"type": "object",
"properties": {
"name": {
"const": method.name
const exampleSpec = {
"$id": "https://meta.rdkcentral.com/firebolt/dynamic/" + (json.info.title) +"/examples",
"title": "FireboltOpenRPCExamples",
"definitions": {
"Document": {
"type": "object",
"properties": {
"methods": {
"type": "array",
"items": {
"allOf": json.methods.map(method => ({
"if": {
"type": "object",
"properties": {
"name": {
"const": method.name
}
}
}
},
"then": {
"type": "object",
"properties": {
"examples": {
"type": "array",
"items": {
"type": "object",
"properties": {
"result": {
"type": "object",
"properties": {
"value": method.result.schema
}
},
"params": method.params.length ? {
"type": "array",
"items": {
"allOf": method.params.map(param => ({
"if": {
"type": "object",
"properties": {
"name": {
"const": param.name
},
"then": {
"type": "object",
"properties": {
"examples": {
"type": "array",
"items": {
"type": "object",
"properties": {
"result": {
"type": "object",
"properties": {
"value": method.result.schema
}
},
"params": method.params.length ? {
"type": "array",
"items": {
"allOf": method.params.map(param => ({
"if": {
"type": "object",
"properties": {
"name": {
"const": param.name
}
}
},
"then": {
"type": "object",
"properties": {
"value": param.schema
}
}
},
"then": {
"type": "object",
"properties": {
"value": param.schema
}
}
}))
},
"if": {
"type": "array" // always true, but avoids an empty allOf below
},
"then": method.params.filter(p => p.required).length ? {
"allOf": method.params.filter(p => p.required).map(param => ({
"contains": {
"type": "object",
"properties": {
"name": {
"const": param.name
}))
},
"if": {
"type": "array" // always true, but avoids an empty allOf below
},
"then": method.params.filter(p => p.required).length ? {
"allOf": method.params.filter(p => p.required).map(param => ({
"contains": {
"type": "object",
"properties": {
"name": {
"const": param.name
}
}
}
}
}))
}))
} : {}
} : {}
} : {}
}
}
}
}
}
}
}))
}))
}
}
}
}
}
},
"x-schemas": json['x-schemas'],
"components": json.components
}

exampleSpec.oneOf = [
{
"$ref": "#/definitions/Document"
},
"x-schemas": json['x-schemas'],
"components": json.components
}
]

exampleSpec.oneOf = [
{
"$ref": "#/definitions/Document"
}
]

const examples = ajv.compile(exampleSpec)
const examples = ajv.compile(exampleSpec)

try {
const openrpcResult = validate(json, {}, ajv, openrpc)
const fireboltResult = validate(json, {}, ajv, firebolt)
const exampleResult = validate(json, {}, ajv, examples)
Expand All @@ -285,8 +284,8 @@ const run = async ({
// console.dir(exampleSpec, { depth: 100 })
}
}
}
catch (error) {
} catch (error) {
logError(`Error parsing ${key}\n`)
throw error
}
})
Expand All @@ -298,4 +297,4 @@ const run = async ({
return Promise.resolve()
}

export default run
export default run

0 comments on commit 811985b

Please sign in to comment.