Skip to content

Commit

Permalink
Add jsDoc parser in example
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed Oct 25, 2021
1 parent 29571ed commit d779fb7
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
39 changes: 39 additions & 0 deletions example/heros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,42 @@ export type GetSupermanSkill = (
skillName: string,
withKryptonite?: boolean
) => string;

export interface HeroContact {
/**
* The email of the hero.
*
* @format email
*/
email: string;

/**
* The name of the hero.
*
* @minLength 2
* @maxLength 50
*/
name: string;

/**
* The phone number of the hero.
*
* @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
*/
phoneNumber: string;

/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower?: boolean;

/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: number;
}
57 changes: 55 additions & 2 deletions example/heros.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export const enemySchema = z.object({
inPrison: z.boolean(),
});

export const supermanEnemySchema = enemySchema;

export const supermanSchema = z.object({
name: z.union([
z.literal("superman"),
Expand Down Expand Up @@ -51,15 +49,33 @@ export const killSupermanSchema = z
.returns(z.promise(z.boolean()));

export const withDefaultsSchema = z.object({
/**
* @default 42
*/
theAnswerToTheUltimateQuestionOfLife: z.number().default(42),
/**
* @default false
*/
isVulnerable: z.boolean().default(false),
/**
* @default clark
*/
name: z
.union([z.literal("clark"), z.literal("superman"), z.literal("kal-l")])
.default("clark"),
/**
* @default The Answer to the Ultimate Question of Life
*/
theMeaningOf42: z
.string()
.default("The Answer to the Ultimate Question of Life"),
/**
* @default ""
*/
emptyString: z.string().optional().default(""),
/**
* @default "true"
*/
booleanAsString: z.string().default("true"),
});

Expand All @@ -77,6 +93,43 @@ export const getSupermanSkillSchema = z
.args(z.string(), z.boolean().optional())
.returns(z.string());

export const heroContactSchema = z.object({
/**
* The email of the hero.
*
* @format email
*/
email: z.string().email(),
/**
* The name of the hero.
*
* @minLength 2
* @maxLength 50
*/
name: z.string().min(2).max(50),
/**
* The phone number of the hero.
*
* @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
*/
phoneNumber: z.string().regex(/^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$/),
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower: z.boolean().optional().default(true),
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: z.number().min(0).max(500),
});

export const supermanEnemySchema = supermanSchema.shape.enemies.valueSchema;

export const supermanNameSchema = supermanSchema.shape.name;

export const supermanInvinciblePowerSchema =
Expand Down

0 comments on commit d779fb7

Please sign in to comment.