Skip to content

Commit

Permalink
fix type definition for fastify.swagger({ yaml: true }) (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwickern authored Sep 23, 2022
1 parent a2e08a6 commit 5f33c7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 4 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ declare module 'openapi-types' {

declare module 'fastify' {
interface FastifyInstance {
swagger: (
opts?: {
yaml?: boolean;
}
) => OpenAPI.Document;
swagger:
((opts?: { yaml?: false }) => OpenAPI.Document) &
((opts: { yaml: true }) => string) &
((opts: { yaml: boolean }) => OpenAPI.Document | string);

swaggerCSP: {
script: string[];
Expand Down
7 changes: 7 additions & 0 deletions test/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import fastifySwagger, {
FastifySwaggerUiHooksOptions, JSONObject,
} from "../.."
import { minimalOpenApiV3Document } from './minimal-openapiV3-document';
import { expectType } from "tsd";
import { OpenAPI } from "openapi-types";

const app = fastify();
const uiConfig: FastifySwaggerUiConfigOptions = {
Expand Down Expand Up @@ -227,3 +229,8 @@ app.register(fastifySwagger, {
.ready((err) => {
app.swagger();
})

expectType<OpenAPI.Document>(app.swagger())
expectType<OpenAPI.Document>(app.swagger({ yaml: false }))
expectType<string>(app.swagger({ yaml: true }))
expectType<OpenAPI.Document | string>(app.swagger({ yaml: Boolean(process.env.YAML) }))

0 comments on commit 5f33c7d

Please sign in to comment.