1
1
import path from "node:path" ;
2
2
import getPackageMetadata from "@omer-x/package-metadata" ;
3
- import clearUnusedSchemas from "./clearUnusedSchemas" ;
3
+ import clearUnusedSchemasFunction from "./clearUnusedSchemas" ;
4
4
import { filterDirectoryItems , getDirectoryItems } from "./dir" ;
5
5
import isDocumentedRoute from "./isDocumentedRoute" ;
6
6
import { findAppFolderPath , getRouteExports } from "./next" ;
@@ -20,6 +20,7 @@ type GeneratorOptions = {
20
20
servers ?: ServerObject [ ] ,
21
21
security ?: OpenApiDocument [ "security" ] ,
22
22
securitySchemes ?: ComponentsObject [ "securitySchemes" ] ,
23
+ clearUnusedSchemas ?: boolean ,
23
24
} ;
24
25
25
26
export default async function generateOpenApiSpec ( schemas : Record < string , ZodType > , {
@@ -30,6 +31,7 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
30
31
servers,
31
32
security,
32
33
securitySchemes,
34
+ clearUnusedSchemas : clearUnusedSchemasOption = true ,
33
35
} : GeneratorOptions = { } ) {
34
36
const verifiedOptions = verifyOptions ( includeOption , excludeOption ) ;
35
37
const appFolderPath = await findAppFolderPath ( ) ;
@@ -69,7 +71,7 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
69
71
version : metadata . version ,
70
72
} ,
71
73
servers,
72
- ...clearUnusedSchemas ( pathsAndComponents ) ,
74
+ ...( clearUnusedSchemasOption ? clearUnusedSchemasFunction ( pathsAndComponents ) : pathsAndComponents ) ,
73
75
security,
74
76
tags : [ ] ,
75
77
} as Omit < OpenApiDocument , "components" > & Required < Pick < OpenApiDocument , "components" > > ;
0 commit comments