Socket
Socket
Sign inDemoInstall

json-schema-to-typescript

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-typescript - npm Package Compare versions

Comparing version 10.0.0 to 10.0.1

test.js

2

dist/src/linker.d.ts

@@ -7,2 +7,2 @@ import { JSONSchema, LinkedJSONSchema } from './types/JSONSchema';

*/
export declare function link(schema: JSONSchema4Type | JSONSchema, parent?: JSONSchema4Type | null, processed?: Set<string | number | boolean | import("json-schema").JSONSchema4Object | import("json-schema").JSONSchema4Array | JSONSchema | null>): LinkedJSONSchema;
export declare function link(schema: JSONSchema4Type | JSONSchema, parent?: JSONSchema4Type | null): LinkedJSONSchema;

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

*/
function link(schema, parent, processed) {
function link(schema, parent) {
if (parent === void 0) { parent = null; }
if (processed === void 0) { processed = new Set(); }
if (!Array.isArray(schema) && !lodash_1.isPlainObject(schema)) {

@@ -18,6 +17,5 @@ return schema;

// Handle cycles
if (processed.has(schema)) {
if (schema.hasOwnProperty(JSONSchema_1.Parent)) {
return schema;
}
processed.add(schema);
// Add a reference to this schema's parent

@@ -31,7 +29,7 @@ Object.defineProperty(schema, JSONSchema_1.Parent, {

if (Array.isArray(schema)) {
schema.forEach(function (child) { return link(child, schema, processed); });
schema.forEach(function (child) { return link(child, schema); });
}
// Objects
for (var key in schema) {
link(schema[key], schema, processed);
link(schema[key], schema);
}

@@ -38,0 +36,0 @@ return schema;

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

params: schema.type.map(function (type) {
return parse(__assign(__assign({}, lodash_1.omit(schema, 'description', 'id', 'title')), { type: type }), options, undefined, processed, usedNames);
var member = __assign(__assign({}, lodash_1.omit(schema, 'description', 'id', 'title')), { type: type });
return parse(utils_1.maybeStripDefault(member), options, undefined, processed, usedNames);
}),

@@ -207,0 +208,0 @@ type: 'UNION'

@@ -52,3 +52,9 @@ "use strict";

}
return schema.type === 'boolean' || typeof schema.default === 'boolean';
if (schema.type === 'boolean') {
return true;
}
if (!Array.isArray(schema.type) && typeof schema.default === 'boolean') {
return true;
}
return false;
},

@@ -71,3 +77,9 @@ CUSTOM_TYPE: function () {

}
return schema.type === 'integer' || schema.type === 'number' || typeof schema.default === 'number';
if (schema.type === 'integer' || schema.type === 'number') {
return true;
}
if (!Array.isArray(schema.type) && typeof schema.default === 'number') {
return true;
}
return false;
},

@@ -94,3 +106,9 @@ OBJECT: function (schema) {

}
return schema.type === 'string' || typeof schema.default === 'string';
if (schema.type === 'string') {
return true;
}
if (!Array.isArray(schema.type) && typeof schema.default === 'string') {
return true;
}
return false;
},

@@ -97,0 +115,0 @@ TYPED_ARRAY: function (schema) {

@@ -27,2 +27,9 @@ import { JSONSchema, LinkedJSONSchema } from './types/JSONSchema';

export declare function pathTransform(outputPath: string, inputPath: string, filePath: string): string;
/**
* Removes the schema's `default` property if it doesn't match the schema's `type` property.
* Useful when parsing unions.
*
* Mutates `schema`.
*/
export declare function maybeStripDefault(schema: LinkedJSONSchema): LinkedJSONSchema;
export {};

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.pathTransform = exports.escapeBlockComment = exports.log = exports.error = exports.generateName = exports.toSafeString = exports.stripExtension = exports.justName = exports.traverse = exports.mapDeep = exports.Try = void 0;
exports.maybeStripDefault = exports.pathTransform = exports.escapeBlockComment = exports.log = exports.error = exports.generateName = exports.toSafeString = exports.stripExtension = exports.justName = exports.traverse = exports.mapDeep = exports.Try = void 0;
var lodash_1 = require("lodash");

@@ -296,2 +296,49 @@ var path_1 = require("path");

exports.pathTransform = pathTransform;
/**
* Removes the schema's `default` property if it doesn't match the schema's `type` property.
* Useful when parsing unions.
*
* Mutates `schema`.
*/
function maybeStripDefault(schema) {
if (!('default' in schema)) {
return schema;
}
switch (schema.type) {
case 'array':
if (Array.isArray(schema.default)) {
return schema;
}
break;
case 'boolean':
if (typeof schema.default === 'boolean') {
return schema;
}
break;
case 'integer':
case 'number':
if (typeof schema.default === 'number') {
return schema;
}
break;
case 'string':
if (typeof schema.default === 'string') {
return schema;
}
break;
case 'null':
if (schema.default === null) {
return schema;
}
break;
case 'object':
if (lodash_1.isPlainObject(schema.default)) {
return schema;
}
break;
}
delete schema.default;
return schema;
}
exports.maybeStripDefault = maybeStripDefault;
//# sourceMappingURL=utils.js.map
{
"name": "json-schema-to-typescript",
"version": "10.0.0",
"version": "10.0.1",
"description": "compile json schema to typescript typings",

@@ -5,0 +5,0 @@ "main": "dist/src/index.js",

@@ -9,7 +9,3 @@ import {JSONSchema, Parent, LinkedJSONSchema} from './types/JSONSchema'

*/
export function link(
schema: JSONSchema4Type | JSONSchema,
parent: JSONSchema4Type | null = null,
processed = new Set<JSONSchema4Type | JSONSchema>()
): LinkedJSONSchema {
export function link(schema: JSONSchema4Type | JSONSchema, parent: JSONSchema4Type | null = null): LinkedJSONSchema {
if (!Array.isArray(schema) && !isPlainObject(schema)) {

@@ -20,6 +16,5 @@ return schema as LinkedJSONSchema

// Handle cycles
if (processed.has(schema)) {
if ((schema as JSONSchema).hasOwnProperty(Parent)) {
return schema as LinkedJSONSchema
}
processed.add(schema)

@@ -35,3 +30,3 @@ // Add a reference to this schema's parent

if (Array.isArray(schema)) {
schema.forEach(child => link(child, schema, processed))
schema.forEach(child => link(child, schema))
}

@@ -41,3 +36,3 @@

for (const key in schema as JSONSchema) {
link((schema as JSONSchema)[key], schema, processed)
link((schema as JSONSchema)[key], schema)
}

@@ -44,0 +39,0 @@

@@ -26,3 +26,3 @@ import {JSONSchema4Type, JSONSchema4TypeName} from 'json-schema'

} from './types/JSONSchema'
import {generateName, log} from './utils'
import {generateName, log, maybeStripDefault} from './utils'

@@ -250,5 +250,6 @@ export type Processed = Map<LinkedJSONSchema, Map<SchemaType, AST>>

standaloneName: standaloneName(schema, keyNameFromDefinition, usedNames),
params: (schema.type as JSONSchema4TypeName[]).map(type =>
parse({...omit(schema, 'description', 'id', 'title'), type}, options, undefined, processed, usedNames)
),
params: (schema.type as JSONSchema4TypeName[]).map(type => {
const member: LinkedJSONSchema = {...omit(schema, 'description', 'id', 'title'), type}
return parse(maybeStripDefault(member as any), options, undefined, processed, usedNames)
}),
type: 'UNION'

@@ -255,0 +256,0 @@ }

@@ -53,3 +53,9 @@ import {isPlainObject} from 'lodash'

}
return schema.type === 'boolean' || typeof schema.default === 'boolean'
if (schema.type === 'boolean') {
return true
}
if (!Array.isArray(schema.type) && typeof schema.default === 'boolean') {
return true
}
return false
},

@@ -72,3 +78,9 @@ CUSTOM_TYPE() {

}
return schema.type === 'integer' || schema.type === 'number' || typeof schema.default === 'number'
if (schema.type === 'integer' || schema.type === 'number') {
return true
}
if (!Array.isArray(schema.type) && typeof schema.default === 'number') {
return true
}
return false
},

@@ -97,3 +109,9 @@ OBJECT(schema) {

}
return schema.type === 'string' || typeof schema.default === 'string'
if (schema.type === 'string') {
return true
}
if (!Array.isArray(schema.type) && typeof schema.default === 'string') {
return true
}
return false
},

@@ -100,0 +118,0 @@ TYPED_ARRAY(schema) {

@@ -296,1 +296,49 @@ import {deburr, isPlainObject, mapValues, trim, upperFirst} from 'lodash'

}
/**
* Removes the schema's `default` property if it doesn't match the schema's `type` property.
* Useful when parsing unions.
*
* Mutates `schema`.
*/
export function maybeStripDefault(schema: LinkedJSONSchema): LinkedJSONSchema {
if (!('default' in schema)) {
return schema
}
switch (schema.type) {
case 'array':
if (Array.isArray(schema.default)) {
return schema
}
break
case 'boolean':
if (typeof schema.default === 'boolean') {
return schema
}
break
case 'integer':
case 'number':
if (typeof schema.default === 'number') {
return schema
}
break
case 'string':
if (typeof schema.default === 'string') {
return schema
}
break
case 'null':
if (schema.default === null) {
return schema
}
break
case 'object':
if (isPlainObject(schema.default)) {
return schema
}
break
}
delete schema.default
return schema
}
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