mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-13 16:03:43 +00:00
[Bug][typescript-fetch] Fix missing close parenthesis in oneOf models. (#21645)
* Modify unit tests for typescript-fetch, issue 21259 to check for closing parens & fix a typo in TypeScriptFetchModelTest * Fix bug in closing parens in modelOneOf.mustache and some spacing adjustments * Update samples --------- Co-authored-by: Chris Gual <cgual@omnidian.com>
This commit is contained in:
parent
815a7324e3
commit
7c1dce4756
@ -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}}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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}}
|
||||
|
@ -356,19 +356,21 @@ public class TypeScriptFetchClientCodegenTest {
|
||||
|
||||
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')))");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ import static io.swagger.codegen.utils.ModelUtils.updateCodegenPropertyEnum;
|
||||
@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")
|
||||
|
@ -57,7 +57,7 @@ export function TestArrayResponseFromJSONTyped(json: any, ignoreDiscriminator: b
|
||||
if (json.every(item => typeof item === 'string')) {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {} as any;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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 {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user