Skip to content

Commit

Permalink
fix: add array to zod map
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorsoft committed Sep 25, 2024
1 parent 3610c16 commit a6257a5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libs/eventually-openapi/src/home/esml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ const ZOD2TYPE: { [K in z.ZodFirstPartyTypeKind]?: string } = {
[z.ZodFirstPartyTypeKind.ZodBoolean]: "boolean",
[z.ZodFirstPartyTypeKind.ZodDate]: "date",
[z.ZodFirstPartyTypeKind.ZodNativeEnum]: "string",
[z.ZodFirstPartyTypeKind.ZodEnum]: "string"
[z.ZodFirstPartyTypeKind.ZodEnum]: "string",
[z.ZodFirstPartyTypeKind.ZodArray]: "array"
};

const toField = (
name: string,
type: any,
optional: boolean,
model: Record<string, any>
): { name: string; type: string; optional: boolean } => {
): {
name: string;
type: string;
optional: boolean;
} => {
if (
type instanceof z.ZodString ||
type instanceof z.ZodNumber ||
Expand All @@ -26,7 +31,8 @@ const toField = (
type instanceof z.ZodNativeEnum ||
type instanceof z.ZodEnum ||
type instanceof z.ZodObject ||
type instanceof z.ZodRecord
type instanceof z.ZodRecord ||
type instanceof z.ZodArray
) {
if (type instanceof z.ZodOptional)
return toField(name, type._def.innerType, true, model);
Expand Down Expand Up @@ -108,7 +114,6 @@ export const esml = (): Record<string, any> => {
const schema = toSchema(m.schema, model);
if (schema) model[m.name] = { type: m.type, schema };
});

return {
[camelize(config.service)]: model
};
Expand Down

0 comments on commit a6257a5

Please sign in to comment.