From 40e7f99c296c21c3c6c443130924cd7abfc3dcbf Mon Sep 17 00:00:00 2001 From: radzom Date: Tue, 8 Dec 2020 17:21:39 +0100 Subject: [PATCH] Fix type of StaticDocumentSpec.document --- index.d.ts | 5 +++-- package.json | 1 + test/types/http2-types.test.ts | 3 ++- test/types/imports.test.ts | 3 ++- test/types/minimal-openapiV3-document.ts | 11 +++++++++++ test/types/types.test.ts | 5 +++-- 6 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 test/types/minimal-openapiV3-document.ts diff --git a/index.d.ts b/index.d.ts index 34f9eb1c..6299c2d9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,6 @@ import { FastifyPlugin } from 'fastify'; import * as SwaggerSchema from 'swagger-schema-official'; +import { OpenAPIV2, OpenAPIV3 } from 'openapi-types'; declare module 'fastify' { interface FastifyInstance { @@ -68,7 +69,7 @@ export interface StaticPathSpec { } export interface StaticDocumentSpec { - document: string; + document: OpenAPIV2.Document | OpenAPIV3.Document; } export interface FastifyStaticSwaggerOptions extends FastifySwaggerOptions { @@ -76,4 +77,4 @@ export interface FastifyStaticSwaggerOptions extends FastifySwaggerOptions { specification: StaticPathSpec | StaticDocumentSpec; } -export default fastifySwagger; \ No newline at end of file +export default fastifySwagger; diff --git a/package.json b/package.json index 3d396184..3221140f 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "fs-extra": "^9.0.0", "joi": "^14.3.1", "joi-to-json-schema": "^5.1.0", + "openapi-types": "^7.0.1", "pre-commit": "^1.2.2", "standard": "^16.0.1", "swagger-parser": "^10.0.2", diff --git a/test/types/http2-types.test.ts b/test/types/http2-types.test.ts index 813676f2..e6462d4e 100644 --- a/test/types/http2-types.test.ts +++ b/test/types/http2-types.test.ts @@ -1,5 +1,6 @@ import fastify from 'fastify'; import fastifySwagger from '../..'; +import { minimalOpenApiV3Document } from './minimal-openapiV3-document'; const app = fastify({ http2: true @@ -11,7 +12,7 @@ app.register(fastifySwagger, { transform: (schema : any) => schema }); app.register(fastifySwagger, { mode: 'static', specification: { - document: 'path' + document: minimalOpenApiV3Document }, routePrefix: '/documentation', exposeRoute: true, diff --git a/test/types/imports.test.ts b/test/types/imports.test.ts index 37b22491..28ee3c8f 100644 --- a/test/types/imports.test.ts +++ b/test/types/imports.test.ts @@ -2,12 +2,13 @@ import fastify from "fastify"; import swaggerDefault, { fastifySwagger, SwaggerOptions } from "../.."; import * as fastifySwaggerStar from "../.."; +import { minimalOpenApiV3Document } from './minimal-openapiV3-document'; const app = fastify(); const fastifySwaggerOptions: SwaggerOptions = { mode: "static", specification: { - document: "path", + document: minimalOpenApiV3Document, }, routePrefix: "/documentation", exposeRoute: true, diff --git a/test/types/minimal-openapiV3-document.ts b/test/types/minimal-openapiV3-document.ts new file mode 100644 index 00000000..dd94e296 --- /dev/null +++ b/test/types/minimal-openapiV3-document.ts @@ -0,0 +1,11 @@ +import { OpenAPIV3 } from 'openapi-types' + +export const minimalOpenApiV3Document: OpenAPIV3.Document = { + openapi: '3.0.0', + info: { + "version": "1.0.0", + "title": "Test OpenApiv3 specification", + }, + "paths": { + } +} diff --git a/test/types/types.test.ts b/test/types/types.test.ts index 4af34522..8b3a9905 100644 --- a/test/types/types.test.ts +++ b/test/types/types.test.ts @@ -1,5 +1,6 @@ import fastify from 'fastify'; import fastifySwagger, { SwaggerOptions } from '../..'; +import { minimalOpenApiV3Document } from './minimal-openapiV3-document'; const app = fastify(); @@ -9,7 +10,7 @@ app.register(fastifySwagger, { transform: (schema : any) => schema }); app.register(fastifySwagger, { mode: 'static', specification: { - document: 'path' + document: minimalOpenApiV3Document }, routePrefix: '/documentation', exposeRoute: true, @@ -18,7 +19,7 @@ app.register(fastifySwagger, { const fastifySwaggerOptions: SwaggerOptions = { mode: 'static', specification: { - document: 'path' + document: minimalOpenApiV3Document }, routePrefix: '/documentation', exposeRoute: true,