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 @@ -32,6 +32,7 @@ export function instanceOf{{classname}}(value: object): value is {{classname}} {
if (!('{{name}}' in value) || value['{{name}}'] === undefined) return false;
{{/hasSanitizedName}}
{{#isEnum}}
{{^isContainer}}
{{#allowableValues}}
{{#values}}
{{#-first}}
Expand All @@ -48,6 +49,7 @@ export function instanceOf{{classname}}(value: object): value is {{classname}} {
{{/-first}}
{{/values}}
{{/allowableValues}}
{{/isContainer}}
{{/isEnum}}
{{/required}}
{{/vars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,21 @@ public void testNestedOneOfGeneratesTypeAliasForOneOfParent() throws IOException
TestUtils.assertFileContains(outerPlain, "export interface OuterPlain {");
}

@Test(description = "instanceOf guard must not emit scalar enum comparison for array-typed enum properties")
public void testInstanceOfArrayEnumNoScalarComparison() throws Exception {
File output = generate(
Collections.emptyMap(),
"src/test/resources/3_0/typescript-fetch/array_of_single_value_enum.json"
);

Path modelPath = Paths.get(output + "/models/TestSchema.ts");
// Must NOT emit a scalar !== comparison for an array-typed enum property
TestUtils.assertFileNotContains(modelPath, "value['types'] !== 'boatbooker_activities'");
TestUtils.assertFileNotContains(modelPath, "value['types'] !== boatbooker_activities");
// Must still check for presence of the field
TestUtils.assertFileContains(modelPath, "'types' in value");
}

@Test(description = "Optional nullable fields should deserialize to null, not undefined (fix #5670)")
public void testOptionalNullableFieldDeserializesToNull() throws Exception {
File output = generate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"openapi": "3.0.1",
"info": {
"title": "Array of Single-Value Enum Test",
"version": "1.0.0"
},
"paths": {},
"components": {
"schemas": {
"TestSchema": {
"required": ["types"],
"type": "object",
"properties": {
"types": {
"type": "array",
"items": {
"type": "string",
"enum": ["boatbooker_activities"]
}
}
}
}
}
}
}
Loading