Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSchemaName not applied to imports #213

Open
deckchairlabs opened this issue Feb 29, 2024 · 1 comment · May be fixed by #215
Open

getSchemaName not applied to imports #213

deckchairlabs opened this issue Feb 29, 2024 · 1 comment · May be fixed by #215
Labels
breaking v4 This issue introduces a breaking change that would go into v4 enhancement New feature or request good first issue Good for newcomers

Comments

@deckchairlabs
Copy link

Bug description

When using the generate api providing a custom getSchemaName the named imports for other schemas don't use the custom getSchamaName

const schema = generate({
  sourceText,
  inputOutputMappings: mappings,
  getSchemaName(identifier) {
    // Return the type name as is with Schema suffix eg. TypeNameSchema
    return identifier + "Schema";
  },
});

Input

import type { AliasTypeSummary } from "./AliasTypeSummary.ts";
import type { Entity } from "./Entity.ts";
export type Alias = {
  Id?: number;
  AliasFirstName?: string;
  AliasLastName?: string;
  AliasType?: AliasTypeSummary;
  Constituent?: Entity;
  EditIndicator?: boolean;
  UpdatedDateTime?: string;
  CreatedDateTime?: string;
  CreateLocation?: string;
  CreatedBy?: string;
  UpdatedBy?: string;
};

Expected output

// Generated by ts-to-zod
import { z } from "zod";

import { aliasTypeSummarySchema } from "./AliasTypeSummary.schema.ts";
import { entitySchema } from "./Entity.schema.ts";

export const AliasSchema = z.object({
  Id: z.number().optional(),
  AliasFirstName: z.string().optional(),
  AliasLastName: z.string().optional(),
  AliasType: aliasTypeSummarySchema.optional(),
  Constituent: entitySchema.optional(),
  EditIndicator: z.boolean().optional(),
  UpdatedDateTime: z.string().optional(),
  CreatedDateTime: z.string().optional(),
  CreateLocation: z.string().optional(),
  CreatedBy: z.string().optional(),
  UpdatedBy: z.string().optional(),
});

Actual output

// Generated by ts-to-zod
import { z } from "zod";

import { AliasTypeSummarySchema } from "./AliasTypeSummary.schema.ts";
import { EntitySchema } from "./Entity.schema.ts";

export const AliasSchema = z.object({
  Id: z.number().optional(),
  AliasFirstName: z.string().optional(),
  AliasLastName: z.string().optional(),
  AliasType: AliasTypeSummarySchema.optional(),
  Constituent: EntitySchema.optional(),
  EditIndicator: z.boolean().optional(),
  UpdatedDateTime: z.string().optional(),
  CreatedDateTime: z.string().optional(),
  CreateLocation: z.string().optional(),
  CreatedBy: z.string().optional(),
  UpdatedBy: z.string().optional(),
});

Versions

  • Typescript: v5.3.3
  • Zod: v3.22.4
@deckchairlabs
Copy link
Author

Ah. I've just realised the inputOuputMappings accepts the same option, would be nice if this could default to the passed option in generate

@tvillaren tvillaren added enhancement New feature or request good first issue Good for newcomers labels Feb 29, 2024
@deckchairlabs deckchairlabs linked a pull request Mar 1, 2024 that will close this issue
@tvillaren tvillaren added the breaking v4 This issue introduces a breaking change that would go into v4 label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking v4 This issue introduces a breaking change that would go into v4 enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants