json-schema-to-typescript
Advanced tools
Comparing version 2.3.1 to 2.4.0
@@ -58,2 +58,8 @@ "use strict"; | ||
Compiler.prototype.getRuleType = function (rule) { | ||
// normalize rule | ||
// TODO: move this somewhere else | ||
// TODO: avoid mutating rule | ||
if (rule.type && Array.isArray(rule.type) && rule.type.length === 1) { | ||
rule.type = rule.type[0]; | ||
} | ||
if (rule.type === 'array' && rule.items) { | ||
@@ -60,0 +66,0 @@ return RuleType.TypedArray; |
@@ -190,3 +190,4 @@ "use strict"; | ||
Array.prototype._type = function (settings) { | ||
return (this.type || new Any()).toSafeType(settings) + "[]"; | ||
var type = (this.type || new Any()).toSafeType(settings); | ||
return (type.indexOf('|') > -1 || type.indexOf('&') > -1 ? "(" + type + ")" : type) + "[]"; // hacky | ||
}; | ||
@@ -193,0 +194,0 @@ return Array; |
{ | ||
"name": "json-schema-to-typescript", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "compile json schema to typescript typings", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -65,2 +65,10 @@ import { EnumJSONSchema, JSONSchema, NamedEnumJSONSchema } from './JSONSchema' | ||
private getRuleType(rule: JSONSchema): RuleType { | ||
// normalize rule | ||
// TODO: move this somewhere else | ||
// TODO: avoid mutating rule | ||
if (rule.type && Array.isArray(rule.type) && rule.type.length === 1) { | ||
rule.type = rule.type[0] | ||
} | ||
if (rule.type === 'array' && rule.items) { | ||
@@ -67,0 +75,0 @@ return RuleType.TypedArray |
@@ -160,3 +160,4 @@ import { camelCase, upperFirst } from 'lodash' | ||
_type(settings: TsTypeSettings) { | ||
return `${(this.type || new Any()).toSafeType(settings)}[]` | ||
const type = (this.type || new Any()).toSafeType(settings) | ||
return `${type.indexOf('|') > -1 || type.indexOf('&') > -1 ? `(${type})` : type}[]` // hacky | ||
} | ||
@@ -163,0 +164,0 @@ } |
@@ -10,2 +10,14 @@ export var schema = { | ||
"type": "array" | ||
}, | ||
"bar": { | ||
"items": { | ||
"type": "string" | ||
}, | ||
"type": ["array"] | ||
}, | ||
"baz": { | ||
"items": { | ||
"type": ["string", "number"] | ||
}, | ||
"type": ["array"] | ||
} | ||
@@ -17,3 +29,5 @@ } | ||
foo?: string[]; | ||
bar?: string[]; | ||
baz?: (string | number)[]; | ||
[k: string]: any; | ||
}` |
@@ -38,2 +38,5 @@ export var schema = { | ||
"tsEnumNames": ["Four","Five","Six"] | ||
}, | ||
"impliedHeterogeneousEnum": { | ||
"enum": [-20.1, null, "foo", false] | ||
} | ||
@@ -71,4 +74,5 @@ }, | ||
impliedNamedIntegerEnum: ImpliedNamedIntegerEnum; | ||
impliedHeterogeneousEnum?: -20.1 | null | "foo" | false; | ||
}` | ||
} | ||
}) |
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
83053
2387