@ifit/json-schema-tools
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [1.2.0](https://github.com/ifit/schema-tools/compare/@ifit/json-schema-tools@1.1.0...@ifit/json-schema-tools@1.2.0) (2024-03-12) | ||
### Bug Fixes | ||
* lint fix for unused variable in getTypes function ([712c095](https://github.com/ifit/schema-tools/commit/712c095362f4712ec555d49f5d0ecce239c01039)) | ||
### Features | ||
* created npm package and using it in chainsaw code ([1e5f4cc](https://github.com/ifit/schema-tools/commit/1e5f4cc64fa0f615106d8c86ff64ce11dc44678e)) | ||
# 1.1.0 (2024-03-11) | ||
@@ -8,0 +24,0 @@ |
@@ -1,1 +0,2 @@ | ||
export declare function someFunction(): void; | ||
export declare function generateTypescript(schema: object): Promise<string>; | ||
export declare function getTypes(typescript: string): string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.someFunction = void 0; | ||
function someFunction() { | ||
console.log("hit in json schema tools"); | ||
exports.getTypes = exports.generateTypescript = void 0; | ||
const json_schema_to_typescript_1 = require("json-schema-to-typescript"); | ||
function annotateProperties(schema) { | ||
var _a; | ||
if (Array.isArray(schema.enum)) { | ||
schema.tsEnumNames = schema.enum.map((val) => { | ||
return val | ||
.split("_") | ||
.map((word) => `${word[0].toUpperCase()}${word.slice(1).toLowerCase()}`) | ||
.join(""); | ||
}); | ||
} | ||
switch (schema.format) { | ||
case "date-time": | ||
schema.tsType = "DateTime"; | ||
break; | ||
case "duration": | ||
schema.tsType = "Duration"; | ||
break; | ||
} | ||
if (schema.type === "object") { | ||
for (const value of Object.values((_a = schema.properties) !== null && _a !== void 0 ? _a : {})) { | ||
annotateProperties(value); | ||
} | ||
} | ||
const arrayTypes = schema.oneOf || schema.anyOf || schema.allOf; | ||
if (Array.isArray(arrayTypes)) { | ||
for (const value of arrayTypes) { | ||
annotateProperties(value); | ||
} | ||
} | ||
} | ||
exports.someFunction = someFunction; | ||
async function generateTypescript(schema) { | ||
var _a; | ||
const schemaCopy = JSON.parse(JSON.stringify(schema)); | ||
for (const value of Object.values((_a = schemaCopy.definitions) !== null && _a !== void 0 ? _a : {})) { | ||
annotateProperties(value); | ||
} | ||
const ts = await (0, json_schema_to_typescript_1.compile)(schemaCopy, "#", { | ||
bannerComment: "", | ||
enableConstEnums: false, | ||
}); | ||
return ts; | ||
} | ||
exports.generateTypescript = generateTypescript; | ||
function getTypes(typescript) { | ||
const match = typescript.matchAll(/ (type|interface|enum) (\w+) /g); | ||
return Array.from(match).map(([_all, _type, name]) => name); | ||
} | ||
exports.getTypes = getTypes; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ifit/json-schema-tools", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "> TODO: description", | ||
@@ -35,3 +35,6 @@ "author": "ericventor <Eric.Ventor@iFit.com>", | ||
}, | ||
"gitHead": "cc58676391bd95e0f528c876ba5467e3a8425e4e" | ||
"dependencies": { | ||
"json-schema-to-typescript": "^13.1.2" | ||
}, | ||
"gitHead": "3e042f3a0f0cddf126efa637cabaff69e5fc6d90" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
7369
54
0
1
+ Added@bcherny/json-schema-ref-parser@10.0.5-fork(transitive)
+ Added@jsdevtools/ono@7.1.3(transitive)
+ Added@types/glob@7.2.0(transitive)
+ Added@types/json-schema@7.0.15(transitive)
+ Added@types/lodash@4.17.13(transitive)
+ Added@types/minimatch@5.1.2(transitive)
+ Added@types/node@22.9.0(transitive)
+ Added@types/prettier@2.7.3(transitive)
+ Addedany-promise@1.3.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcall-me-maybe@1.0.2(transitive)
+ Addedcli-color@2.0.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedd@1.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedes6-weak-map@2.0.3(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedget-stdin@8.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-promise@4.2.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-schema-to-typescript@13.1.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlru-queue@0.1.0(transitive)
+ Addedmemoizee@0.4.17(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedmz@2.7.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprettier@2.8.8(transitive)
+ Addedthenify@3.3.1(transitive)
+ Addedthenify-all@1.6.0(transitive)
+ Addedtimers-ext@0.1.8(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedwrappy@1.0.2(transitive)