UNPKG

fastify-openapi-glue

Version:

generate a fastify configuration from an openapi specification

36 lines (33 loc) 1.26 kB
import path from "node:path"; import { test } from "node:test"; import { Generator } from "../lib/generator.js"; import { templateTypes } from "../lib/templates/templateTypes.js"; const localFile = (fileName) => path.join(import.meta.dirname, fileName); const dir = localFile("."); const checksumOnly = true; const localPlugin = false; // if you need new checksums (e.g. because you changed template or spec file) // run `npm run updateChecksums` const specs = new Set(["./test-swagger.v2", "./test-swagger-noBasePath.v2"]); for (const type of templateTypes) { for (const spec of specs) { const specFile = localFile(`${spec}.json`); const checksumFile = localFile(`${spec}.${type}.checksums.json`); const testChecksums = ( await import(checksumFile, { with: { type: "json" }, }) ).default; const project = `generated-${type}-project`; const generator = new Generator(checksumOnly, localPlugin); await test(`generator generates ${type} project data for ${spec}`, async (t) => { try { await generator.parse(specFile); const checksums = await generator.generateProject(dir, project, type); t.assert.deepEqual(checksums, testChecksums, "checksums match"); } catch (e) { t.assert.fail(e.message); } }); } }