11import path from "node:path" ;
22import getPackageMetadata from "@omer-x/package-metadata" ;
3- import clearUnusedSchemas from "./clearUnusedSchemas" ;
3+ import clearUnusedSchemasFunction from "./clearUnusedSchemas" ;
44import { filterDirectoryItems , getDirectoryItems } from "./dir" ;
55import isDocumentedRoute from "./isDocumentedRoute" ;
66import { findAppFolderPath , getRouteExports } from "./next" ;
@@ -20,6 +20,7 @@ type GeneratorOptions = {
2020 servers ?: ServerObject [ ] ,
2121 security ?: OpenApiDocument [ "security" ] ,
2222 securitySchemes ?: ComponentsObject [ "securitySchemes" ] ,
23+ clearUnusedSchemas ?: boolean ,
2324} ;
2425
2526export default async function generateOpenApiSpec ( schemas : Record < string , ZodType > , {
@@ -30,6 +31,7 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
3031 servers,
3132 security,
3233 securitySchemes,
34+ clearUnusedSchemas : clearUnusedSchemasOption = true ,
3335} : GeneratorOptions = { } ) {
3436 const verifiedOptions = verifyOptions ( includeOption , excludeOption ) ;
3537 const appFolderPath = await findAppFolderPath ( ) ;
@@ -69,7 +71,7 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
6971 version : metadata . version ,
7072 } ,
7173 servers,
72- ...clearUnusedSchemas ( pathsAndComponents ) ,
74+ ...( clearUnusedSchemasOption ? clearUnusedSchemasFunction ( pathsAndComponents ) : pathsAndComponents ) ,
7375 security,
7476 tags : [ ] ,
7577 } as Omit < OpenApiDocument , "components" > & Required < Pick < OpenApiDocument , "components" > > ;
0 commit comments