diff --git a/demo/stl-api-gen/api/posts/create.ts b/demo/stl-api-gen/api/posts/create.ts index 620e2961..df135302 100644 --- a/demo/stl-api-gen/api/posts/create.ts +++ b/demo/stl-api-gen/api/posts/create.ts @@ -1,6 +1,6 @@ import { z } from "stainless"; -import { PostType as __symbol_PostType } from "./models"; +import { PostType as __symbol_PostType } from "./create"; export const Query: z.ZodTypeAny = z.object({ include: z.includes(z.lazy(() => __symbol_PostType), 3).optional() }); export const Body: z.ZodTypeAny = z.object({ body: z.string() }); export const PostType: z.ZodTypeAny = z.any(); -export const __postu32$api$posts: any = { query: z.lazy(() => Query), body: z.lazy(() => Body), response: z.lazy(() => PostType) }; +export const __postu32$api$posts: any = { query: z.lazy(() => Query), body: z.lazy(() => Body), response: z.lazy(() => __symbol_PostType) }; diff --git a/demo/stl-api-gen/api/posts/retrieve.ts b/demo/stl-api-gen/api/posts/retrieve.ts index 1d4a31e1..8f4e2d67 100644 --- a/demo/stl-api-gen/api/posts/retrieve.ts +++ b/demo/stl-api-gen/api/posts/retrieve.ts @@ -1,7 +1,7 @@ import { z } from "stainless"; -import { PostType as __symbol_PostType } from "./models"; +import { PostType as __symbol_PostType } from "./retrieve"; import * as __u46u46$u46u46$u46u46$libs$prismadbu46ts from "../../../libs/prismadb"; export const Query: z.ZodTypeAny = z.object({ include: z.includes(z.lazy(() => __symbol_PostType), 3).optional(), select: z.selects(z.lazy(() => __symbol_PostType), 3).optional() }); export const Path: z.ZodTypeAny = z.object({ post: z.string().prismaModelLoader(__u46u46$u46u46$u46u46$libs$prismadbu46ts.prisma.post) }); export const PostType: z.ZodTypeAny = z.any(); -export const __getu32$api$posts$u123postu125: any = { query: z.lazy(() => Query), path: z.lazy(() => Path), response: z.lazy(() => PostType) }; +export const __getu32$api$posts$u123postu125: any = { query: z.lazy(() => Query), path: z.lazy(() => Path), response: z.lazy(() => __symbol_PostType) }; diff --git a/packages/ts-to-zod/src/convertType.ts b/packages/ts-to-zod/src/convertType.ts index eea630cc..912a9e99 100644 --- a/packages/ts-to-zod/src/convertType.ts +++ b/packages/ts-to-zod/src/convertType.ts @@ -165,13 +165,23 @@ export class ConvertTypeContext extends SchemaGenContext { currentFilePath: string; isSymbolImported(symbol: tm.Symbol): boolean { - const symbolFileName: string = getDeclarationOrThrow(symbol) - .getSourceFile() - .getFilePath(); - return this.currentFilePath !== symbolFileName; + const declaration = getDeclarationOrThrow(symbol); + const symbolFileName: string = declaration.getSourceFile().getFilePath(); + return ( + this.currentFilePath !== symbolFileName || + isDeclarationImported(declaration) + ); } } +function isDeclarationImported(declaration: tm.Node): boolean { + return ( + declaration instanceof tm.ImportSpecifier || + declaration instanceof tm.ImportClause || + declaration instanceof tm.ImportDeclaration + ); +} + export interface ImportInfo { as?: string; /** @@ -381,12 +391,7 @@ function convertTypeofNode( if ( !declaration || - !( - isDeclarationExported(declaration) || - declaration instanceof tm.ImportSpecifier || - declaration instanceof tm.ImportClause || - declaration instanceof tm.ImportDeclaration - ) + !(isDeclarationExported(declaration) || isDeclarationImported(declaration)) ) { console.dir(declaration); ctx.addError(