Skip to content

Commit

Permalink
Fix #842 - exact description comment tracing.
Browse files Browse the repository at this point in the history
When object alias type comes, `typia` had failed to catch its description comment and comment tags. This PR fixes such long time bug.

As the description comment is not important feature in `typia`, nobody had identified it until @jakubpavlicko22 says.
  • Loading branch information
samchon committed Oct 12, 2023
1 parent 6989d4a commit 105a4ae
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 17 deletions.
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.2.1",
"version": "5.2.2-dev.20231012",
"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.2.1",
"version": "5.2.2-dev.20231012",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -72,7 +72,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.2.1-dev.20231011"
"typia": "5.2.2-dev.20231012"
},
"peerDependencies": {
"typescript": ">= 4.8.0"
Expand Down
7 changes: 6 additions & 1 deletion src/factories/MetadataCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ export class MetadataCollection {
name: $id,
properties: [],
description:
(type.aliasSymbol &&
CommentFactory.description(type.aliasSymbol)) ??
(type.symbol && CommentFactory.description(type.symbol)) ??
undefined,
jsDocTags: type.symbol?.getJsDocTags() ?? [],
jsDocTags:
type.aliasSymbol?.getJsDocTags() ??
type.symbol?.getJsDocTags() ??
[],
validated: false,
index: this.object_index_++,
recursive: null!,
Expand Down
2 changes: 2 additions & 0 deletions test/generated/output/issues/test_issue_831_optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const test_issue_831_optional = () => {
},
},
nullable: false,
description: "Make all properties in T optional",
"x-typia-jsDocTags": [],
},
RequiredIQuery: {
Expand Down Expand Up @@ -103,6 +104,7 @@ export const test_issue_831_optional = () => {
},
nullable: false,
required: ["required", "optional"],
description: "Make all properties in T required",
"x-typia-jsDocTags": [],
},
},
Expand Down
40 changes: 27 additions & 13 deletions test/issues/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import typia, { IJsonApplication, IJsonComponents } from "typia";
import typia from "typia";

interface IQuery {
nonRequired: string | undefined;
/**
* Some description.
*
* @title something
*/
interface Interface {
value: number;
}

const app: IJsonApplication = typia.json.application<[Partial<IQuery>]>();
const query: IJsonComponents.IObject = app.components.schemas
?.PartialIQuery as IJsonComponents.IObject;
/**
* Some description.
*
* @title something
*/
interface Type {
value: number;
}

console.log(
Object.entries(query.properties).map(([key, value]) => [
key,
value["x-typia-required"],
value["x-typia-optional"],
]),
);
const app = typia.json.application<[Interface, Type]>();
console.log({
interface: {
description: app.components.schemas?.Interface?.description,
tags: app.components.schemas?.Interface?.["x-typia-jsDocTags"],
},
type: {
description: app.components.schemas?.Type?.description,
tags: app.components.schemas?.Type?.["x-typia-jsDocTags"],
},
});
1 change: 1 addition & 0 deletions test/schemas/json/ajv/DynamicTree.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"$id": "#/components/schemas/RecordstringDynamicTree",
"type": "object",
"properties": {},
"description": "Construct a type with a set of properties K of type T",
"x-typia-jsDocTags": [],
"additionalProperties": {
"$ref": "#/components/schemas/DynamicTree"
Expand Down
1 change: 1 addition & 0 deletions test/schemas/json/ajv/ObjectPartial.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"x-typia-optional": true
}
},
"description": "Make all properties in T optional",
"x-typia-jsDocTags": []
},
"ObjectPartial.IBase": {
Expand Down
1 change: 1 addition & 0 deletions test/schemas/json/ajv/ObjectRequired.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"array",
"object"
],
"description": "Make all properties in T required",
"x-typia-jsDocTags": []
},
"ObjectRequired.IBase": {
Expand Down
2 changes: 2 additions & 0 deletions test/schemas/json/ajv/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@
"$id": "#/components/schemas/RecordstringIObjectIAlias",
"type": "object",
"properties": {},
"description": "Construct a type with a set of properties K of type T",
"x-typia-jsDocTags": [],
"additionalProperties": {
"oneOf": [
Expand Down Expand Up @@ -1484,6 +1485,7 @@
"$id": "#/components/schemas/RecordstringIJsonSchema",
"type": "object",
"properties": {},
"description": "Construct a type with a set of properties K of type T",
"x-typia-jsDocTags": [],
"additionalProperties": {
"$ref": "#/components/schemas/IJsonSchema"
Expand Down
1 change: 1 addition & 0 deletions test/schemas/json/swagger/DynamicTree.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"type": "object",
"properties": {},
"nullable": false,
"description": "Construct a type with a set of properties K of type T",
"x-typia-jsDocTags": [],
"x-typia-additionalProperties": {
"$ref": "#/components/schemas/DynamicTree"
Expand Down
1 change: 1 addition & 0 deletions test/schemas/json/swagger/ObjectPartial.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
}
},
"nullable": false,
"description": "Make all properties in T optional",
"x-typia-jsDocTags": []
},
"ObjectPartial.IBase.Nullable": {
Expand Down
1 change: 1 addition & 0 deletions test/schemas/json/swagger/ObjectRequired.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"array",
"object"
],
"description": "Make all properties in T required",
"x-typia-jsDocTags": []
},
"ObjectRequired.IBase.Nullable": {
Expand Down
2 changes: 2 additions & 0 deletions test/schemas/json/swagger/UltimateUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@
"type": "object",
"properties": {},
"nullable": false,
"description": "Construct a type with a set of properties K of type T",
"x-typia-jsDocTags": [],
"x-typia-additionalProperties": {
"oneOf": [
Expand Down Expand Up @@ -1530,6 +1531,7 @@
"type": "object",
"properties": {},
"nullable": false,
"description": "Construct a type with a set of properties K of type T",
"x-typia-jsDocTags": [],
"x-typia-additionalProperties": {
"$ref": "#/components/schemas/IJsonSchema"
Expand Down

0 comments on commit 105a4ae

Please sign in to comment.