Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,37 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
if (json.every(item => typeof item === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) {
return json;
}
}
}
{{/isNumeric}}
{{#isString}}
if (Array.isArray(json)) {
if (json.every(item => typeof item === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) {
return json;
}
}
}
{{/isString}}
{{/items}}
{{/isArray}}
{{^isArray}}
{{#isDateType}}
if(!(isNaN(new Date(json).getTime()))) {
if (!(isNaN(new Date(json).getTime()))) {
return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}new Date(json));
}
{{/isDateType}}
{{^isDateType}}
{{#isDateTimeType}}
if(!(isNaN(new Date(json).getTime()))) {
if (!(isNaN(new Date(json).getTime()))) {
return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}new Date(json));
}
{{/isDateTimeType}}
{{/isDateType}}
{{#isNumeric}}
if(typeof json === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}json === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
if (typeof json === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}json === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
return json;
}
{{/isNumeric}}
{{#isString}}
if(typeof json === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}json === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
if (typeof json === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}json === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
return json;
}
{{/isString}}
Expand Down Expand Up @@ -189,14 +189,14 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
{{/isDateTimeType}}
{{#isNumeric}}
if (Array.isArray(value)) {
if (value.every(item => typeof item === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
if (value.every(item => typeof item === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) {
return value;
}
}
{{/isNumeric}}
{{#isString}}
if (Array.isArray(value)) {
if (value.every(item => typeof item === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
if (value.every(item => typeof item === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}item === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}})) {
return value;
}
}
Expand All @@ -205,22 +205,22 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
{{/isArray}}
{{^isArray}}
{{#isDateType}}
if(value instanceof Date) {
if (value instanceof Date) {
return ((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString().substring(0,10));
}
}
{{/isDateType}}
{{#isDateTimeType}}
if(value instanceof Date) {
if (value instanceof Date) {
return {{^required}}{{#isNullable}}value === null ? null : {{/isNullable}}{{^isNullable}}value == null ? undefined : {{/isNullable}}{{/required}}((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString());
}
{{/isDateTimeType}}
{{#isNumeric}}
if(typeof value === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}value === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
if (typeof value === 'number'{{#isEnum}} && ({{#allowableValues}}{{#values}}value === {{.}}{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
return value;
}
{{/isNumeric}}
{{#isString}}
if(typeof value === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}value === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
if (typeof value === 'string'{{#isEnum}} && ({{#allowableValues}}{{#values}}value === '{{.}}'{{^-last}} || {{/-last}}{{/values}}{{/allowableValues}}){{/isEnum}}) {
return value;
}
{{/isString}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,21 @@ public void givenSchemaIsOneOfAndComposedSchemasArePrimitiveThenReturnStatements

Path exampleModelPath = Paths.get(outputPath + "/models/MyCustomSpeed.ts");
//FromJSON
TestUtils.assertFileContains(exampleModelPath, "typeof json === 'number'");
TestUtils.assertFileContains(exampleModelPath, "typeof json === 'string'");
TestUtils.assertFileContains(exampleModelPath, "json === 'fixed-value-a' || json === 'fixed-value-b' || json === 'fixed-value-c'");
TestUtils.assertFileContains(exampleModelPath, "isNaN(new Date(json).getTime())");
TestUtils.assertFileContains(exampleModelPath, "json.every(item => typeof item === 'number'");
TestUtils.assertFileContains(exampleModelPath, "json.every(item => typeof item === 'string' && (item === 'oneof-array-enum-a' || item === 'oneof-array-enum-b' || item === 'oneof-array-enum-c')");
TestUtils.assertFileContains(exampleModelPath, "(typeof json !== 'object')");
TestUtils.assertFileContains(exampleModelPath, "(instanceOfMyNumericValue(json))");
TestUtils.assertFileContains(exampleModelPath, "(typeof json === 'number' && (json === 10 || json === 20 || json === 30))");
TestUtils.assertFileContains(exampleModelPath, "(typeof json === 'string' && (json === 'fixed-value-a' || json === 'fixed-value-b' || json === 'fixed-value-c'))");
TestUtils.assertFileContains(exampleModelPath, "(isNaN(new Date(json).getTime())");
TestUtils.assertFileContains(exampleModelPath, "(json.every(item => typeof item === 'number'))");
TestUtils.assertFileContains(exampleModelPath, "(json.every(item => typeof item === 'string' && (item === 'oneof-array-enum-a' || item === 'oneof-array-enum-b' || item === 'oneof-array-enum-c')))");
//ToJSON
TestUtils.assertFileContains(exampleModelPath, "typeof value === 'number'");
TestUtils.assertFileContains(exampleModelPath, "typeof value === 'string'");
TestUtils.assertFileContains(exampleModelPath, "value === 'fixed-value-a' || value === 'fixed-value-b' || value === 'fixed-value-c'");
TestUtils.assertFileContains(exampleModelPath, "value instanceof Date");
TestUtils.assertFileContains(exampleModelPath, "value.every(item => typeof item === 'number'");
TestUtils.assertFileContains(exampleModelPath, "value.every(item => typeof item === 'string' && (item === 'oneof-array-enum-a' || item === 'oneof-array-enum-b' || item === 'oneof-array-enum-c')");
TestUtils.assertFileContains(exampleModelPath, "(typeof value !== 'object')");
TestUtils.assertFileContains(exampleModelPath, "(instanceOfMyNumericValue(value))");
TestUtils.assertFileContains(exampleModelPath, "(typeof value === 'number' && (value === 10 || value === 20 || value === 30))");
TestUtils.assertFileContains(exampleModelPath, "(typeof value === 'string' && (value === 'fixed-value-a' || value === 'fixed-value-b' || value === 'fixed-value-c'))");
TestUtils.assertFileContains(exampleModelPath, "(value instanceof Date)");
TestUtils.assertFileContains(exampleModelPath, "(value.every(item => typeof item === 'number'))");
TestUtils.assertFileContains(exampleModelPath, "(value.every(item => typeof item === 'string' && (item === 'oneof-array-enum-a' || item === 'oneof-array-enum-b' || item === 'oneof-array-enum-c')))");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@SuppressWarnings("static-method")
public class TypeScriptFetchModelTest {

@Test(description = "convert a simple TypeScript Angular model")
@Test(description = "convert a simple TypeScript Fetch model")
public void simpleModelTest() {
final Schema model = new Schema()
.description("a sample model")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function TestArrayResponseFromJSONTyped(json: any, ignoreDiscriminator: b
if (json.every(item => typeof item === 'string')) {
return json;
}
}
}
return {} as any;
}

Expand All @@ -81,7 +81,7 @@ export function TestArrayResponseToJSONTyped(value?: TestArrayResponse | null, i
return value;
}
if (Array.isArray(value)) {
if (value.every(item => typeof item === 'string') {
if (value.every(item => typeof item === 'string')) {
return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function TestResponseFromJSONTyped(json: any, ignoreDiscriminator: boolea
if (instanceOfTestB(json)) {
return TestBFromJSONTyped(json, true);
}
if(typeof json === 'string') {
if (typeof json === 'string') {
return json;
}
return {} as any;
Expand All @@ -74,7 +74,7 @@ export function TestResponseToJSONTyped(value?: TestResponse | null, ignoreDiscr
if (instanceOfTestB(value)) {
return TestBToJSON(value as TestB);
}
if(typeof value === 'string') {
if (typeof value === 'string') {
return value;
}
return {};
Expand Down
Loading