fastify-openapi-glue
Version:
generate a fastify configuration from an openapi specification
36 lines (30 loc) • 1.05 kB
JavaScript
import { comments } from "../templateUtils.js";
export default (data) =>
`// this file contains a test harness that was auto-generated by fastify-openapi-glue
// running the tests directly after generation will probably fail as the parameters
// need to be manually added.
import { test } from "node:test";
import Fastify from "fastify";
import fastifyPlugin, { options } from "../${data.plugin}";
const opts = {};
//${data.routes
.map(
(route) => `
// Operation: ${route.operationId}
// URL: ${route.url}
// summary: ${route.schema.summary}
${comments(route, 0)}
test("testing ${route.operationId}", async (t) => {
const fastify = Fastify(options);
fastify.register(fastifyPlugin, opts);
const res = await fastify.inject({
method: "${route.method}",
url: "${data.prefix ? data.prefix : ""}${route.url}",
payload: undefined,${route.schema.body ? " //insert body data here!!" : ""}
headers: undefined,${route.schema.headers ? " //insert headers here!!" : ""}
});
t.assert.equal(res.statusCode, 200);
});`,
)
.join("\n")}
`;