Skip to content

Commit

Permalink
Merge pull request #1020 from samchon/features/plugin
Browse files Browse the repository at this point in the history
Add ContentMediaType and JsonSchemaPlugin tags
  • Loading branch information
samchon authored Apr 2, 2024
2 parents ac2d8b4 + 3aef974 commit 7e4b344
Show file tree
Hide file tree
Showing 95 changed files with 1,984 additions and 37 deletions.
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-5.5.8.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.5.10.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-5.5.8.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.5.10.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.5.8",
"version": "5.5.10",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
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": "5.5.8",
"version": "5.5.10",
"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": "5.5.8"
"typia": "5.5.10"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.5.0"
Expand Down
1 change: 1 addition & 0 deletions src/schemas/json/IJsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export namespace IJsonSchema {
| "json-pointer"
| "relative-json-pointer"
| (string & {});
contentMediaType?: undefined | string;
"x-typia-typeTags"?: undefined | IMetadataTypeTag[];
}
export interface INumber extends IAtomic<"number"> {
Expand Down
10 changes: 10 additions & 0 deletions src/tags/ContentMediaType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { TagBase } from "./TagBase";

export type ContentMediaType<Value extends string> = TagBase<{
target: "string";
kind: "contentMediaType";
value: undefined;
schema: {
contentMediaType: Value;
};
}>;
8 changes: 8 additions & 0 deletions src/tags/JsonSchemaPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TagBase } from "./TagBase";

