From 86168b6b75e93f53d168f653664d017ab08a933a Mon Sep 17 00:00:00 2001 From: Maxime Trimolet Date: Thu, 14 Oct 2021 16:10:55 +0200 Subject: [PATCH] feat: enable openapi v3.1 --- lib/parser.ts | 4 ++-- tests/plugin-config.spec.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/parser.ts b/lib/parser.ts index e2f069e..e5e96f7 100644 --- a/lib/parser.ts +++ b/lib/parser.ts @@ -46,8 +46,8 @@ export interface ParsedRoute { export default async function parse(specOrPath: string | OpenAPIObject): Promise { const spec = await bundleSpecification(specOrPath); //await dereference(specOrPath); - if (!spec?.openapi?.startsWith("3.0")) { - throw new Error("The 'specification' parameter must contain a valid version 3.0.x specification"); + if (!spec?.openapi?.startsWith("3.")) { + throw new Error("The 'specification' parameter must contain a valid version 3.x specification"); } const $refs = await $RefParser.resolve(spec); diff --git a/tests/plugin-config.spec.ts b/tests/plugin-config.spec.ts index f94afbd..3eda61e 100644 --- a/tests/plugin-config.spec.ts +++ b/tests/plugin-config.spec.ts @@ -40,7 +40,7 @@ describe("Config", () => { await expect(fastify.ready()) .rejects.toHaveProperty( "message", - "The 'specification' parameter must contain a valid version 3.0.x specification" + "The 'specification' parameter must contain a valid version 3.x specification" ); }); @@ -78,4 +78,17 @@ describe("Config", () => { await expect(fastify.ready()) .resolves.toBe(fastify); }); + + test("should load V3.1.0 definition with no error", async () => { + const spec310 = JSON.parse(JSON.stringify(PETSTORE_SPEC)); + spec310["openapi"] = "3.1.0"; + + const fastify = createFastify({ + specification: spec310, + controller: CONTROLLER_FILE + }); + + await expect(fastify.ready()) + .resolves.toBe(fastify); + }); });