New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-json-schema-generator

Package Overview
Dependencies
Maintainers
1
Versions
340
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.58.1 to 0.59.0

3

dist/factory/formatter.d.ts

@@ -0,2 +1,3 @@

import { Config } from "./../src/Config";
import { TypeFormatter } from "../src/TypeFormatter";
export declare function createFormatter(): TypeFormatter;
export declare function createFormatter(config: Config): TypeFormatter;

@@ -29,3 +29,4 @@ "use strict";

const VoidTypeFormatter_1 = require("../src/TypeFormatter/VoidTypeFormatter");
function createFormatter() {
function createFormatter(config) {
var _a, _b;
const chainTypeFormatter = new ChainTypeFormatter_1.ChainTypeFormatter([]);

@@ -46,4 +47,4 @@ const circularReferenceTypeFormatter = new CircularReferenceTypeFormatter_1.CircularReferenceTypeFormatter(chainTypeFormatter);

.addTypeFormatter(new EnumTypeFormatter_1.EnumTypeFormatter())
.addTypeFormatter(new ReferenceTypeFormatter_1.ReferenceTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new DefinitionTypeFormatter_1.DefinitionTypeFormatter(circularReferenceTypeFormatter))
.addTypeFormatter(new ReferenceTypeFormatter_1.ReferenceTypeFormatter(circularReferenceTypeFormatter, (_a = config.encodeRefs, (_a !== null && _a !== void 0 ? _a : true))))
.addTypeFormatter(new DefinitionTypeFormatter_1.DefinitionTypeFormatter(circularReferenceTypeFormatter, (_b = config.encodeRefs, (_b !== null && _b !== void 0 ? _b : true))))
.addTypeFormatter(new ObjectTypeFormatter_1.ObjectTypeFormatter(circularReferenceTypeFormatter))

@@ -50,0 +51,0 @@ .addTypeFormatter(new AliasTypeFormatter_1.AliasTypeFormatter(circularReferenceTypeFormatter))

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

const parser = parser_1.createParser(program, config);
const formatter = formatter_1.createFormatter();
const formatter = formatter_1.createFormatter(config);
return new SchemaGenerator_1.SchemaGenerator(program, parser, formatter);

@@ -13,0 +13,0 @@ }

@@ -11,4 +11,5 @@ export interface Config {

skipTypeCheck?: boolean;
encodeRefs?: boolean;
extraTags?: string[];
}
export declare const DEFAULT_CONFIG: Config;

@@ -10,4 +10,5 @@ "use strict";

skipTypeCheck: false,
encodeRefs: true,
extraTags: [],
};
//# sourceMappingURL=Config.js.map

@@ -33,2 +33,5 @@ "use strict";

}
else if (ts.isClassDeclaration(valueDec)) {
return this.childNodeParser.createType(valueDec, context);
}
throw new LogicError_1.LogicError(`Invalid type query "${valueDec.getFullText()}" (ts.SyntaxKind = ${valueDec.kind})`);

@@ -35,0 +38,0 @@ }

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

private childTypeFormatter;
constructor(childTypeFormatter: TypeFormatter);
private encodeRefs;
constructor(childTypeFormatter: TypeFormatter, encodeRefs: boolean);
supportsType(type: DefinitionType): boolean;

@@ -11,0 +12,0 @@ getDefinition(type: DefinitionType): Definition;

@@ -6,4 +6,5 @@ "use strict";

