-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lighten up JSON Schema #916
Merged
Merged
Conversation
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
The JSON schema generated by the `typia.json.application<Types>()` function was quite extensive and lax. The first reason is that when `IJsonSchema.IAttribute` properties are union or array types, they are assigned equally to nested types. And the second reason is the special properties of `typia` that starts with `x-typia-`. Until now, there was no reason for the JSON Schema generated by `typia` to be lightweight. However, recently, as LLM models with ChatGPT as a topic have become popular, and they have started to use a model that charges by token (word), a problem has arisen. JSON Schema is entered into the ChatGPT (LLM) API and utilized to create various AI-enabled services, but these characteristics of the `typia.json.application<Types>()` function ultimately resulted in excessive token charges. Accordingly, this PR first prevented `IJsonSchema.IAttribute` from being excessively allocated. Second, a new generic argument `Surplus` was added to the `typia.json.application<Types, Purpose, Surplus>()` function that can determine whether to use additional properties starting with `x-typia-`. Of course, the default value for this is `false`. ```typescript /** * JSON Schema Application. * * Creates a JSON schema application which contains both main JSON schemas and * components. Note that, all of the named types are stored in the * {@link IJsonApplication.components} property for the `$ref` referencing. * * Also, `typia.json.application()` has two additional generic arguments. * * The 1st *Purpose* means the purpose determines the JSON schema definition spec. * For an example, `ajv` has an extra property "$recursiveRef" that are not * exists in the standard JSON schema definition spec. Otherwise, `swagger` * can't identify the tuple definition. * * The next *Surplus* means whether to allow surplus properties starting with * `x-typia-` or not. If `true`, the surplus properties like `x-typia-jsDocTags` * would be registered into the JSON schema, otherwise, not. * * @template Types Tuple of target types * @template Purpose Purpose of the JSON schema * @template Surplus Allow surplus properties starting with `x-typia-` or not * @return JSON schema application * * @author Jeongho Nam - https://github.com/samchon */ export function application< Types extends unknown[], Purpose extends "ajv" | "swagger" = "swagger", Surplus extends boolean = false, >(): IJsonApplication; ```
samchon
added
documentation
Improvements or additions to documentation
enhancement
New feature or request
labels
Jan 3, 2024
samchon
commented
Jan 3, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Succeeded to pass every test programs.
samchon
added a commit
that referenced
this pull request
Jan 9, 2024
When dieting JSON Schema (#916), have taken a mistake that even dieting the `IJsonSchema.default` value when the default value has configured by comment tag (no problem when type tag). This PR fixes the bug, so that revived the comment tag defined default value.
samchon
added a commit
to samchon/nestia
that referenced
this pull request
Jan 9, 2024
Same reason with samchon/typia#916
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The JSON schema generated by the
typia.json.application<Types>()
function was quite extensive and lax. The first reason is that whenIJsonSchema.IAttribute
properties are union or array types, they are assigned equally to nested types. And the second reason is the special properties oftypia
that starts withx-typia-
.Until now, there was no reason for the JSON Schema generated by
typia
to be lightweight. However, recently, as LLM models with ChatGPT as a topic have become popular, and they have started to use a model that charges by token (word), a problem has arisen. JSON Schema is entered into the ChatGPT (LLM) API and utilized to create various AI-enabled services, but these characteristics of thetypia.json.application<Types>()
function ultimately resulted in excessive token charges.Accordingly, this PR first prevented
IJsonSchema.IAttribute
from being excessively allocated. Second, a new generic argumentSurplus
was added to thetypia.json.application<Types, Purpose, Surplus>()
function that can determine whether to use additional properties starting withx-typia-
. Of course, the default value for this isfalse
.