export type JsonSchemaPlugin<Schema extends object> = TagBase<{
target: "string" | "boolean" | "number" | "array";
kind: "jsonPlugin";
value: undefined;
schema: Schema;
}>;
2 changes: 2 additions & 0 deletions src/tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export * from "./Minimum";
export * from "./MinItems";
export * from "./MinLength";
export * from "./MultipleOf";
export * from "./JsonSchemaPlugin";
export * from "./Pattern";
export * from "./TagBase";
export * from "./Type";
export * from "./ContentMediaType";
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.5.8.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.5.10.tgz"
}
}
6 changes: 6 additions & 0 deletions test/schemas/json/ajv_standard/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@
"format": {
"type": "string"
},
"contentMediaType": {
"type": "string"
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1488,6 +1491,9 @@
"format": {
"type": "string"
},
"contentMediaType": {
"type": "string"
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down
10 changes: 10 additions & 0 deletions test/schemas/json/ajv_surplus/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@
"x-typia-required": false,
"x-typia-optional": true
},
"contentMediaType": {
"type": "string",
"x-typia-required": false,
"x-typia-optional": true
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down Expand Up @@ -2203,6 +2208,11 @@
"x-typia-required": false,
"x-typia-optional": true
},
"contentMediaType": {
"type": "string",
"x-typia-required": false,
"x-typia-optional": true
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down
6 changes: 6 additions & 0 deletions test/schemas/json/swagger_standard/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@
"format": {
"type": "string"
},
"contentMediaType": {
"type": "string"
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1484,6 +1487,9 @@
"format": {
"type": "string"
},
"contentMediaType": {
"type": "string"
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down
10 changes: 10 additions & 0 deletions test/schemas/json/swagger_surplus/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,11 @@
"x-typia-required": false,
"x-typia-optional": true
},
"contentMediaType": {
"type": "string",
"x-typia-required": false,
"x-typia-optional": true
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down Expand Up @@ -2209,6 +2214,11 @@
"x-typia-required": false,
"x-typia-optional": true
},
"contentMediaType": {
"type": "string",
"x-typia-required": false,
"x-typia-optional": true
},
"x-typia-typeTags": {
"type": "array",
"items": {
Expand Down
108 changes: 108 additions & 0 deletions test/schemas/reflect/metadata/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -5350,6 +5350,60 @@
"description": null,
"jsDocTags": []
},
{
"key": {
"any": false,
"required": true,
"optional": false,
"nullable": false,
"functional": false,
"atomics": [],
"constants": [
{
"type": "string",
"values": [
"contentMediaType"
]
}
],
"templates": [],
"escaped": null,
"rest": null,
"arrays": [],
"tuples": [],
"objects": [],
"aliases": [],
"natives": [],
"sets": [],
"maps": []
},
"value": {
"any": false,
"required": false,
"optional": true,
"nullable": false,
"functional": false,
"atomics": [
{
"type": "string",
"tags": []
}
],
"constants": [],
"templates": [],
"escaped": null,
"rest": null,
"arrays": [],
"tuples": [],
"objects": [],
"aliases": [],
"natives": [],
"sets": [],
"maps": []
},
"description": null,
"jsDocTags": []
},
{
"key": {
"any": false,
Expand Down Expand Up @@ -15352,6 +15406,60 @@
"description": null,
"jsDocTags": []
},
{
"key": {
"any": false,
"required": true,
"optional": false,
"nullable": false,
"functional": false,
"atomics": [],
"constants": [
{
"type": "string",
"values": [
"contentMediaType"
]
}
],
"templates": [],
"escaped": null,
"rest": null,
"arrays": [],
"tuples": [],
"objects": [],
"aliases": [],
"natives": [],
"sets": [],
"maps": []
},
"value": {
"any": false,
"required": false,
"optional": true,
"nullable": false,
"functional": false,
"atomics": [
{
"type": "string",
"tags": []
}
],
"constants": [],
"templates": [],
"escaped": null,
"rest": null,
"arrays": [],
"tuples": [],
"objects": [],
"aliases": [],
"natives": [],
"sets": [],
"maps": []
},
"description": null,
"jsDocTags": []
},
{
"key": {
"any": false,
Expand Down
14 changes: 14 additions & 0 deletions test/src/features/issues/test_issue_jsonSchema_contentMediaType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import typia, { tags } from "typia";

import { TestValidator } from "../../helpers/TestValidator";

export const test_issue_jsonSchema_contentMediaType = () => {
const app: typia.IJsonApplication =
typia.json.application<
[string & tags.ContentMediaType<"application/json">]
>();
TestValidator.equals("contentType")(app.schemas[0])({
type: "string",
contentMediaType: "application/json",
} as any);
};
18 changes: 18 additions & 0 deletions test/src/features/issues/test_issue_jsonSchema_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import typia, { tags } from "typia";

import { TestValidator } from "../../helpers/TestValidator";

export const test_issue_jsonSchema_plugin = () => {
const app: typia.IJsonApplication = typia.json.application<
[
string &
tags.JsonSchemaPlugin<{
"x-typia-easy-to-learn": true;
}>,
]
>();
TestValidator.equals("plugin")(app.schemas[0])({
type: "string",
"x-typia-easy-to-learn": true,
} as any);
};
26 changes: 26 additions & 0 deletions test/src/generated/output/assert/test_assert_UltimateUnion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export const test_assert_UltimateUnion = _test_assert(TypeGuardError)(
input.maxLength <= 4294967295)) &&
(undefined === input.pattern || "string" === typeof input.pattern) &&
(undefined === input.format || "string" === typeof input.format) &&
(undefined === input.contentMediaType ||
"string" === typeof input.contentMediaType) &&
(undefined === input["x-typia-typeTags"] ||
(Array.isArray(input["x-typia-typeTags"]) &&
input["x-typia-typeTags"].every(
Expand Down Expand Up @@ -755,6 +757,8 @@ export const test_assert_UltimateUnion = _test_assert(TypeGuardError)(
input.maxLength <= 4294967295)) &&
(undefined === input.pattern || "string" === typeof input.pattern) &&
(undefined === input.format || "string" === typeof input.format) &&
(undefined === input.contentMediaType ||
"string" === typeof input.contentMediaType) &&
(undefined === input["x-typia-typeTags"] ||
(Array.isArray(input["x-typia-typeTags"]) &&
input["x-typia-typeTags"].every(
Expand Down Expand Up @@ -2792,6 +2796,17 @@ export const test_assert_UltimateUnion = _test_assert(TypeGuardError)(
},
errorFactory,
)) &&
(undefined === input.contentMediaType ||
"string" === typeof input.contentMediaType ||
$guard(
_exceptionable,
{
path: _path + ".contentMediaType",
expected: "(string | undefined)",
value: input.contentMediaType,
},
errorFactory,
)) &&
(undefined === input["x-typia-typeTags"] ||
((Array.isArray(input["x-typia-typeTags"]) ||
$guard(
Expand Down Expand Up @@ -5967,6 +5982,17 @@ export const test_assert_UltimateUnion = _test_assert(TypeGuardError)(
},
errorFactory,
)) &&
(undefined === input.contentMediaType ||
"string" === typeof input.contentMediaType ||
$guard(
_exceptionable,
{
path: _path + ".contentMediaType",
expected: "(string | undefined)",
value: input.contentMediaType,
},
errorFactory,
)) &&
(undefined === input["x-typia-typeTags"] ||
((Array.isArray(input["x-typia-typeTags"]) ||
$guard(
Expand Down
Loading

0 comments on commit 7e4b344

Please sign in to comment.