mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-14 00:13:50 +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
@ -100,24 +100,24 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
|
|||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{^isArray}}
|
{{^isArray}}
|
||||||
{{#isDateType}}
|
{{#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));
|
return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}new Date(json));
|
||||||
}
|
}
|
||||||
{{/isDateType}}
|
{{/isDateType}}
|
||||||
{{^isDateType}}
|
{{^isDateType}}
|
||||||
{{#isDateTimeType}}
|
{{#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));
|
return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}new Date(json));
|
||||||
}
|
}
|
||||||
{{/isDateTimeType}}
|
{{/isDateTimeType}}
|
||||||
{{/isDateType}}
|
{{/isDateType}}
|
||||||
{{#isNumeric}}
|
{{#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;
|
return json;
|
||||||
}
|
}
|
||||||
{{/isNumeric}}
|
{{/isNumeric}}
|
||||||
{{#isString}}
|
{{#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;
|
return json;
|
||||||
}
|
}
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
@ -189,14 +189,14 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
|
|||||||
{{/isDateTimeType}}
|
{{/isDateTimeType}}
|
||||||
{{#isNumeric}}
|
{{#isNumeric}}
|
||||||
if (Array.isArray(value)) {
|
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;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/isNumeric}}
|
{{/isNumeric}}
|
||||||
{{#isString}}
|
{{#isString}}
|
||||||
if (Array.isArray(value)) {
|
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;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,22 +205,22 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
|
|||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{^isArray}}
|
{{^isArray}}
|
||||||
{{#isDateType}}
|
{{#isDateType}}
|
||||||
if(value instanceof Date) {
|
if (value instanceof Date) {
|
||||||
return ((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString().substring(0,10));
|
return ((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString().substring(0,10));
|
||||||
}
|
}
|
||||||
{{/isDateType}}
|
{{/isDateType}}
|
||||||
{{#isDateTimeType}}
|
{{#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());
|
return {{^required}}{{#isNullable}}value === null ? null : {{/isNullable}}{{^isNullable}}value == null ? undefined : {{/isNullable}}{{/required}}((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString());
|
||||||
}
|
}
|
||||||
{{/isDateTimeType}}
|
{{/isDateTimeType}}
|
||||||
{{#isNumeric}}
|
{{#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;
|
return value;
|
||||||
}
|
}
|
||||||
{{/isNumeric}}
|
{{/isNumeric}}
|
||||||
{{#isString}}
|
{{#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;
|
return value;
|
||||||
}
|
}
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
|
@ -356,19 +356,21 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
|
|
||||||
Path exampleModelPath = Paths.get(outputPath + "/models/MyCustomSpeed.ts");
|
Path exampleModelPath = Paths.get(outputPath + "/models/MyCustomSpeed.ts");
|
||||||
//FromJSON
|
//FromJSON
|
||||||
TestUtils.assertFileContains(exampleModelPath, "typeof json === 'number'");
|
TestUtils.assertFileContains(exampleModelPath, "(typeof json !== 'object')");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "typeof json === 'string'");
|
TestUtils.assertFileContains(exampleModelPath, "(instanceOfMyNumericValue(json))");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "json === 'fixed-value-a' || json === 'fixed-value-b' || json === 'fixed-value-c'");
|
TestUtils.assertFileContains(exampleModelPath, "(typeof json === 'number' && (json === 10 || json === 20 || json === 30))");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "isNaN(new Date(json).getTime())");
|
TestUtils.assertFileContains(exampleModelPath, "(typeof json === 'string' && (json === 'fixed-value-a' || json === 'fixed-value-b' || json === 'fixed-value-c'))");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "json.every(item => typeof item === 'number'");
|
TestUtils.assertFileContains(exampleModelPath, "(isNaN(new Date(json).getTime())");
|
||||||
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, "(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
|
//ToJSON
|
||||||
TestUtils.assertFileContains(exampleModelPath, "typeof value === 'number'");
|
TestUtils.assertFileContains(exampleModelPath, "(typeof value !== 'object')");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "typeof value === 'string'");
|
TestUtils.assertFileContains(exampleModelPath, "(instanceOfMyNumericValue(value))");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "value === 'fixed-value-a' || value === 'fixed-value-b' || value === 'fixed-value-c'");
|
TestUtils.assertFileContains(exampleModelPath, "(typeof value === 'number' && (value === 10 || value === 20 || value === 30))");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "value instanceof Date");
|
TestUtils.assertFileContains(exampleModelPath, "(typeof value === 'string' && (value === 'fixed-value-a' || value === 'fixed-value-b' || value === 'fixed-value-c'))");
|
||||||
TestUtils.assertFileContains(exampleModelPath, "value.every(item => typeof item === 'number'");
|
TestUtils.assertFileContains(exampleModelPath, "(value instanceof Date)");
|
||||||
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, "(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")
|
@SuppressWarnings("static-method")
|
||||||
public class TypeScriptFetchModelTest {
|
public class TypeScriptFetchModelTest {
|
||||||
|
|
||||||
@Test(description = "convert a simple TypeScript Angular model")
|
@Test(description = "convert a simple TypeScript Fetch model")
|
||||||
public void simpleModelTest() {
|
public void simpleModelTest() {
|
||||||
final Schema model = new Schema()
|
final Schema model = new Schema()
|
||||||
.description("a sample model")
|
.description("a sample model")
|
||||||
|
@ -81,7 +81,7 @@ export function TestArrayResponseToJSONTyped(value?: TestArrayResponse | null, i
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
if (value.every(item => typeof item === 'string') {
|
if (value.every(item => typeof item === 'string')) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ export function TestResponseFromJSONTyped(json: any, ignoreDiscriminator: boolea
|
|||||||
if (instanceOfTestB(json)) {
|
if (instanceOfTestB(json)) {
|
||||||
return TestBFromJSONTyped(json, true);
|
return TestBFromJSONTyped(json, true);
|
||||||
}
|
}
|
||||||
if(typeof json === 'string') {
|
if (typeof json === 'string') {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
return {} as any;
|
return {} as any;
|
||||||
@ -74,7 +74,7 @@ export function TestResponseToJSONTyped(value?: TestResponse | null, ignoreDiscr
|
|||||||
if (instanceOfTestB(value)) {
|
if (instanceOfTestB(value)) {
|
||||||
return TestBToJSON(value as TestB);
|
return TestBToJSON(value as TestB);
|
||||||
}
|
}
|
||||||
if(typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user