Skip to content

Commit de4e09e

Browse files
Update instanceOfType metthod
1 parent 8e7a128 commit de4e09e

18 files changed

Lines changed: 36 additions & 162 deletions

File tree

modules/openapi-generator/src/main/resources/typescript/model/TypeMatcher.mustache

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ import { AttributeTypeMapEntry } from '../models/ModelTypes{{importFileExtension
99
*/
1010
export function instanceOfType(data: any, attributeTypeMap: Array<AttributeTypeMapEntry>): boolean {
1111
for (const attribute of attributeTypeMap) {
12-
if (attribute.required) {
13-
// Check both that the property exists AND that it's not undefined.
14-
// This is important because `data[attribute.baseName] === undefined` alone
15-
// would be true for both missing properties and properties explicitly set to undefined,
16-
// while `!(attribute.baseName in data)` distinguishes between these cases.
17-
// For proper OpenAPI validation, required fields must actually be present in the data.
18-
if (!(attribute.baseName in data) || data[attribute.baseName] === undefined) {
19-
return false;
20-
}
12+
if (attribute.required && data[attribute.baseName] === undefined) {
13+
return false;
2114
}
2215
}
2316

samples/client/echo_api/typescript/build/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/array-of-lists/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/enum-single-value/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/null-types-simple/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/with-unique-items/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/encode-decode/build/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/browser/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/composed-schemas/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/typescript/builds/default/models/TypeMatcher.ts

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)