Skip to content

Commit

Permalink
Restore issue testing
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Oct 4, 2023
1 parent 143c439 commit a0d85e1
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
bin/
issues/
lib/
measure/
node_modules/
/issues/

packages/typescript-json/src/
package-lock.json
Expand Down
13 changes: 13 additions & 0 deletions test/issues/811.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import typia, { tags } from "typia";

interface UpdateUserDto {
email: string & tags.Format<"email"> & tags.MaxLength<20>;
dateOfBirth: string & tags.Format<"date">;
}

console.log(
typia.validateEquals<UpdateUserDto>({
dateOfBirth: "2023-11-10",
email: "123@gmail.com",
}),
);
4 changes: 4 additions & 0 deletions test/issues/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import typia, { IJsonApplication } from "typia";

const app = typia.json.application<[IJsonApplication]>();
console.log(Object.keys(app.components.schemas ?? {}));
5 changes: 5 additions & 0 deletions test/issues/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import typia from "typia";

import { TypeTagDefault } from "../structures/TypeTagDefault";

typia.createIs<TypeTagDefault>();
28 changes: 28 additions & 0 deletions test/issues/nullable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import typia, { tags } from "typia";

interface CreditCase {
id: number & tags.Type<"uint32">;
company_name: null | string;
email: (string & tags.Format<"email">) | null;
firstname: null | string;
lastname: null | string;
mobile_number: null | string;
phone_number: null | string;

created_at: Date;
updated_at: Date;
}

const stringify = typia.json.createAssertStringify<CreditCase>();
const str: string = stringify({
id: 1,
company_name: null,
email: null,
firstname: null,
lastname: null,
mobile_number: null,
phone_number: null,
created_at: new Date(),
updated_at: new Date(),
});
console.log(str);
19 changes: 19 additions & 0 deletions test/issues/object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import typia from "typia";

interface Something {
required: string;
optional?: number;
undefindable: boolean | undefined;
both?: string | undefined;
nullable: Something | null;
}

const app = typia.metadata<[Something]>();
console.log(
app.collection.objects[0]?.properties.map((p) => ({
name: p.key.constants[0]?.values[0],
optional: p.value.optional,
required: p.value.required,
nullable: p.value.nullable,
})),
);
16 changes: 16 additions & 0 deletions test/issues/partial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import typia from "typia";

interface ISomething {
value: number;
}
type P = Partial<ISomething> & { next: string };

const app = typia.metadata<[P]>();
console.log(
app.collection.objects[0]?.properties.map((p) => ({
name: p.key.constants[0]?.values[0],
optional: p.value.optional,
required: p.value.required,
nullable: p.value.nullable,
})),
);
12 changes: 12 additions & 0 deletions test/issues/required.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import typia from "typia";

interface ISomething {
value?: number;
}
type P = Required<ISomething>;

const value = typia.metadata<[P]>().collection.objects[0]?.properties[0]?.value;
console.log({
optional: value?.optional,
required: value?.required,
});
20 changes: 20 additions & 0 deletions test/issues/swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import typia, { IJsonApplication, IJsonComponents } from "typia";

interface IQuery {
required: string;
nonRequired: string | undefined;
optional?: string;
none?: string | undefined;
}

const app: IJsonApplication = typia.json.application<[Partial<IQuery>]>();
const query: IJsonComponents.IObject = app.components.schemas
?.PartialIQuery as IJsonComponents.IObject;

console.log(
Object.entries(query.properties).map(([key, value]) => [
key,
value["x-typia-required"],
value["x-typia-optional"],
]),
);

0 comments on commit a0d85e1

Please sign in to comment.