-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1182 from samchon/feature/enum
Close #1181: support enumeration level description comment in JSON schema.
- Loading branch information
Showing
21 changed files
with
198 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import typia from "typia"; | ||
|
||
import { TestValidator } from "./internal/TestValidator"; | ||
|
||
const app = typia.json.application<[ConstEnum]>(); | ||
console.log(app.components.schemas?.ConstEnum); | ||
|
||
TestValidator.equals("enum-description")(app.components.schemas?.ConstEnum)({ | ||
oneOf: [ | ||
{ | ||
const: 1, | ||
title: "The value one", | ||
description: | ||
"The value one.\n\nThe value one defined in the constant enumeration.", | ||
}, | ||
{ | ||
const: 2, | ||
title: "The value two", | ||
description: | ||
"The value two.\n\nThe value two defined in the constant enumeration.", | ||
}, | ||
], | ||
}); | ||
|
||
const enum ConstEnum { | ||
/** | ||
* The value one. | ||
* | ||
* The value one defined in the constant enumeration. | ||
*/ | ||
ONE = 1, | ||
|
||
/** | ||
* The value two. | ||
* | ||
* The value two defined in the constant enumeration. | ||
*/ | ||
TWO = 2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export namespace TestValidator { | ||
export const equals = | ||
(title: string, exception: (key: string) => boolean = () => false) => | ||
<T>(x: T) => | ||
(y: T) => { | ||
const diff: string[] = json_equal_to(exception)(x)(y); | ||
if (diff.length) | ||
throw new Error( | ||
`Bug on ${title}: found different values - [${diff.join(", ")}]`, | ||
); | ||
}; | ||
} | ||
|
||
const json_equal_to = | ||
(exception: (key: string) => boolean) => | ||
<T>(x: T) => | ||
(y: T): string[] => { | ||
const container: string[] = []; | ||
const iterate = | ||
(accessor: string) => | ||
(x: any) => | ||
(y: any): void => { | ||
if (typeof x !== typeof y) container.push(accessor); | ||
else if (x instanceof Array) | ||
if (!(y instanceof Array)) container.push(accessor); | ||
else array(accessor)(x)(y); | ||
else if (x instanceof Object) object(accessor)(x)(y); | ||
else if (x !== y) container.push(accessor); | ||
}; | ||
const array = | ||
(accessor: string) => | ||
(x: any[]) => | ||
(y: any[]): void => { | ||
if (x.length !== y.length) container.push(`${accessor}.length`); | ||
x.forEach((xItem, i) => iterate(`${accessor}[${i}]`)(xItem)(y[i])); | ||
}; | ||
const object = | ||
(accessor: string) => | ||
(x: any) => | ||
(y: any): void => | ||
Object.keys(x) | ||
.filter((key) => x[key] !== undefined && !exception(key)) | ||
.forEach((key) => iterate(`${accessor}.${key}`)(x[key])(y[key])); | ||
|
||
iterate("")(x)(y); | ||
return container; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,6 @@ | |
"typescript": "^5.3.2" | ||
}, | ||
"dependencies": { | ||
"typia": "../typia-6.5.5.tgz" | ||
"typia": "../typia-6.6.0.tgz" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CommentFactory } from "../../factories/CommentFactory"; | ||
|
||
import { IJsDocTagInfo } from "../../module"; | ||
|
||
export const application_title = (schema: { | ||
description?: string | null | undefined; | ||
jsDocTags?: IJsDocTagInfo[] | undefined; | ||
}): string | undefined => { | ||
const info: IJsDocTagInfo | undefined = schema.jsDocTags?.find( | ||
(tag) => tag.name === "title", | ||
); | ||
if (info?.text?.length) return CommentFactory.merge(info.text); | ||
else if (!schema.description?.length) return undefined; | ||
|
||
const index: number = schema.description.indexOf("\n"); | ||
const top: string = ( | ||
index === -1 ? schema.description : schema.description.substring(0, index) | ||
).trim(); | ||
return top.endsWith(".") ? top.substring(0, top.length - 1) : undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { Atomic } from "../../typings/Atomic"; | ||
|
||
import { IJsDocTagInfo } from "./IJsDocTagInfo"; | ||
import { IMetadataTypeTag } from "./IMetadataTypeTag"; | ||
|
||
export interface IMetadataConstantValue<T extends Atomic.Type> { | ||
value: T; | ||
tags: IMetadataTypeTag[][] | undefined; | ||
description?: string | null; | ||
jsDocTags?: IJsDocTagInfo[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,6 @@ | |
"typescript": "^5.4.5" | ||
}, | ||
"dependencies": { | ||
"typia": "../typia-6.5.5.tgz" | ||
"typia": "../typia-6.6.0.tgz" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
test/src/features/issues/test_issue_1179_tuple_type_in_dynamic_object.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.