Skip to content

Commit

Permalink
Merge pull request #1025 from samchon/features/recursive
Browse files Browse the repository at this point in the history
Fix `Record<string, string>` bug of `typia.json.application<"3.1">()` function.
  • Loading branch information
samchon authored Apr 12, 2024
2 parents 97dfef2 + e2bed50 commit 4cb9dec
Show file tree
Hide file tree
Showing 160 changed files with 29,738 additions and 18,916 deletions.
7 changes: 5 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ updates:
versioning-strategy: increase
open-pull-requests-limit: 25
allow:
- dependency-name: "@samchon/openapi"
- dependency-name: "ts-node"
- dependency-name: "typescript"
groups:
TypeScript:
Ecosystem:
- patterns:
- "@samchon/openapi"
- "ts-node"
- "typescript"
- package-ecosystem: "npm"
Expand All @@ -21,11 +23,12 @@ updates:
versioning-strategy: increase
open-pull-requests-limit: 25
allow:
- dependency-name: "@samchon/openapi"
- dependency-name: "ts-node"
- dependency-name: "ts-patch"
- dependency-name: "typescript"
groups:
TypeScript:
Ecosystem:
- patterns:
- "ts-node"
- "ts-patch"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-6.0.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-6.0.1.tgz"
}
}
5 changes: 5 additions & 0 deletions debug/features/record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import typia from "typia";

const app = typia.json.application<[Record<string, string>], "3.1">();

console.log(JSON.stringify(app, null, 2));
2 changes: 1 addition & 1 deletion debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"typescript": "^5.4.2"
},
"dependencies": {
"typia": "D:\\github\\samchon\\typia\\typia-6.0.0-dev.20240411.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-6.0.0.tgz"
}
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "D:\\github\\samchon\\typia\\typia-6.0.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-6.0.1.tgz"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "6.0.0",
"version": "6.0.1",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -65,7 +65,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"@samchon/openapi": "^0.1.2",
"@samchon/openapi": "^0.1.4",
"commander": "^10.0.0",
"comment-json": "^4.2.3",
"inquirer": "^8.2.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "6.0.0",
"version": "6.0.1",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -62,7 +62,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "6.0.0"
"typia": "6.0.1"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.5.0"
Expand Down
4 changes: 2 additions & 2 deletions src/programmers/internal/application_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const application_array =
generator: (value: Metadata) => Schema<Version>,
) =>
(array: MetadataArray): ArraySchema<Version>[] =>
application_plugin(
application_plugin<ArraySchema<Version>>(
{
type: "array",
items: generator(array.type.value),
} satisfies ArraySchema<Version>,
} as ArraySchema<Version>,
array.tags,
);

Expand Down
4 changes: 3 additions & 1 deletion src/programmers/internal/application_escaped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const application_escaped =
)
string.format = "date-time";
}
return is_one_of(output) ? output.oneOf : [output];
return is_one_of(output)
? (output.oneOf as OneOfSchema<Version>[])
: [output];
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/programmers/internal/application_v30_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const application_v30_schema =

// toJSON() METHOD
if (meta.escaped !== null)
application_escaped(application_v30_schema(false)(components)({}))(
application_escaped<"3.0">(application_v30_schema(false)(components)({}))(
meta.escaped,
).forEach(insert);

Expand All @@ -73,7 +73,7 @@ export const application_v30_schema =

// ARRAY
for (const array of meta.arrays)
application_array(application_v30_schema(false)(components)({}))(
application_array<"3.0">(application_v30_schema(false)(components)({}))(
array,
).forEach(insert);

Expand Down
6 changes: 6 additions & 0 deletions src/programmers/internal/application_v31_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommentFactory } from "../../factories/CommentFactory";
import { IJsDocTagInfo } from "../../schemas/metadata/IJsDocTagInfo";
import { MetadataAlias } from "../../schemas/metadata/MetadataAlias";

import { application_v31_object } from "./application_v31_object";
import { application_v31_schema } from "./application_v31_schema";

/**
Expand All @@ -14,6 +15,11 @@ export const application_v31_alias =
<BlockNever extends boolean>(blockNever: BlockNever) =>
(components: OpenApi.IComponents) =>
(alias: MetadataAlias): OpenApi.IJsonSchema.IReference => {
if (alias.value.size() === 1 && alias.value.objects.length === 1)
return application_v31_object(components)(
alias.value.objects[0]!,
) as OpenApi.IJsonSchema.IReference;

const $ref: string = `#/components/schemas/${alias.name}`;
if (components.schemas?.[alias.name] === undefined) {
// TEMPORARY ASSIGNMENT
Expand Down
10 changes: 7 additions & 3 deletions src/programmers/internal/application_v31_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ export const application_v31_object =
(
obj: MetadataObject,
): OpenApi.IJsonSchema.IReference | OpenApi.IJsonSchema.IObject => {
const $ref: string = `#/components/schemas/${obj.name}`;
if (components.schemas?.[obj.name] !== undefined) return { $ref };
if (obj._Is_literal() === true)
return create_object_schema(components)(obj);

const key: string = obj.name;
const $ref: string = `#/components/schemas/${key}`;
if (components.schemas?.[key] !== undefined) return { $ref };

const object: OpenApiV3.IJsonSchema = {};
components.schemas ??= {};
components.schemas[obj.name] = object;
components.schemas[key] = object;
Object.assign(object, create_object_schema(components)(obj));
return { $ref };
};
Expand Down
1 change: 0 additions & 1 deletion src/programmers/internal/application_v31_tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const application_v31_tuple =
: tuple.type.elements;
return {
type: "array",
items: undefined!,
prefixItems: prefixItems.map(generator),
additionalItems: tail ? generator(tail) : false,
};
Expand Down
3 changes: 2 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
"typescript": "^5.4.2"
},
"dependencies": {
"@samchon/openapi": "^0.1.4",
"cli": "^1.0.1",
"protobufjs": "^7.2.5",
"randexp": "^0.5.3",
"source-map-support": "^0.5.21",
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-6.0.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-6.0.1.tgz"
}
}
84 changes: 84 additions & 0 deletions test/schemas/json/v3_0/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IArray"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.ITuple"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IObject"
},
Expand Down Expand Up @@ -295,6 +298,81 @@
"type"
]
},
"OpenApi.IJsonSchema.ITuple": {
"type": "object",
"properties": {
"prefixItems": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OpenApi.IJsonSchema"
}
},
"additionalItems": {
"oneOf": [
{
"type": "boolean"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IConstant"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IBoolean"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.INumber"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IInteger"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IString"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IArray"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.ITuple"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IObject"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IReferencestring"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IOneOf"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IUnknown"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.INull"
}
]
},
"type": {
"type": "string",
"enum": [
"array"
]
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"deprecated": {
"type": "boolean"
}
},
"nullable": false,
"required": [
"prefixItems",
"additionalItems",
"type"
]
},
"OpenApi.IJsonSchema.IObject": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -324,6 +402,9 @@
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IArray"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.ITuple"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IObject"
},
Expand Down Expand Up @@ -414,6 +495,9 @@
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IArray"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.ITuple"
},
{
"$ref": "#/components/schemas/OpenApi.IJsonSchema.IObject"
},
Expand Down
Loading

0 comments on commit 4cb9dec

Please sign in to comment.