class DefinitionTypeFormatter {
constructor(childTypeFormatter) {
constructor(childTypeFormatter, encodeRefs) {
this.childTypeFormatter = childTypeFormatter;
this.encodeRefs = encodeRefs;
}

@@ -14,3 +15,4 @@ supportsType(type) {

getDefinition(type) {
return { $ref: "#/definitions/" + encodeURIComponent(type.getName()) };
const ref = type.getName();
return { $ref: `#/definitions/${this.encodeRefs ? encodeURIComponent(ref) : ref}` };
}

@@ -17,0 +19,0 @@ getChildren(type) {

@@ -35,3 +35,5 @@ "use strict";

...result,
...this.childTypeFormatter.getChildren(baseType).slice(1),
...this.childTypeFormatter
.getChildren(baseType)
.filter(childType => childType.getName() !== baseType.getName()),
], []),

@@ -38,0 +40,0 @@ ...(additionalProperties instanceof BaseType_1.BaseType

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

private childTypeFormatter;
constructor(childTypeFormatter: TypeFormatter);
private encodeRefs;
constructor(childTypeFormatter: TypeFormatter, encodeRefs: boolean);
supportsType(type: ReferenceType): boolean;

@@ -11,0 +12,0 @@ getDefinition(type: ReferenceType): Definition;

@@ -6,4 +6,5 @@ "use strict";

class ReferenceTypeFormatter {
constructor(childTypeFormatter) {
constructor(childTypeFormatter, encodeRefs) {
this.childTypeFormatter = childTypeFormatter;
this.encodeRefs = encodeRefs;
}

@@ -14,3 +15,4 @@ supportsType(type) {

getDefinition(type) {
return { $ref: "#/definitions/" + encodeURIComponent(type.getName()) };
const ref = type.getName();
return { $ref: `#/definitions/${this.encodeRefs ? encodeURIComponent(ref) : ref}` };
}

@@ -17,0 +19,0 @@ getChildren(type) {

@@ -84,2 +84,6 @@ "use strict";

}
if ((other.additionalProperties || other.additionalProperties === undefined) &&
definition.additionalProperties == false) {
delete definition.additionalProperties;
}
return definition;

@@ -86,0 +90,0 @@ };

@@ -11,6 +11,2 @@ "use strict";

const SchemaGenerator_1 = require("../src/SchemaGenerator");
const validator = new Ajv({
extendRefs: "fail",
format: "full",
});
const basePath = "test/config";

@@ -27,3 +23,3 @@ function assertSchema(name, userConfig, tsconfig) {

const program = program_1.createProgram(config);
const generator = new SchemaGenerator_1.SchemaGenerator(program, parser_1.createParser(program, config), formatter_1.createFormatter());
const generator = new SchemaGenerator_1.SchemaGenerator(program, parser_1.createParser(program, config), formatter_1.createFormatter(config));
const expected = JSON.parse(fs_1.readFileSync(path_1.resolve(`${basePath}/${name}/schema.json`), "utf8"));

@@ -33,2 +29,6 @@ const actual = JSON.parse(JSON.stringify(generator.createSchema(config.type)));

expect(actual).toEqual(expected);
const validator = new Ajv({
extendRefs: "fail",
format: config.encodeRefs === false ? undefined : "full",
});
validator.validateSchema(actual);

@@ -131,3 +131,10 @@ expect(validator.errors).toBeNull();

}, true));
it("no-ref-encode", assertSchema("no-ref-encode", {
type: "MyObject",
expose: "all",
encodeRefs: false,
topRef: true,
jsDoc: "none",
}));
});
//# sourceMappingURL=config.test.js.map

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

const program = program_1.createProgram(config);
const generator = new SchemaGenerator_1.SchemaGenerator(program, parser_1.createParser(program, config), formatter_1.createFormatter());
const generator = new SchemaGenerator_1.SchemaGenerator(program, parser_1.createParser(program, config), formatter_1.createFormatter(config));
expect(() => generator.createSchema(type)).toThrowError(message);

@@ -22,0 +22,0 @@ };

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

const program = program_1.createProgram(config);
const generator = new SchemaGenerator_1.SchemaGenerator(program, parser_1.createParser(program, config), formatter_1.createFormatter());
const generator = new SchemaGenerator_1.SchemaGenerator(program, parser_1.createParser(program, config), formatter_1.createFormatter(config));
const schema = generator.createSchema(type);

@@ -45,2 +45,3 @@ const expected = JSON.parse(fs_1.readFileSync(path_1.resolve(`${basePath}/${relativePath}/schema.json`), "utf8"));

it("interface-extra-props", assertSchema("interface-extra-props", "MyObject"));
it("interface-extended-extra-props", assertSchema("interface-extended-extra-props", "MyObject"));
it("interface-array", assertSchema("interface-array", "TagArray"));

@@ -103,2 +104,3 @@ it("interface-property-dash", assertSchema("interface-property-dash", "MyObject"));

it("type-typeof-enum", assertSchema("type-typeof-enum", "MyObject"));
it("type-typeof-class", assertSchema("type-typeof-class", "MyObject"));
it("type-indexed-access-tuple-1", assertSchema("type-indexed-access-tuple-1", "MyType"));

@@ -137,2 +139,3 @@ it("type-indexed-access-tuple-2", assertSchema("type-indexed-access-tuple-2", "MyType"));

