UNPKG

fastify-openapi-glue

Version:

generate a fastify configuration from an openapi specification

33 lines (30 loc) 1.28 kB
import { createRequire } from "node:module"; import { test } from "node:test"; import { Generator } from "../lib/generator.js"; import { templateTypes } from "../lib/templates/templateTypes.js"; const importJSON = createRequire(import.meta.url); const localFile = (fileName) => new URL(fileName, import.meta.url).pathname; 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 importJSON(checksumFile); 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); } }); } }