Skip to content

Commit

Permalink
Test bigint type cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Aug 14, 2024
1 parent 776e1a0 commit fe9e637
Show file tree
Hide file tree
Showing 21 changed files with 698 additions and 37 deletions.
13 changes: 11 additions & 2 deletions packages/sdk/src/generates/internal/SdkHttpNamespaceProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,17 @@ export namespace SdkHttpNamespaceProgrammer {
undefined,
[
ts.factory.createBinaryExpression(
ts.factory.createIdentifier(
g.path.find((p) => p.field === name)!.name,
ts.factory.createCallChain(
ts.factory.createPropertyAccessChain(
ts.factory.createIdentifier(
g.path.find((p) => p.field === name)!.name,
),
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
"toString",
),
undefined,
undefined,
[],
),
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
ts.factory.createStringLiteral("null"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,17 @@ export namespace SdkWebSocketNamespaceProgrammer {
undefined,
[
ts.factory.createBinaryExpression(
ts.factory.createIdentifier(
pathParams.find((p) => p.field === name)!.name,
ts.factory.createCallChain(
ts.factory.createPropertyAccessChain(
ts.factory.createIdentifier(
pathParams.find((p) => p.field === name)!.name,
),
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
"toString",
),
undefined,
undefined,
[],
),
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
ts.factory.createStringLiteral("null"),
Expand Down
15 changes: 8 additions & 7 deletions test/features/headers/src/api/functional/headers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,25 @@ export async function emplace(
}
export namespace emplace {
export type Headers = Resolved<IHeaders>;
export type Output = Primitive<IHeaders>;
export type Output = Resolved<IHeaders>;

export const METADATA = {
method: "PATCH",
path: "/headers/:section",
request: null,
response: {
type: "application/json",
type: "application/x-www-form-urlencoded",
encrypted: false,
},
status: 200,
parseQuery: typia.http.createAssertQuery<IHeaders>(),
} as const;

export const path = (section: string) =>
`/headers/${encodeURIComponent(section ?? "null")}`;
`/headers/${encodeURIComponent(section?.toString() ?? "null")}`;
export const random = (
g?: Partial<typia.IRandomGenerator>,
): Resolved<Primitive<IHeaders>> => typia.random<Primitive<IHeaders>>(g);
): Resolved<Resolved<IHeaders>> => typia.random<Resolved<IHeaders>>(g);
export const simulate = (
connection: IConnection<emplace.Headers>,
section: string,
Expand All @@ -67,7 +68,7 @@ export namespace emplace {
method: METADATA.method,
host: connection.host,
path: path(section),
contentType: "application/json",
contentType: "application/x-www-form-urlencoded",
});
assert.param("section")(() => typia.assert(section));
return random(
Expand Down Expand Up @@ -132,7 +133,7 @@ export namespace store {
} as const;

export const path = (section: string) =>
`/headers/${encodeURIComponent(section ?? "null")}`;
`/headers/${encodeURIComponent(section?.toString() ?? "null")}`;
export const random = (
g?: Partial<typia.IRandomGenerator>,
): Resolved<Primitive<IBbsArticle>> =>
Expand Down Expand Up @@ -212,7 +213,7 @@ export namespace update {
} as const;

export const path = (section: string, id: string & Format<"uuid">) =>
`/headers/${encodeURIComponent(section ?? "null")}/${encodeURIComponent(id ?? "null")}`;
`/headers/${encodeURIComponent(section?.toString() ?? "null")}/${encodeURIComponent(id?.toString() ?? "null")}`;
export const random = (g?: Partial<typia.IRandomGenerator>): Resolved<void> =>
typia.random<void>(g);
export const simulate = (
Expand Down
1 change: 1 addition & 0 deletions test/features/headers/src/api/structures/IHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface IHeaders {
"x-category": "x" | "y" | "z";
"x-memo"?: string;
"x-bigint": bigint;

/**
* @default Samchon
Expand Down
2 changes: 1 addition & 1 deletion test/features/headers/src/controllers/HeadersController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IHeaders } from "@api/lib/structures/IHeaders";

@Controller("headers/:section")
export class HeadersController {
@core.TypedRoute.Patch()
@core.TypedQuery.Patch()
public emplace(
@core.TypedHeaders() headers: IHeaders,
@Param("section") section: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Primitive } from "@nestia/fetcher";
import type { Resolved } from "@nestia/fetcher";
import typia from "typia";

import api from "../../../../api";
import type { IHeaders } from "../../../../api/structures/IHeaders";

export const test_api_headers_emplace = async (connection: api.IConnection) => {
const output: Primitive<IHeaders> = await api.functional.headers.emplace(
const output: Resolved<IHeaders> = await api.functional.headers.emplace(
{
...connection,
headers: {
Expand Down
6 changes: 5 additions & 1 deletion test/features/headers/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"responses": {
"200": {
"content": {
"application/json": {
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "#/components/schemas/IHeaders"
}
Expand Down Expand Up @@ -203,6 +203,9 @@
"x-memo": {
"type": "string"
},
"x-bigint": {
"type": "integer"
},
"x-nAme": {
"type": "string"
},
Expand All @@ -221,6 +224,7 @@
},
"required": [
"x-category",
"x-bigint",
"x-values",
"x-fLags"
]
Expand Down
2 changes: 1 addition & 1 deletion test/features/param/src/api/functional/calculate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export namespace connect {
export type Listener = ICalculator;

export const path = (id: string & Format<"uuid">) =>
`/calculate/${encodeURIComponent(id ?? "null")}`;
`/calculate/${encodeURIComponent(id?.toString() ?? "null")}`;
}
63 changes: 53 additions & 10 deletions test/features/param/src/api/functional/param/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export namespace composite {
} as const;

export const path = (value: string, value2: string) =>
`/param/${encodeURIComponent(value ?? "null")}/composite/${encodeURIComponent(value2 ?? "null")}`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/composite/${encodeURIComponent(value2?.toString() ?? "null")}`;
}

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ export namespace boolean {
} as const;

export const path = (value: false | true) =>
`/param/${encodeURIComponent(value ?? "null")}/boolean`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/boolean`;
}

/**
Expand Down Expand Up @@ -147,7 +147,50 @@ export namespace number {
} as const;

export const path = (value: number) =>
`/param/${encodeURIComponent(value ?? "null")}/number`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/number`;
}

/**
* The bigint.
* @controller TypedParamController.bigint
* @path GET /param/:value/bigint
* @nestia Generated by Nestia - https://github.com/samchon/nestia
*/
export async function bigint(
connection: IConnection,
value: bigint,
): Promise<bigint.Output> {
return PlainFetcher.fetch(
{
...connection,
headers: {
...connection.headers,
"Content-Type": "application/json",
},
},
{
...bigint.METADATA,
template: bigint.METADATA.path,
path: bigint.path(value),
},
);
}
export namespace bigint {
export type Output = Primitive<number>;

export const METADATA = {
method: "GET",
path: "/param/:value/bigint",
request: null,
response: {
type: "application/json",
encrypted: false,
},
status: 200,
} as const;

export const path = (value: bigint) =>
`/param/${encodeURIComponent(value?.toString() ?? "null")}/bigint`;
}

/**
Expand Down Expand Up @@ -190,7 +233,7 @@ export namespace string {
} as const;

export const path = (value: string) =>
`/param/${encodeURIComponent(value ?? "null")}/string`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/string`;
}

/**
Expand Down Expand Up @@ -232,7 +275,7 @@ export namespace nullable {
} as const;

export const path = (value: null | string) =>
`/param/${encodeURIComponent(value ?? "null")}/nullable`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/nullable`;
}

/**
Expand Down Expand Up @@ -274,7 +317,7 @@ export namespace literal {
} as const;

export const path = (value: "A" | "B" | "C") =>
`/param/${encodeURIComponent(value ?? "null")}/literal`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/literal`;
}

/**
Expand Down Expand Up @@ -316,7 +359,7 @@ export namespace uuid {
} as const;

export const path = (value: string & Format<"uuid">) =>
`/param/${encodeURIComponent(value ?? "null")}/uuid`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/uuid`;
}

/**
Expand Down Expand Up @@ -358,7 +401,7 @@ export namespace date {
} as const;

export const path = (value: string & Format<"date">) =>
`/param/${encodeURIComponent(value ?? "null")}/date`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/date`;
}

/**
Expand Down Expand Up @@ -400,7 +443,7 @@ export namespace uuid_nullable {
} as const;

export const path = (value: null | (string & Format<"uuid">)) =>
`/param/${encodeURIComponent(value ?? "null")}/uuid_nullable`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/uuid_nullable`;
}

/**
Expand Down Expand Up @@ -442,5 +485,5 @@ export namespace date_nullable {
} as const;

export const path = (value: null | (string & Format<"date">)) =>
`/param/${encodeURIComponent(value ?? "null")}/date_nullable`;
`/param/${encodeURIComponent(value?.toString() ?? "null")}/date_nullable`;
}
3 changes: 0 additions & 3 deletions test/features/param/src/controllers/CalculateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export class CalculateController {
@core.WebSocketRoute.Driver()
driver: Driver<IListener>,
): Promise<void> {
console.log({
id,
});
await adaptor.accept({
getId: () => id,
plus: (x, y) => {
Expand Down
26 changes: 20 additions & 6 deletions test/features/param/src/controllers/TypedParamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { tags } from "typia";
export class TypedParamController {
/**
* Composite path parameters.
*
*
* @param value The first value.
* The first string value.
* @param value2 The second value.
Expand Down Expand Up @@ -39,14 +39,28 @@ export class TypedParamController {
@core.TypedRoute.Get(":value/number")
public number(
/**
* Description in the parameter.
*/
@core.TypedParam("value")
value: number
* Description in the parameter.
*/
@core.TypedParam("value")
value: number,
): number {
return value;
}

/**
* The bigint.
*/
@core.TypedRoute.Get(":value/bigint")
public bigint(
/**
* Description in the parameter.
*/
@core.TypedParam("value")
value: bigint,
): number {
return Number(value);
}

/**
* The string.
*/
Expand All @@ -56,7 +70,7 @@ export class TypedParamController {
* @title Yaho
* @description Yoohoo
*/
@core.TypedParam("value") value: string
@core.TypedParam("value") value: string,
): string {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Primitive } from "@nestia/fetcher";
import typia from "typia";

import api from "../../../../api";

export const test_api_param_bigint = async (connection: api.IConnection) => {
const output: Primitive<number> = await api.functional.param.bigint(
connection,
typia.random<bigint>(),
);
typia.assert(output);
};
21 changes: 21 additions & 0 deletions test/features/param/src/test/features/api/test_api_param_bigint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TestValidator } from "@nestia/e2e";
import typia from "typia";

import api from "@api";

export const test_api_param_number = async (
connection: api.IConnection,
): Promise<void> => {
const value: number = await api.functional.param.bigint(
connection,
BigInt(1),
);
typia.assert(value);

await TestValidator.httpError("boolean")(400)(() =>
api.functional.param.bigint(connection, true as any),
);
await TestValidator.httpError("string")(400)(() =>
api.functional.param.bigint(connection, "string" as any),
);
};
Loading

0 comments on commit fe9e637

Please sign in to comment.