it("generic-default", assertSchema("generic-default", "MyObject"));
it("generic-nested", assertSchema("generic-nested", "MyObject"));
it("generic-prefixed-number", assertSchema("generic-prefixed-number", "MyObject"));

@@ -139,0 +142,0 @@ it("generic-void", assertSchema("generic-void", "MyObject"));

@@ -15,11 +15,12 @@ "use strict";

.option("-e, --expose <expose>", "Type exposing", /^(all|none|export)$/, "export")
.option("-r, --no-top-ref", "Do not create a top-level $ref definition")
.option("-j, --jsDoc <extended>", "Read JsDoc annotations", /^(none|basic|extended)$/, "extended")
.option("-u, --unstable", "Do not sort properties")
.option("-s, --strict-tuples", "Do not allow additional items on tuples")
.option("-c, --no-type-check", "Skip type checks to improve performance")
.option("--unstable", "Do not sort properties")
.option("--strict-tuples", "Do not allow additional items on tuples")
.option("--no-top-ref", "Do not create a top-level $ref definition")
.option("--no-type-check", "Skip type checks to improve performance")
.option("--no-ref-encode", "Do not encode references")
.option("-o, --out <file>", "Set the output file (default: stdout)")
.option("-k, --validationKeywords [value]", "Provide additional validation keywords to include", (value, list) => list.concat(value), [])
.option("--validationKeywords [value]", "Provide additional validation keywords to include", (value, list) => list.concat(value), [])
.parse(process.argv);
const config = Object.assign(Object.assign({}, Config_1.DEFAULT_CONFIG), { path: args.path, tsconfig: args.tsconfig, type: args.type, expose: args.expose, topRef: args.topRef, jsDoc: args.jsDoc, sortProps: !args.unstable, strictTuples: args.strictTuples, skipTypeCheck: !args.typeCheck, extraTags: args.validationKeywords });
const config = Object.assign(Object.assign({}, Config_1.DEFAULT_CONFIG), { path: args.path, tsconfig: args.tsconfig, type: args.type, expose: args.expose, topRef: args.topRef, jsDoc: args.jsDoc, sortProps: !args.unstable, strictTuples: args.strictTuples, skipTypeCheck: !args.typeCheck, encodeRefs: args.refEncode, extraTags: args.validationKeywords });
try {

@@ -26,0 +27,0 @@ const schema = generator_1.createGenerator(config).createSchema(args.type);

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

@@ -36,26 +36,26 @@ "main": "dist/index.js",

"dependencies": {
"@types/json-schema": "^7.0.3",
"commander": "~4.0.1",
"@types/json-schema": "^7.0.4",
"commander": "~4.1.1",
"glob": "~7.1.6",
"json-stable-stringify": "^1.0.1",
"typescript": "~3.7.3"
"typescript": "~3.7.5"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/jest": "^24.0.23",
"@types/jest": "^25.1.1",
"@types/json-stable-stringify": "^1.0.32",
"@types/node": "^12.12.18",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"ajv": "~6.10.2",
"@types/node": "^13.7.0",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"ajv": "~6.11.0",
"chai": "~4.2.0",
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.7.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^24.9.0",
"jest": "^25.1.0",
"jest-junit": "^10.0.0",
"prettier": "^1.19.1",
"source-map-support": "~0.5.16",
"ts-jest": "^24.2.0",
"ts-node": "^8.5.4"
"ts-jest": "^25.2.0",
"ts-node": "^8.6.2"
},

@@ -62,0 +62,0 @@ "scripts": {

@@ -55,5 +55,2 @@ # ts-json-schema-generator

-r, --no-top-ref
Do not create a top-level $ref definition.
-j, --jsDoc <extended|none|basic>

@@ -64,12 +61,18 @@ none: Do not use JsDoc annotations.

-u, --unstable
--unstable
Do not sort properties.
-s, --strict-tuples
--strict-tuples
Do not allow additional items on tuples.
-c, --no-type-check
--no-top-ref
Do not create a top-level $ref definition.
--no-type-check
Skip type checks for better performance.
-k, --validationKeywords
--no-ref-encode
Do not encode references. According to the standard, references must be valid URIs but some tools do not support encoded references.
--validationKeywords
Provide additional validation keywords to include.

@@ -76,0 +79,0 @@ ```

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

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

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