Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-json-schema-generator

Package Overview
Dependencies
Maintainers
1
Versions
335
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-json-schema-generator - npm Package Compare versions

Comparing version 0.16.0 to 0.18.0

2

dist/src/Schema/Definition.d.ts

@@ -16,3 +16,3 @@ export declare type RawType = number | boolean | string | null;

};
enum?: RawType[] | Definition[];
enum?: (RawType | Definition)[];
default?: RawType | Object;

@@ -19,0 +19,0 @@ additionalProperties?: false | Definition;

@@ -6,2 +6,3 @@ import { Definition } from "../Schema/Definition";

import { TypeFormatter } from "../TypeFormatter";
export declare function makeNullable(def: Definition): Definition;
export declare class AnnotatedTypeFormatter implements SubTypeFormatter {

@@ -8,0 +9,0 @@ private childTypeFormatter;

@@ -7,3 +7,3 @@ "use strict";

const union = def.oneOf || def.anyOf;
if (union && union.filter((d) => d.type === null).length > 0) {
if (union && union.filter((d) => d.type === "null").length === 0) {
union.push({ type: "null" });

@@ -20,2 +20,5 @@ }

}
if (def.enum && def.enum.indexOf(null) === -1) {
def.enum.push(null);
}
}

@@ -42,2 +45,3 @@ else {

}
exports.makeNullable = makeNullable;
class AnnotatedTypeFormatter {

@@ -44,0 +48,0 @@ constructor(childTypeFormatter) {

@@ -12,14 +12,6 @@ "use strict";

const types = uniqueArray_1.uniqueArray(values.map((value) => this.getValueType(value)));
if (types.length === 1) {
return {
type: types[0],
enum: values,
};
}
else {
return {
type: types,
enum: values,
};
}
return {
type: types.length === 1 ? types[0] : types,
enum: values,
};
}

@@ -26,0 +18,0 @@ getChildren(type) {

@@ -10,3 +10,4 @@ import { Definition } from "../Schema/Definition";

private isLiteralUnion(type);
private getLiteralValue(value);
private getLiteralType(value);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const LiteralType_1 = require("../Type/LiteralType");
const NullType_1 = require("../Type/NullType");
const UnionType_1 = require("../Type/UnionType");

@@ -11,3 +12,3 @@ const uniqueArray_1 = require("../Utils/uniqueArray");

getDefinition(type) {
const values = uniqueArray_1.uniqueArray(type.getTypes().map((item) => item.getValue()));
const values = uniqueArray_1.uniqueArray(type.getTypes().map((item) => this.getLiteralValue(item)));
const types = uniqueArray_1.uniqueArray(type.getTypes().map((item) => this.getLiteralType(item)));

@@ -31,6 +32,9 @@ if (types.length === 1) {

isLiteralUnion(type) {
return type.getTypes().every((item) => item instanceof LiteralType_1.LiteralType);
return type.getTypes().every((item) => item instanceof LiteralType_1.LiteralType || item instanceof NullType_1.NullType);
}
getLiteralValue(value) {
return value.getId() === "null" ? null : value.getValue();
}
getLiteralType(value) {
return value.getValue() === null ? "null" : typeof value.getValue();
return value.getId() === "null" ? "null" : typeof value.getValue();
}

@@ -37,0 +41,0 @@ }

@@ -13,2 +13,18 @@ "use strict";

const definitions = type.getTypes().map((item) => this.childTypeFormatter.getDefinition(item));
let stringType = true;
let oneNotEnum = false;
for (const def of definitions) {
if (def.type !== "string") {
stringType = false;
break;
}
if (def.enum === undefined) {
oneNotEnum = true;
}
}
if (stringType && oneNotEnum) {
return {
type: "string",
};
}
return definitions.length > 1 ? {

@@ -15,0 +31,0 @@ anyOf: definitions,

{
"name": "ts-json-schema-generator",
"version": "0.16.0",
"version": "0.18.0",
"description": "Generate JSON schema from your Typescript sources",

@@ -41,19 +41,18 @@ "main": "dist/index.js",

"dependencies": {
"commander": "~2.11.0",
"commander": "~2.12.2",
"glob": "~7.1.2",
"json-stable-stringify": "^1.0.1",
"ts-node": "^3.3.0",
"typescript": "~2.6.1"
"ts-node": "^4.1.0",
"typescript": "~2.6.2"
},
"devDependencies": {
"@types/assertion-error": "^1.0.30",
"@types/chai": "^4.0.4",
"@types/commander": "^2.11.0",
"@types/glob": "^5.0.33",
"@types/chai": "^4.0.10",
"@types/glob": "^5.0.34",
"@types/json-stable-stringify": "^1.0.32",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.47",
"ajv": "~5.3.0",
"@types/mocha": "^2.2.45",
"@types/node": "^8.5.2",
"ajv": "~5.5.2",
"chai": "~4.1.2",
"mocha": "~4.0.1",
"mocha": "~4.1.0",
"source-map-support": "~0.5.0",

@@ -68,3 +67,3 @@ "tslint": "~5.8.0"

"lint": "tslint -p .",
"test": "tsc -p . && mocha -t 10000 --require source-map-support/register dist/test",
"test": "tsc -p . && mocha -t 10000 --require source-map-support/register --recursive dist/test",
"debug": "ts-node --inspect=19248 --debug-brk ts-json-schema-generator.ts",

@@ -71,0 +70,0 @@ "run": "ts-node ts-json-schema-generator.ts"

@@ -1,8 +0,4 @@

/** @hide */
export type Hidden = number;
export interface A {
foo: number;
export interface MyObject {
foo: "ok" | "fail" | "abort";
bar: "ok" | "fail" | "abort" | string;
}
export type MyObject = A | Hidden;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc