Skip to content
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

Custom JSON schema definer #1009

Merged
merged 1 commit into from
Mar 19, 2024
Merged

Custom JSON schema definer #1009

merged 1 commit into from
Mar 19, 2024

Conversation

samchon
Copy link
Owner

@samchon samchon commented Mar 19, 2024

If utilize tags.TagBase.schema property type, it be assigned to the JSON schema, so that customizable.

import typia, { tags } from "typia";

export const SpecialTagSchema = typia.json.application<[Special], "swagger">();

interface Special {
  /**
   * Deprecated tags are just used for marking.
   *
   * @title Unsigned integer
   * @deprecated
   */
  type: number & tags.Type<"int32">;

  /**
   * Internal tagged property never be shown in JSON schema.
   *
   * It even doesn't be shown in other `typia` functions like `assert<T>()`.
   *
   * @internal
   */
  internal: number[];

  /**
   * Hidden tagged property never be shown in JSON schema.
   *
   * However, it would be shown in other `typia` functions like `stringify<T>()`.
   *
   * @hidden
   */
  hidden: boolean;

  /**
   * You can limit the range of number.
   *
   * @exclusiveMinimum 19
   * @maximum 100
   * @default 30
   */
  number?: number;

  /**
   * You can limit the length of string.
   *
   * Also, multiple range conditions are also possible.
   */
  string: string &
    (
      | (tags.MinLength<3> & tags.MaxLength<24>)
      | (tags.MinLength<40> & tags.MaxLength<100>)
    );

  /**
   * You can limit the pattern of string.
   *
   * @pattern ^[a-z]+$
   */
  pattern: string;

  /**
   * You can limit the format of string.
   *
   * @format date-time
   */
  format: string | null;

  /**
   * In the Array case, possible to restrict its elements.
   */
  array: Array<string & tags.Format<"uuid">> & tags.MinItems<3>;
}

@samchon samchon added the enhancement New feature or request label Mar 19, 2024
@samchon samchon self-assigned this Mar 19, 2024
@samchon samchon merged commit ff2864c into master Mar 19, 2024
2 of 3 checks passed
@samchon samchon deleted the features/title branch March 19, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant