typescript-json-schema
Advanced tools
Comparing version 0.49.0 to 0.50.0
@@ -93,2 +93,3 @@ import * as ts from "typescript"; | ||
}; | ||
private isFromDefaultLib; | ||
private parseCommentsIntoDefinition; | ||
@@ -117,2 +118,2 @@ private getDefinitionForRootType; | ||
export declare function programFromConfig(configFileName: string, onlyIncludeFiles?: string[]): ts.Program; | ||
export declare function exec(filePattern: string, fullTypeName: string, args?: Args): void; | ||
export declare function exec(filePattern: string, fullTypeName: string, args?: Args): Promise<void>; |
@@ -13,2 +13,38 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -258,2 +294,3 @@ exports.exec = exports.programFromConfig = exports.generateSchema = exports.buildGenerator = exports.getProgramFromFiles = exports.JsonSchemaGenerator = exports.regexRequire = exports.getDefaultArgs = void 0; | ||
id: true, | ||
$id: true, | ||
title: true | ||
@@ -298,2 +335,9 @@ }; | ||
}); | ||
JsonSchemaGenerator.prototype.isFromDefaultLib = function (symbol) { | ||
var declarations = symbol.getDeclarations(); | ||
if (declarations && declarations.length > 0) { | ||
return declarations[0].parent.getSourceFile().hasNoDefaultLib; | ||
} | ||
return false; | ||
}; | ||
JsonSchemaGenerator.prototype.parseCommentsIntoDefinition = function (symbol, definition, otherAnnotations) { | ||
@@ -304,9 +348,11 @@ var _this = this; | ||
} | ||
var comments = symbol.getDocumentationComment(this.tc); | ||
if (comments.length) { | ||
definition.description = comments | ||
.map(function (comment) { | ||
return comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n"); | ||
}) | ||
.join(""); | ||
if (!this.isFromDefaultLib(symbol)) { | ||
var comments = symbol.getDocumentationComment(this.tc); | ||
if (comments.length) { | ||
definition.description = comments | ||
.map(function (comment) { | ||
return comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n"); | ||
}) | ||
.join(""); | ||
} | ||
} | ||
@@ -914,2 +960,5 @@ var jsdocs = symbol.getJsDocTags(); | ||
} | ||
if (pairedSymbol && symbol && this.isFromDefaultLib(symbol)) { | ||
this.parseCommentsIntoDefinition(pairedSymbol, definition, otherAnnotations); | ||
} | ||
if (!asRef || !this.reffedDefinitions[fullTypeName]) { | ||
@@ -1224,37 +1273,54 @@ if (asRef) { | ||
function exec(filePattern, fullTypeName, args) { | ||
var _a; | ||
if (args === void 0) { args = getDefaultArgs(); } | ||
var program; | ||
var onlyIncludeFiles = undefined; | ||
if (REGEX_TSCONFIG_NAME.test(path.basename(filePattern))) { | ||
if (args.include && args.include.length > 0) { | ||
var globs = args.include.map(function (f) { return glob.sync(f); }); | ||
onlyIncludeFiles = (_a = []).concat.apply(_a, globs).map(normalizeFileName); | ||
} | ||
program = programFromConfig(filePattern, onlyIncludeFiles); | ||
} | ||
else { | ||
onlyIncludeFiles = glob.sync(filePattern); | ||
program = getProgramFromFiles(onlyIncludeFiles, { | ||
strictNullChecks: args.strictNullChecks, | ||
}); | ||
onlyIncludeFiles = onlyIncludeFiles.map(normalizeFileName); | ||
} | ||
var definition = generateSchema(program, fullTypeName, args, onlyIncludeFiles); | ||
if (definition === null) { | ||
throw new Error("No output definition. Probably caused by errors prior to this?"); | ||
} | ||
var json = stringify(definition, { space: 4 }) + "\n\n"; | ||
if (args.out) { | ||
require("fs").writeFile(args.out, json, function (err) { | ||
if (err) { | ||
throw new Error("Unable to write output file: " + err.message); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var program, onlyIncludeFiles, globs, definition, json, hasBeenBuffered; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
onlyIncludeFiles = undefined; | ||
if (REGEX_TSCONFIG_NAME.test(path.basename(filePattern))) { | ||
if (args.include && args.include.length > 0) { | ||
globs = args.include.map(function (f) { return glob.sync(f); }); | ||
onlyIncludeFiles = (_a = []).concat.apply(_a, globs).map(normalizeFileName); | ||
} | ||
program = programFromConfig(filePattern, onlyIncludeFiles); | ||
} | ||
else { | ||
onlyIncludeFiles = glob.sync(filePattern); | ||
program = getProgramFromFiles(onlyIncludeFiles, { | ||
strictNullChecks: args.strictNullChecks, | ||
}); | ||
onlyIncludeFiles = onlyIncludeFiles.map(normalizeFileName); | ||
} | ||
definition = generateSchema(program, fullTypeName, args, onlyIncludeFiles); | ||
if (definition === null) { | ||
throw new Error("No output definition. Probably caused by errors prior to this?"); | ||
} | ||
json = stringify(definition, { space: 4 }) + "\n\n"; | ||
if (args.out) { | ||
return [2, new Promise(function (resolve, reject) { | ||
var fs = require("fs"); | ||
fs.mkdir(path.dirname(args.out), { recursive: true }, function (mkErr) { | ||
if (mkErr) { | ||
return reject(new Error("Unable to create parent directory for output file: " + mkErr.message)); | ||
} | ||
fs.writeFile(args.out, json, function (wrErr) { | ||
if (wrErr) { | ||
return reject(new Error("Unable to write output file: " + wrErr.message)); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
})]; | ||
} | ||
else { | ||
hasBeenBuffered = process.stdout.write(json); | ||
if (hasBeenBuffered) { | ||
return [2, new Promise(function (resolve) { return process.stdout.on("drain", function () { return resolve(); }); })]; | ||
} | ||
} | ||
return [2]; | ||
}); | ||
} | ||
else { | ||
process.stdout.write(json); | ||
} | ||
}); | ||
} | ||
exports.exec = exec; | ||
//# sourceMappingURL=typescript-json-schema.js.map |
{ | ||
"name": "typescript-json-schema", | ||
"version": "0.49.0", | ||
"version": "0.50.0", | ||
"description": "typescript-json-schema generates JSON Schema files from your Typescript sources", | ||
@@ -48,18 +48,19 @@ "main": "dist/typescript-json-schema.js", | ||
"dependencies": { | ||
"@types/json-schema": "^7.0.6", | ||
"@types/json-schema": "^7.0.7", | ||
"@types/node": "^14.14.33", | ||
"glob": "^7.1.6", | ||
"json-stable-stringify": "^1.0.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.3", | ||
"typescript": "^4.2.3", | ||
"yargs": "^16.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.14", | ||
"@types/chai": "^4.2.15", | ||
"@types/glob": "^7.1.3", | ||
"@types/json-stable-stringify": "^1.0.32", | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.13", | ||
"ajv": "^6.12.6", | ||
"chai": "^4.2.0", | ||
"mocha": "^8.2.1", | ||
"@types/mocha": "^8.2.1", | ||
"ajv": "^7.2.1", | ||
"ajv-formats": "^1.5.1", | ||
"chai": "^4.3.3", | ||
"mocha": "^8.3.1", | ||
"prettier": "^2.2.1", | ||
@@ -66,0 +67,0 @@ "source-map-support": "^0.5.19", |
@@ -420,2 +420,3 @@ import * as glob from "glob"; | ||
id: true, | ||
$id: true, | ||
title: true | ||
@@ -516,2 +517,10 @@ }; | ||
private isFromDefaultLib(symbol: ts.Symbol) { | ||
const declarations = symbol.getDeclarations(); | ||
if (declarations && declarations.length > 0) { | ||
return declarations[0].parent.getSourceFile().hasNoDefaultLib; | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -525,11 +534,13 @@ * Parse the comments of a symbol into the definition and other annotations. | ||
// the comments for a symbol | ||
const comments = symbol.getDocumentationComment(this.tc); | ||
if (!this.isFromDefaultLib(symbol)) { | ||
// the comments for a symbol | ||
const comments = symbol.getDocumentationComment(this.tc); | ||
if (comments.length) { | ||
definition.description = comments | ||
.map((comment) => | ||
comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n") | ||
) | ||
.join(""); | ||
if (comments.length) { | ||
definition.description = comments | ||
.map((comment) => | ||
comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n") | ||
) | ||
.join(""); | ||
} | ||
} | ||
@@ -1268,2 +1279,6 @@ | ||
} | ||
if (pairedSymbol && symbol && this.isFromDefaultLib(symbol)) { | ||
this.parseCommentsIntoDefinition(pairedSymbol, definition, otherAnnotations); | ||
} | ||
// Create the actual definition only if is an inline definition, or | ||
@@ -1646,3 +1661,3 @@ // if it will be a $ref and it is not yet created | ||
export function exec(filePattern: string, fullTypeName: string, args = getDefaultArgs()): void { | ||
export async function exec(filePattern: string, fullTypeName: string, args = getDefaultArgs()): Promise<void> { | ||
let program: ts.Program; | ||
@@ -1671,10 +1686,22 @@ let onlyIncludeFiles: string[] | undefined = undefined; | ||
if (args.out) { | ||
require("fs").writeFile(args.out, json, function (err: Error) { | ||
if (err) { | ||
throw new Error("Unable to write output file: " + err.message); | ||
} | ||
return new Promise((resolve, reject) => { | ||
const fs = require("fs"); | ||
fs.mkdir(path.dirname(args.out), { recursive: true }, function (mkErr: Error) { | ||
if (mkErr) { | ||
return reject(new Error("Unable to create parent directory for output file: " + mkErr.message)); | ||
} | ||
fs.writeFile(args.out, json, function(wrErr: Error) { | ||
if (wrErr) { | ||
return reject(new Error("Unable to write output file: " + wrErr.message)); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
process.stdout.write(json); | ||
const hasBeenBuffered = process.stdout.write(json); | ||
if (hasBeenBuffered) { | ||
return new Promise(resolve => process.stdout.on("drain", () => resolve())); | ||
} | ||
} | ||
} |
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
225775
3258
7
+ Added@types/node@^14.14.33
+ Added@types/node@14.18.63(transitive)
Updated@types/json-schema@^7.0.7
Updatedtypescript@^4.2.3