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

typescript-json-schema

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-json-schema - npm Package Compare versions

Comparing version 0.42.0 to 0.43.0

api.md

1

dist/typescript-json-schema-cli.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
var typescript_json_schema_1 = require("./typescript-json-schema");

@@ -4,0 +5,0 @@ function run() {

3

dist/typescript-json-schema.d.ts

@@ -77,2 +77,3 @@ import * as ts from "typescript";

private reffedDefinitions;
private schemaOverrides;
private userValidationKeywords;

@@ -88,3 +89,3 @@ private typeNamesById;

}, tc: ts.TypeChecker, args?: Args);
readonly ReffedDefinitions: {
get ReffedDefinitions(): {
[key: string]: Definition;

@@ -91,0 +92,0 @@ };

@@ -14,2 +14,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.exec = exports.programFromConfig = exports.generateSchema = exports.buildGenerator = exports.getProgramFromFiles = exports.JsonSchemaGenerator = exports.getDefaultArgs = void 0;
var glob = require("glob");

@@ -228,2 +229,3 @@ var stringify = require("json-stable-stringify");

this.reffedDefinitions = {};
this.schemaOverrides = new Map();
this.typeNamesById = {};

@@ -238,3 +240,3 @@ this.typeIdsByName = {};

var _a;
return (__assign({}, acc, (_a = {}, _a[word] = true, _a)));
return (__assign(__assign({}, acc), (_a = {}, _a[word] = true, _a)));
}, {});

@@ -246,3 +248,3 @@ }

},
enumerable: true,
enumerable: false,
configurable: true

@@ -285,3 +287,3 @@ });

var v = match[2];
definition[name] = __assign({}, definition[name], (_a = {}, _a[k] = v ? parseValue(v) : true, _a));
definition[name] = __assign(__assign({}, definition[name]), (_a = {}, _a[k] = v ? parseValue(v) : true, _a));
return;

@@ -293,3 +295,3 @@ }

if (parts.length === 2 && subDefinitions[parts[0]]) {
definition[parts[0]] = __assign({}, definition[parts[0]], (_b = {}, _b[parts[1]] = text ? parseValue(text) : true, _b));
definition[parts[0]] = __assign(__assign({}, definition[parts[0]]), (_b = {}, _b[parts[1]] = text ? parseValue(text) : true, _b));
}

@@ -311,3 +313,3 @@ }

if (tupleType) {
var elemTypes = tupleType.elementTypes || propertyType.typeArguments;
var elemTypes = propertyType.typeArguments;
var fixedTypes = elemTypes.map(function (elType) { return _this.getTypeDefinition(elType); });

@@ -798,2 +800,5 @@ definition.type = "array";

}
else if (reffedType && this.schemaOverrides.has(reffedType.escapedName)) {
fullTypeName = reffedType.escapedName;
}
else {

@@ -881,2 +886,3 @@ fullTypeName = this.getTypeName(typ);

this.reffedDefinitions[symbolName] = schema;
this.schemaOverrides.set(symbolName, schema);
};

@@ -914,3 +920,3 @@ JsonSchemaGenerator.prototype.getSchemaForSymbol = function (symbolName, includeReffedDefinitions) {

if (this.args.ref && includeReffedDefinitions && Object.keys(this.reffedDefinitions).length > 0) {
root.definitions = __assign({}, root.definitions, this.reffedDefinitions);
root.definitions = __assign(__assign({}, root.definitions), this.reffedDefinitions);
}

@@ -917,0 +923,0 @@ return root;

{
"name": "typescript-json-schema",
"version": "0.42.0",
"version": "0.43.0",
"description": "typescript-json-schema generates JSON Schema files from your Typescript sources",

@@ -48,20 +48,20 @@ "main": "dist/typescript-json-schema.js",

"dependencies": {
"@types/json-schema": "^7.0.3",
"glob": "~7.1.4",
"@types/json-schema": "^7.0.5",
"glob": "~7.1.6",
"json-stable-stringify": "^1.0.1",
"typescript": "^3.5.3",
"yargs": "^14.0.0"
"typescript": "~4.0.2",
"yargs": "^15.4.1"
},
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/glob": "^7.1.1",
"@types/chai": "^4.2.12",
"@types/glob": "^7.1.3",
"@types/json-stable-stringify": "^1.0.32",
"@types/mocha": "^5.2.7",
"@types/node": "^12.7.2",
"ajv": "^6.10.2",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.0",
"ajv": "^6.12.4",
"chai": "^4.2.0",
"mocha": "^6.2.0",
"source-map-support": "^0.5.13",
"ts-node": "^8.3.0",
"tslint": "^5.19.0"
"mocha": "^8.1.1",
"source-map-support": "^0.5.19",
"ts-node": "^9.0.0",
"tslint": "^6.1.3"
},

@@ -72,2 +72,3 @@ "scripts": {

"debug": "ts-node --inspect=19248 --debug-brk typescript-json-schema-cli.ts",
"docs": "./update-docs.js",
"run": "ts-node typescript-json-schema-cli.ts",

@@ -74,0 +75,0 @@ "build": "tsc -p .",

@@ -9,4 +9,4 @@ # typescript-json-schema

* Compiles your Typescript program to get complete type information.
* Translates required properties, extends, annotation keywords, property initializers as defaults. You can find examples for these features in the [test examples](https://github.com/YousefED/typescript-json-schema/tree/master/test/programs).
- Compiles your Typescript program to get complete type information.
- Translates required properties, extends, annotation keywords, property initializers as defaults. You can find examples for these features in the [api doc](https://github.com/YousefED/typescript-json-schema/tree/master/api.md) or the [test examples](https://github.com/YousefED/typescript-json-schema/tree/master/test/programs).

@@ -17,4 +17,4 @@ ## Usage

* Install with `npm install typescript-json-schema -g`
* Generate schema from a typescript type: `typescript-json-schema project/directory/tsconfig.json TYPE`
- Install with `npm install typescript-json-schema -g`
- Generate schema from a typescript type: `typescript-json-schema project/directory/tsconfig.json TYPE`

@@ -26,3 +26,3 @@ To generate files for only _some_ types in `tsconfig.json` specify

* Generate schema from a typescript type: `typescript-json-schema "project/directory/**/*.ts" TYPE`
- Generate schema from a typescript type: `typescript-json-schema "project/directory/**/*.ts" TYPE`

@@ -59,3 +59,3 @@ The `TYPE` can either be a single, fully qualified type or `"*"` to generate the schema for all types.

```ts
import {resolve} from "path";
import { resolve } from "path";

@@ -66,3 +66,3 @@ import * as TJS from "typescript-json-schema";

const settings: TJS.PartialArgs = {
required: true
required: true,
};

@@ -72,4 +72,4 @@

const compilerOptions: TJS.CompilerOptions = {
strictNullChecks: true
}
strictNullChecks: true,
};

@@ -79,3 +79,7 @@ // optionally pass a base path

const program = TJS.getProgramFromFiles([resolve("my-file.ts")], compilerOptions, basePath);
const program = TJS.getProgramFromFiles(
[resolve("my-file.ts")],
compilerOptions,
basePath
);

@@ -85,3 +89,2 @@ // We can either get the schema for one file and one type...

// ... or a generator that lets us incrementally get more schemas

@@ -103,3 +106,3 @@

const settings: TJS.PartialArgs = {
uniqueNames: true
uniqueNames: true,
};

@@ -140,9 +143,9 @@

export interface Shape {
/**
* The size of the shape.
*
* @minimum 0
* @TJS-type integer
*/
size: number;
/**
* The size of the shape.
*
* @minimum 0
* @TJS-type integer
*/
size: number;
}

@@ -155,16 +158,16 @@ ```

{
"$ref": "#/definitions/Shape",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Shape": {
"properties": {
"size": {
"description": "The size of the shape.",
"minimum": 0,
"type": "integer"
}
},
"type": "object"
"$ref": "#/definitions/Shape",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Shape": {
"properties": {
"size": {
"description": "The size of the shape.",
"minimum": 0,
"type": "integer"
}
},
"type": "object"
}
}
}

@@ -177,3 +180,3 @@ ```

annotation with the full JSON of the spec (for special cases). This replaces the item types that would
have been inferred from the TypeScript type of the array elements.
have been inferred from the TypeScript type of the array elements.

@@ -184,16 +187,16 @@ Example:

export interface ShapesData {
/**
* Specify individual fields in items.
*
* @items.type integer
* @items.minimum 0
*/
sizes: number[];
/**
* Specify individual fields in items.
*
* @items.type integer
* @items.minimum 0
*/
sizes: number[];
/**
* Or specify a JSON spec:
*
* @items {"type":"string","format":"email"}
*/
emails: string[];
/**
* Or specify a JSON spec:
*
* @items {"type":"string","format":"email"}
*/
emails: string[];
}

@@ -206,27 +209,27 @@ ```

{
"$ref": "#/definitions/ShapesData",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Shape": {
"properties": {
"sizes": {
"description": "Specify individual fields in items.",
"items": {
"minimum": 0,
"type": "integer"
},
"type": "array"
},
"emails": {
"description": "Specify individual fields in items.",
"items": {
"format": "email",
"type": "string"
},
"type": "array"
}
},
"type": "object"
"$ref": "#/definitions/ShapesData",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Shape": {
"properties": {
"sizes": {
"description": "Specify individual fields in items.",
"items": {
"minimum": 0,
"type": "integer"
},
"type": "array"
},
"emails": {
"description": "Or specify a JSON spec:",
"items": {
"format": "email",
"type": "string"
},
"type": "array"
}
},
"type": "object"
}
}
}

@@ -233,0 +236,0 @@ ```

@@ -361,5 +361,15 @@ import * as glob from "glob";

/**
* This map holds references to all reffed definition., including schema
* overrides and generateddefinitions.
*/
private reffedDefinitions: { [key: string]: Definition } = {};
/**
* This map only holds explicit schema overrides. This helps differentiate between
* user defined schema overrides and generated definitions.
*/
private schemaOverrides = new Map<string, Definition>();
/**
* This is a set of all the user-defined validation keywords.

@@ -478,3 +488,3 @@ */

if (tupleType) { // tuple
const elemTypes: ts.NodeArray<ts.TypeNode> = tupleType.elementTypes || (propertyType as any).typeArguments;
const elemTypes: ts.NodeArray<ts.TypeNode> = (propertyType as any).typeArguments;
const fixedTypes = elemTypes.map(elType => this.getTypeDefinition(elType as any));

@@ -1012,2 +1022,4 @@ definition.type = "array";

fullTypeName = `${this.getTypeName(typ)}.${generateHashOfNode(getCanonicalDeclaration(sym), relativePath)}`;
} else if (reffedType && this.schemaOverrides.has(reffedType.escapedName as string)) {
fullTypeName = reffedType.escapedName as string;
} else {

@@ -1102,2 +1114,3 @@ fullTypeName = this.getTypeName(typ);

this.reffedDefinitions[symbolName] = schema;
this.schemaOverrides.set(symbolName, schema);
}

@@ -1104,0 +1117,0 @@

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