Skip to content

Commit 5f33c7d

Browse files
authored
fix type definition for fastify.swagger({ yaml: true }) (#670)
1 parent a2e08a6 commit 5f33c7d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

index.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ declare module 'openapi-types' {
2020

2121
declare module 'fastify' {
2222
interface FastifyInstance {
23-
swagger: (
24-
opts?: {
25-
yaml?: boolean;
26-
}
27-
) => OpenAPI.Document;
23+
swagger:
24+
((opts?: { yaml?: false }) => OpenAPI.Document) &
25+
((opts: { yaml: true }) => string) &
26+
((opts: { yaml: boolean }) => OpenAPI.Document | string);
2827

2928
swaggerCSP: {
3029
script: string[];

test/types/types.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import fastifySwagger, {
66
FastifySwaggerUiHooksOptions, JSONObject,
77
} from "../.."
88
import { minimalOpenApiV3Document } from './minimal-openapiV3-document';
9+
import { expectType } from "tsd";
10+
import { OpenAPI } from "openapi-types";
911

1012
const app = fastify();
1113
const uiConfig: FastifySwaggerUiConfigOptions = {
@@ -227,3 +229,8 @@ app.register(fastifySwagger, {
227229
.ready((err) => {
228230
app.swagger();
229231
})
232+
233+
expectType<OpenAPI.Document>(app.swagger())
234+
expectType<OpenAPI.Document>(app.swagger({ yaml: false }))
235+
expectType<string>(app.swagger({ yaml: true }))
236+
expectType<OpenAPI.Document | string>(app.swagger({ yaml: Boolean(process.env.YAML) }))

0 commit comments

Comments
 (0)