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

Support of Schema properties in ts-to-core-types #5

Open
pomgui opened this issue Feb 23, 2022 · 1 comment
Open

Support of Schema properties in ts-to-core-types #5

pomgui opened this issue Feb 23, 2022 · 1 comment

Comments

@pomgui
Copy link

pomgui commented Feb 23, 2022

Before anything: Great work! I'm using typeconv in some of my projects and I found it extremely useful.

However, AFAIU, the ts-to-core-types.ts module only supports a few schema properties when converting from jsDoc comment tags (e.g. example, see, default).

It would be great if it can also support all of the properties defined in OpenAPI3 Schema Object.

Example:

interface WorkingPerson {
  /**
   * @format uuid
   */
  uuid: string;
  /**
   * @format int32
   * @maximum 70
   * @minimum 5
   * @deprecated true
   */
  age: number;
}

As an exercise, I altered this project allowing the use of unlimited "custom" jsDoc tags, however I stopped when I realized that the allowed properties are kind a hard coded in other projects too (i.e. core-types interface CoreTypeAnnotations).

So my question is: Is there a reason for this?

@grantila
Copy link
Owner

I'm not sure how other systems would treat unknown such tags, so I limited it to what is known (e.g. jsdoc: https://jsdoc.app/). If there's a standard out there for annotating schema constraints (format, maximum, etc as you described) in jsdoc, I'm happy to add it.

Your example, in typescript; it would be fine to create such an object with age = 80, no editor/linter/compiler would pick that up and complain that age is above maximum, since that tag is not standard but "made up".

@deprecated in your case, should probably not have a value true but (if anything) an explanation, see https://jsdoc.app/tags-deprecated.html

I'm not against this, will just need to consider if there is previous work around this topic to piggy-back on (aligning json schema constraints with jsdoc tags specifically).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants