-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[swift5/swift6] Fix oneOf decoding when enumUnknownDefaultCase is enabled #23496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,40 @@ extension {{projectName}}API { | |
| } | ||
| {{/swiftUseApiNamespace}}{{#models}}{{#model}}{{#vendorExtensions.x-swift-identifiable}} | ||
| extension {{#swiftUseApiNamespace}}{{projectName}}API.{{/swiftUseApiNamespace}}{{{classname}}}: Identifiable {} | ||
| {{/vendorExtensions.x-swift-identifiable}}{{/model}}{{/models}} | ||
| {{/vendorExtensions.x-swift-identifiable}}{{#enumUnknownDefaultCase}}{{^vendorExtensions.x-is-one-of-interface}}{{^isArray}}{{^isEnum}}{{#hasEnums}} | ||
| extension {{#swiftUseApiNamespace}}{{projectName}}API.{{/swiftUseApiNamespace}}{{{classname}}}: UnknownCaseCheckable { | ||
| {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var containsUnknownDefaultOpenApiCase: Bool { | ||
| {{#allVars}} | ||
| {{#isEnum}} | ||
| {{^isContainer}} | ||
| {{#vendorExtensions.x-null-encodable}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Unknown-case detection skips enums inside containers, so oneOf decoding can still accept a variant even when enum elements fell back to Prompt for AI agents |
||
| if {{{name}}} == .encodeValue(.unknownDefaultOpenApi) { return true } | ||
| {{/vendorExtensions.x-null-encodable}} | ||
| {{^vendorExtensions.x-null-encodable}} | ||
| if {{{name}}} == .unknownDefaultOpenApi { return true } | ||
| {{/vendorExtensions.x-null-encodable}} | ||
| {{/isContainer}} | ||
| {{/isEnum}} | ||
| {{^isEnum}} | ||
| {{#isEnumRef}} | ||
| {{^isContainer}} | ||
| {{#vendorExtensions.x-null-encodable}} | ||
| if {{{name}}} == .encodeValue(.unknownDefaultOpenApi) { return true } | ||
| {{/vendorExtensions.x-null-encodable}} | ||
| {{^vendorExtensions.x-null-encodable}} | ||
| if {{{name}}} == .unknownDefaultOpenApi { return true } | ||
| {{/vendorExtensions.x-null-encodable}} | ||
| {{/isContainer}} | ||
| {{/isEnumRef}} | ||
| {{/isEnum}} | ||
| {{/allVars}} | ||
| return false | ||
| } | ||
| } | ||
| {{/hasEnums}}{{/isEnum}}{{/isArray}}{{/vendorExtensions.x-is-one-of-interface}}{{#isEnum}} | ||
| extension {{#swiftUseApiNamespace}}{{projectName}}API.{{/swiftUseApiNamespace}}{{{classname}}}: UnknownCaseCheckable { | ||
| {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var containsUnknownDefaultOpenApiCase: Bool { | ||
| self == .unknownDefaultOpenApi | ||
| } | ||
| } | ||
| {{/isEnum}}{{/enumUnknownDefaultCase}}{{/model}}{{/models}} | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,3 +44,10 @@ internal struct EnumArrays: Codable, JSONEncodable { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| extension EnumArrays: UnknownCaseCheckable { | ||||||||||||||
| internal var containsUnknownDefaultOpenApiCase: Bool { | ||||||||||||||
| if justSymbol == .unknownDefaultOpenApi { return true } | ||||||||||||||
| return false | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+50
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: UnknownCaseCheckable ignores arrayEnum, so unknown enum defaults inside arrayEnum are not detected. Prompt for AI agents
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,3 +41,10 @@ internal struct EnumArrays: Sendable, Codable { | |
| } | ||
| } | ||
|
|
||
|
|
||
| extension EnumArrays: UnknownCaseCheckable { | ||
| internal var containsUnknownDefaultOpenApiCase: Bool { | ||
| if justSymbol == .unknownDefaultOpenApi { return true } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: UnknownCaseCheckable ignores arrayEnum, so unknown enum values in array_enum won’t be detected and oneOf discrimination can accept a variant based on unknown-enum fallback. Prompt for AI agents |
||
| return false | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: containsUnknownDefaultOpenApiCase skips enum containers, so unknown enum values inside arrays/maps are not detected and oneOf decoding can still accept the wrong variant.
Prompt for AI agents