YousefED / typescript-json-schema

Generate json-schema from your Typescript sources
BSD 3-Clause "New" or "Revised" License
3.17k stars 323 forks source link

Support bigint #584

Closed maartenbreddels closed 8 months ago

maartenbreddels commented 11 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

I used patch-package to patch typescript-json-schema@0.62.0 for the project I'm working on; it's an easier way to propose a fix than to open a PR.

I had your tool crash on a bigint, and this seems to solve my problem:

diff --git a/node_modules/typescript-json-schema/dist/typescript-json-schema.js b/node_modules/typescript-json-schema/dist/typescript-json-schema.js
index b230291..e6fb7af 100644
--- a/node_modules/typescript-json-schema/dist/typescript-json-schema.js
+++ b/node_modules/typescript-json-schema/dist/typescript-json-schema.js
@@ -482,6 +482,11 @@ var JsonSchemaGenerator = (function () {
                 definition.properties = {};
                 definition.additionalProperties = true;
             }
+            else if (propertyTypeString === "bigint") {
+                definition.type = "number";
+                definition.properties = {};
+                definition.additionalProperties = false;
+            }
             else {
                 var value = extractLiteralValue(propertyType);
                 if (value !== undefined) {
@@ -558,6 +563,7 @@ var JsonSchemaGenerator = (function () {
                         }
                     }
                 }
+
                 else {
                     var error = new TypeError("Unsupported type: " + propertyTypeString);
                     error.type = propertyType;

I hope this is helpful.

Regards,

Maarten

This issue body was partially generated by patch-package.

benmusson commented 9 months ago

I had the same issue on 0.63.0, and this solution worked.

domoritz commented 9 months ago

Please send a pull request if you'd like this feature supported.

domoritz commented 8 months ago

Done in #596