From 62d35b4c800d28d8c50f0ccd9e728d1553f2e5d2 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 13 May 2022 11:00:04 +0900 Subject: [PATCH] Fix #41 and Report #42 --- README.md | 2 +- package.json | 4 ++-- src/factories/SchemaFactory.ts | 2 +- test/features/test_stringify_atomic_union.ts | 2 +- .../fast-json-stringify-top-level-one-of.ts | 20 +++++++++++++++++++ test/manual.js | 2 +- 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 test/issues/fast-json-stringify-top-level-one-of.ts diff --git a/README.md b/README.md index 71b61076a6..4daa6585cf 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ const stringify = fast({ nullable: false, }, gender: { - anyOf: [ + oneOf: [ { type: "string" }, { type: "number" } ], diff --git a/package.json b/package.json index 43287b110a..78e1ff1d4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typescript-json", - "version": "2.0.9", + "version": "2.0.10", "description": "Faster JSON stringify with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -39,7 +39,7 @@ "typescript": "^4.6.4" }, "dependencies": { - "fast-json-stringify": "^3.1.0", + "fast-json-stringify": "^3.2.0", "nested-error-stacks": "^2.1.1", "tstl": "^2.5.6", "uuid": "^8.3.2" diff --git a/src/factories/SchemaFactory.ts b/src/factories/SchemaFactory.ts index df372fe2fb..f0096fbfc8 100644 --- a/src/factories/SchemaFactory.ts +++ b/src/factories/SchemaFactory.ts @@ -34,7 +34,7 @@ export namespace SchemaFactory return unions[0]; else return { - anyOf: unions + oneOf: unions }; } diff --git a/test/features/test_stringify_atomic_union.ts b/test/features/test_stringify_atomic_union.ts index 31ed642fb4..eed9bf99ed 100644 --- a/test/features/test_stringify_atomic_union.ts +++ b/test/features/test_stringify_atomic_union.ts @@ -9,7 +9,7 @@ export function test_stringify_atomic_union(): void const expected: string = JSON.stringify(value) if (json !== expected) - throw new Error("Bug on TSON.createStringifier(): failed to understand the atomic union type.");; + throw new Error("Bug on TSON.createStringifier(): failed to understand the atomic union type."); }; test(true); diff --git a/test/issues/fast-json-stringify-top-level-one-of.ts b/test/issues/fast-json-stringify-top-level-one-of.ts new file mode 100644 index 0000000000..8327c9e0d9 --- /dev/null +++ b/test/issues/fast-json-stringify-top-level-one-of.ts @@ -0,0 +1,20 @@ +import TSON from "../../src"; + +export function fast_json_stringify_top_level_one_of(): void +{ + const top = TSON.createStringifier(); + const capsuled = TSON.createStringifier(); + + console.log("TOP LEVEL UNION") + console.log(top.toString()); + console.log("-----------------------------------"); + console.log("THE CAPSULED UNION"); + console.log(capsuled.toString()); +} + +interface IMember +{ + id: string; + name: string; + sex: number | string; +} \ No newline at end of file diff --git a/test/manual.js b/test/manual.js index 1fedd47de0..f480169824 100644 --- a/test/manual.js +++ b/test/manual.js @@ -7,7 +7,7 @@ runner.register({ compiler: "ttypescript" }); -const program = require("./features/test_stringify_array_generic_alias.ts"); +const program = require("./issues/fast-json-stringify-top-level-one-of.ts"); for (const value of Object.values(program)) if (typeof value === "function") value(); \ No newline at end of file