diff --git a/index.d.ts b/index.d.ts index f4d7beda..8dc927ce 100644 --- a/index.d.ts +++ b/index.d.ts @@ -58,19 +58,24 @@ declare module 'fastify' { } } +type SwaggerDocumentObject = { + swaggerObject: Partial; +} | { + openapiObject: Partial; +} + type SwaggerTransform = ({ schema, url, route, - swaggerObject, - openapiObject, + ...documentObject }: { schema: S; url: string; route: RouteOptions; - swaggerObject: Partial; - openapiObject: Partial; -}) => { schema: FastifySchema; url: string } +} & SwaggerDocumentObject) => { schema: FastifySchema; url: string } + +type SwaggerTransformObject = (documentObject: SwaggerDocumentObject) => Partial | Partial; type FastifySwagger = FastifyPluginCallback @@ -147,10 +152,7 @@ declare namespace fastifySwagger { /** * custom function to transform the openapi or swagger object before it is rendered */ - transformObject?: ({ swaggerObject, openapiObject }: { - swaggerObject: Partial; - openapiObject: Partial; - }) => Partial | Partial; + transformObject?: SwaggerTransformObject; refResolver?: { /** Clone the input schema without changing it. Default to `false`. */ diff --git a/test/types/types.test.ts b/test/types/types.test.ts index cc914783..85393bf4 100644 --- a/test/types/types.test.ts +++ b/test/types/types.test.ts @@ -220,16 +220,12 @@ app.get( schema, url, route, - swaggerObject, - openapiObject, + ...documentObject }) => { schema satisfies FastifySchema; url satisfies string; route satisfies RouteOptions; - swaggerObject satisfies Partial; - openapiObject satisfies Partial< - OpenAPIV3.Document | OpenAPIV3_1.Document - >; + documentObject satisfies { swaggerObject: Partial } | { openapiObject: Partial }; return { schema, url }; }, },