@@ -4,7 +4,7 @@ import type { NodePath } from "@babel/traverse";
44import * as t from "@babel/types" ;
55
66import { traverse } from "../../shared/babel-traverse.js" ;
7- import { parseTypeScriptFile } from "../../shared/utils.js" ;
7+ import { extractInternalFlagFromComments , parseTypeScriptFile } from "../../shared/utils.js" ;
88import { logger } from "../../shared/logger.js" ;
99import { SymbolResolver } from "../../shared/symbol-resolver.js" ;
1010import { DrizzleZodProcessor } from "./drizzle-zod-processor.js" ;
@@ -78,6 +78,8 @@ export class ZodSchemaConverter {
7878 /** Schema variable names whose component name was overridden via .meta({ id }). These must
7979 * NOT be copied back under the original variable name in the OpenAPI components object. */
8080 metaIdSchemaNames : Set < string > = new Set ( ) ;
81+ /** Schema variable names marked @internal — excluded from components/schemas output. */
82+ internalSchemaNames : Set < string > = new Set ( ) ;
8183 // Current processing context (set during file processing)
8284 currentFilePath ?: string ;
8385 currentAST ?: t . File ;
@@ -2272,7 +2274,13 @@ export class ZodSchemaConverter {
22722274 * Get all processed Zod schemas
22732275 */
22742276 getProcessedSchemas ( ) : Record < string , OpenApiSchema > {
2275- return this . zodSchemas ;
2277+ const result : Record < string , OpenApiSchema > = { } ;
2278+ for ( const [ name , schema ] of Object . entries ( this . zodSchemas ) ) {
2279+ if ( ! this . internalSchemaNames . has ( name ) ) {
2280+ result [ name ] = schema ;
2281+ }
2282+ }
2283+ return result ;
22762284 }
22772285
22782286 /**
@@ -2346,6 +2354,15 @@ export class ZodSchemaConverter {
23462354
23472355 // Check if is Zod schema
23482356 if ( this . isZodSchema ( declaration . init ) ) {
2357+ const decl = path . node . declaration ;
2358+ const allComments = [
2359+ ...( path . node . leadingComments ?? [ ] ) ,
2360+ ...( decl ?. leadingComments ?? [ ] ) ,
2361+ ...( declaration . leadingComments ?? [ ] ) ,
2362+ ] ;
2363+ if ( extractInternalFlagFromComments ( allComments ) ) {
2364+ this . internalSchemaNames . add ( schemaName ) ;
2365+ }
23492366 if ( ! this . getStoredSchema ( schemaName ) ) {
23502367 logger . debug ( `Pre-processing Zod schema: ${ schemaName } ` ) ;
23512368 this . processingSchemas . add ( schemaName ) ;
@@ -2371,6 +2388,13 @@ export class ZodSchemaConverter {
23712388 if ( t . isIdentifier ( declaration . id ) && declaration . init ) {
23722389 const schemaName = declaration . id . name ;
23732390 if ( this . isZodSchema ( declaration . init ) ) {
2391+ const allComments = [
2392+ ...( path . node . leadingComments ?? [ ] ) ,
2393+ ...( declaration . leadingComments ?? [ ] ) ,
2394+ ] ;
2395+ if ( extractInternalFlagFromComments ( allComments ) ) {
2396+ this . internalSchemaNames . add ( schemaName ) ;
2397+ }
23742398 if ( ! this . getStoredSchema ( schemaName ) && ! this . processingSchemas . has ( schemaName ) ) {
23752399 logger . debug ( `Pre-processing Zod schema: ${ schemaName } ` ) ;
23762400 this . processingSchemas . add ( schemaName ) ;
0 commit comments