From 65755049673e47d53d9388e46c8eb8c56495ca5a Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 10 Jan 2025 14:18:28 +0900 Subject: [PATCH] Fix #121: accessor bug including `#` symbol. --- package.json | 2 +- src/utils/AccessorUtil.ts | 2 +- .../test_issue_121_reference_accessor.ts | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/features/issues/test_issue_121_reference_accessor.ts diff --git a/package.json b/package.json index 04f6f02..6e243de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@samchon/openapi", - "version": "2.3.3", + "version": "2.3.4", "description": "OpenAPI definitions and converters for 'typia' and 'nestia'.", "main": "./lib/index.js", "module": "./lib/index.mjs", diff --git a/src/utils/AccessorUtil.ts b/src/utils/AccessorUtil.ts index e64fbec..46283a2 100644 --- a/src/utils/AccessorUtil.ts +++ b/src/utils/AccessorUtil.ts @@ -2,6 +2,6 @@ export namespace AccessorUtil { export const reference = (prefix: string): string => prefix .split("/") - .filter((str) => !!str.length) + .filter((str, i) => !!str.length && !(i === 0 && str === "#")) .join("."); } diff --git a/test/features/issues/test_issue_121_reference_accessor.ts b/test/features/issues/test_issue_121_reference_accessor.ts new file mode 100644 index 0000000..6f64620 --- /dev/null +++ b/test/features/issues/test_issue_121_reference_accessor.ts @@ -0,0 +1,26 @@ +import { TestValidator } from "@nestia/e2e"; +import { OpenApiTypeChecker } from "@samchon/openapi"; +import typia from "typia"; + +export const test_issue_121_reference_accessor = (): void => { + const collection = typia.json.application<[IMember]>(); + const accessors: string[] = []; + OpenApiTypeChecker.visit({ + closure: (_schema, acc) => { + accessors.push(acc); + }, + components: collection.components, + schema: collection.schemas[0], + }); + TestValidator.equals("accessors")(accessors)([ + "$input.schema", + '$input.components.schemas["IMember"]', + '$input.components.schemas["IMember"].properties["id"]', + '$input.components.schemas["IMember"].properties["age"]', + ]); +}; + +interface IMember { + id: string; + age: number; +}