(
filename: string,
additionalRendererOptions: RendererOptions,
additionalFiles: string[]
)
| 338 | } |
| 339 | |
| 340 | async test( |
| 341 | filename: string, |
| 342 | additionalRendererOptions: RendererOptions, |
| 343 | additionalFiles: string[] |
| 344 | ) { |
| 345 | let input = JSON.parse(fs.readFileSync(filename, "utf8")); |
| 346 | let schema = JSON.parse(fs.readFileSync("schema.json", "utf8")); |
| 347 | |
| 348 | let ajv = new Ajv({ format: "full" }); |
| 349 | let valid = ajv.validate(schema, input); |
| 350 | if (!valid) { |
| 351 | failWith("Generated schema does not validate input JSON.", { |
| 352 | filename |
| 353 | }); |
| 354 | } |
| 355 | |
| 356 | // Generate code from the schema |
| 357 | await quicktypeForLanguage( |
| 358 | this.runLanguage, |
| 359 | "schema.json", |
| 360 | "schema", |
| 361 | false, |
| 362 | additionalRendererOptions |
| 363 | ); |
| 364 | |
| 365 | // Parse the sample with the code generated from its schema, and compare to the sample |
| 366 | compareJsonFileToJson({ |
| 367 | expectedFile: filename, |
| 368 | given: { command: this.runLanguage.runCommand(filename) }, |
| 369 | strict: false, |
| 370 | allowMissingNull: this.runLanguage.allowMissingNull |
| 371 | }); |
| 372 | |
| 373 | // Generate a schema from the schema, making sure the schemas are the same |
| 374 | let schemaSchema = "schema-from-schema.json"; |
| 375 | await quicktype({ |
| 376 | src: ["schema.json"], |
| 377 | srcLang: "schema", |
| 378 | lang: "schema", |
| 379 | topLevel: "schema", |
| 380 | out: schemaSchema, |
| 381 | rendererOptions: {} |
| 382 | }); |
| 383 | compareJsonFileToJson({ |
| 384 | expectedFile: "schema.json", |
| 385 | given: { file: schemaSchema }, |
| 386 | strict: true |
| 387 | }); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | // This fixture tests generating code from Schema with features |
nothing calls this directly
no test coverage detected