Skip to content

Commit 811985b

Browse files
author
jmarti350_comcast
committed
expose current file when encountering validation error
1 parent 1b6484f commit 811985b

1 file changed

Lines changed: 92 additions & 93 deletions

File tree

src/validate/index.mjs

Lines changed: 92 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const run = async ({
148148
}
149149
})
150150

151-
const examples = ajv.compile(exampleSpec)
151+
const examples = ajv.compile(exampleSpec)
152152

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

159159
// Validate all modules
160160
Object.keys(modules).forEach(key => {
161-
let json = JSON.parse(modules[key])
161+
try {
162+
let json = JSON.parse(modules[key])
162163

163-
if (transformations) {
164-
// Do the firebolt API magic
165-
json = fireboltize(json)
164+
if (transformations) {
165+
// Do the firebolt API magic
166+
json = fireboltize(json)
166167

167-
// pull in external markdown files for descriptions
168-
json = addExternalMarkdown(json, markdown)
168+
// pull in external markdown files for descriptions
169+
json = addExternalMarkdown(json, markdown)
169170

170-
// Make sure we have a place to drop shared schemas
171-
json.components = json.components || {}
172-
json.components.schemas = json.components.schemas || {}
171+
// Make sure we have a place to drop shared schemas
172+
json.components = json.components || {}
173+
json.components.schemas = json.components.schemas || {}
173174

174-
// add externally referenced schemas that are in our shared schemas path
175-
json = addExternalSchemas(json, sharedSchemas)
176-
}
175+
// add externally referenced schemas that are in our shared schemas path
176+
json = addExternalSchemas(json, sharedSchemas)
177+
}
177178

178-
const exampleSpec = {
179-
"$id": "https://meta.rdkcentral.com/firebolt/dynamic/" + (json.info.title) +"/examples",
180-
"title": "FireboltOpenRPCExamples",
181-
"definitions": {
182-
"Document": {
183-
"type": "object",
184-
"properties": {
185-
"methods": {
186-
"type": "array",
187-
"items": {
188-
"allOf": json.methods.map(method => ({
189-
"if": {
190-
"type": "object",
191-
"properties": {
192-
"name": {
193-
"const": method.name
179+
const exampleSpec = {
180+
"$id": "https://meta.rdkcentral.com/firebolt/dynamic/" + (json.info.title) +"/examples",
181+
"title": "FireboltOpenRPCExamples",
182+
"definitions": {
183+
"Document": {
184+
"type": "object",
185+
"properties": {
186+
"methods": {
187+
"type": "array",
188+
"items": {
189+
"allOf": json.methods.map(method => ({
190+
"if": {
191+
"type": "object",
192+
"properties": {
193+
"name": {
194+
"const": method.name
195+
}
194196
}
195-
}
196-
},
197-
"then": {
198-
"type": "object",
199-
"properties": {
200-
"examples": {
201-
"type": "array",
202-
"items": {
203-
"type": "object",
204-
"properties": {
205-
"result": {
206-
"type": "object",
207-
"properties": {
208-
"value": method.result.schema
209-
}
210-
},
211-
"params": method.params.length ? {
212-
"type": "array",
213-
"items": {
214-
"allOf": method.params.map(param => ({
215-
"if": {
216-
"type": "object",
217-
"properties": {
218-
"name": {
219-
"const": param.name
197+
},
198+
"then": {
199+
"type": "object",
200+
"properties": {
201+
"examples": {
202+
"type": "array",
203+
"items": {
204+
"type": "object",
205+
"properties": {
206+
"result": {
207+
"type": "object",
208+
"properties": {
209+
"value": method.result.schema
210+
}
211+
},
212+
"params": method.params.length ? {
213+
"type": "array",
214+
"items": {
215+
"allOf": method.params.map(param => ({
216+
"if": {
217+
"type": "object",
218+
"properties": {
219+
"name": {
220+
"const": param.name
221+
}
222+
}
223+
},
224+
"then": {
225+
"type": "object",
226+
"properties": {
227+
"value": param.schema
220228
}
221229
}
222-
},
223-
"then": {
224-
"type": "object",
225-
"properties": {
226-
"value": param.schema
227-
}
228-
}
229-
}))
230-
},
231-
"if": {
232-
"type": "array" // always true, but avoids an empty allOf below
233-
},
234-
"then": method.params.filter(p => p.required).length ? {
235-
"allOf": method.params.filter(p => p.required).map(param => ({
236-
"contains": {
237-
"type": "object",
238-
"properties": {
239-
"name": {
240-
"const": param.name
230+
}))
231+
},
232+
"if": {
233+
"type": "array" // always true, but avoids an empty allOf below
234+
},
235+
"then": method.params.filter(p => p.required).length ? {
236+
"allOf": method.params.filter(p => p.required).map(param => ({
237+
"contains": {
238+
"type": "object",
239+
"properties": {
240+
"name": {
241+
"const": param.name
242+
}
241243
}
242244
}
243-
}
244-
}))
245+
}))
246+
} : {}
245247
} : {}
246-
} : {}
248+
}
247249
}
248250
}
249251
}
250252
}
251-
}
252-
}))
253+
}))
254+
}
253255
}
254256
}
255257
}
256-
}
257-
},
258-
"x-schemas": json['x-schemas'],
259-
"components": json.components
260-
}
261-
262-
exampleSpec.oneOf = [
263-
{
264-
"$ref": "#/definitions/Document"
258+
},
259+
"x-schemas": json['x-schemas'],
260+
"components": json.components
265261
}
266-
]
267262

263+
exampleSpec.oneOf = [
264+
{
265+
"$ref": "#/definitions/Document"
266+
}
267+
]
268268

269-
const examples = ajv.compile(exampleSpec)
269+
const examples = ajv.compile(exampleSpec)
270270

271-
try {
272271
const openrpcResult = validate(json, {}, ajv, openrpc)
273272
const fireboltResult = validate(json, {}, ajv, firebolt)
274273
const exampleResult = validate(json, {}, ajv, examples)
@@ -285,8 +284,8 @@ const run = async ({
285284
// console.dir(exampleSpec, { depth: 100 })
286285
}
287286
}
288-
}
289-
catch (error) {
287+
} catch (error) {
288+
logError(`Error parsing ${key}\n`)
290289
throw error
291290
}
292291
})
@@ -298,4 +297,4 @@ const run = async ({
298297
return Promise.resolve()
299298
}
300299

301-
export default run
300+
export default run

0 commit comments

Comments
 (0)