Huge News!Announcing our $40M Series B led by Abstract Ventures.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.35.0 to 0.36.0

2

package.json
{
"name": "typescript-json-schema",
"version": "0.35.0",
"version": "0.36.0",
"description": "typescript-json-schema generates JSON Schema files from your Typescript sources",

@@ -5,0 +5,0 @@ "main": "typescript-json-schema.js",

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

private typeNamesById;
private typeNamesUsed;
private typeIdsByName;
constructor(symbols: SymbolRef[], allSymbols: {

@@ -100,2 +100,3 @@ [name: string]: ts.Type;

private getTypeName;
private makeTypeNameUnique;
private getTypeDefinition;

@@ -102,0 +103,0 @@ setSchemaOverride(symbolName: string, schema: Definition): void;

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

this.typeNamesById = {};
this.typeNamesUsed = {};
this.typeIdsByName = {};
this.symbols = symbols;

@@ -661,14 +661,12 @@ this.allSymbols = allSymbols;

}
var baseName = this.tc.typeToString(typ, undefined, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType).replace(REGEX_FILE_NAME_OR_SPACE, "");
return this.makeTypeNameUnique(typ, this.tc.typeToString(typ, undefined, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType).replace(REGEX_FILE_NAME_OR_SPACE, ""));
};
JsonSchemaGenerator.prototype.makeTypeNameUnique = function (typ, baseName) {
var id = typ.id;
var name = baseName;
if (this.typeNamesUsed[name]) {
for (var i = 1; true; ++i) {
name = baseName + "_" + i;
if (!this.typeNamesUsed[name]) {
break;
}
}
for (var i = 1; this.typeIdsByName[name] !== undefined && this.typeIdsByName[name] !== id; ++i) {
name = baseName + "_" + i;
}
this.typeNamesById[id] = name;
this.typeNamesUsed[name] = true;
this.typeIdsByName[name] = id;
return name;

@@ -706,5 +704,5 @@ };

if (asTypeAliasRef) {
fullTypeName = this.tc.getFullyQualifiedName(reffedType.getFlags() & ts.SymbolFlags.Alias ?
fullTypeName = this.makeTypeNameUnique(typ, this.tc.getFullyQualifiedName(reffedType.getFlags() & ts.SymbolFlags.Alias ?
this.tc.getAliasedSymbol(reffedType) :
reffedType).replace(REGEX_FILE_NAME_OR_SPACE, "");
reffedType).replace(REGEX_FILE_NAME_OR_SPACE, ""));
}

@@ -721,6 +719,6 @@ else if (asRef) {

this.parseCommentsIntoDefinition(reffedType, definition, otherAnnotations);
this.parseCommentsIntoDefinition(symbol, definition, otherAnnotations);
if (prop) {
this.parseCommentsIntoDefinition(prop, returnedDefinition, otherAnnotations);
}
this.parseCommentsIntoDefinition(symbol, definition, otherAnnotations);
if (!asRef || !this.reffedDefinitions[fullTypeName]) {

@@ -727,0 +725,0 @@ if (asRef) {

@@ -322,3 +322,3 @@ import * as glob from "glob";

*/
private typeNamesUsed: { [name: string]: boolean } = {};
private typeIdsByName: { [name: string]: number } = {};

@@ -823,16 +823,20 @@ constructor(

}
return this.makeTypeNameUnique(
typ,
this.tc.typeToString(typ, undefined, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType).replace(REGEX_FILE_NAME_OR_SPACE, "")
);
}
const baseName = this.tc.typeToString(typ, undefined, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType).replace(REGEX_FILE_NAME_OR_SPACE, "");
private makeTypeNameUnique(typ: ts.Type, baseName: string) {
const id = (typ as any).id as number;
let name = baseName;
if (this.typeNamesUsed[name]) { // If a type with same name exists
for (let i = 1; true; ++i) { // Try appending "_1", "_2", etc.
name = baseName + "_" + i;
if (!this.typeNamesUsed[name]) {
break;
}
}
// If a type with same name exists
// Try appending "_1", "_2", etc.
for (let i = 1; this.typeIdsByName[name] !== undefined && this.typeIdsByName[name] !== id; ++i) {
name = baseName + "_" + i;
}
this.typeNamesById[id] = name;
this.typeNamesUsed[name] = true;
this.typeIdsByName[name] = id;
return name;

@@ -881,7 +885,10 @@ }

if (asTypeAliasRef) {
fullTypeName = this.tc.getFullyQualifiedName(
reffedType!.getFlags() & ts.SymbolFlags.Alias ?
this.tc.getAliasedSymbol(reffedType!) :
reffedType!
).replace(REGEX_FILE_NAME_OR_SPACE, "");
fullTypeName = this.makeTypeNameUnique(
typ,
this.tc.getFullyQualifiedName(
reffedType!.getFlags() & ts.SymbolFlags.Alias ?
this.tc.getAliasedSymbol(reffedType!) :
reffedType!
).replace(REGEX_FILE_NAME_OR_SPACE, "")
);
} else if (asRef) {

@@ -902,6 +909,6 @@ fullTypeName = this.getTypeName(typ);

this.parseCommentsIntoDefinition(reffedType!, definition, otherAnnotations); // handle comments in the type alias declaration
this.parseCommentsIntoDefinition(symbol!, definition, otherAnnotations);
if (prop) {
this.parseCommentsIntoDefinition(prop, returnedDefinition, otherAnnotations);
}
this.parseCommentsIntoDefinition(symbol!, definition, otherAnnotations);

@@ -908,0 +915,0 @@ // Create the actual definition only if is an inline definition, or

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