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
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user