[swift6] Add nonisolatedModels option for default MainActor isolation - #25004
Merged
4brunu merged 3 commits intoSep 25, 2026
Merged
Conversation
Adds a `nonisolatedModels` boolean option (default: false) to the swift6 generator. When enabled, generated model structs/classes/enums, the extensions emitted alongside them, and the supporting protocols and helper types they conform to or store (ParameterConvertible, CaseIterableDefaultsLast, UnknownCaseCheckable, NullEncodable, JSONValue, OpenAPIDateWithoutTime, the validation rule structs, CodableHelper, OpenAPIMutex, OpenISO8601DateFormatter, and the ParameterConvertible, CodingKey and Codable container extensions in Extensions.swift) are marked `nonisolated`. This lets the generated sources be vendored into a module built with Swift 6.2 default MainActor isolation (SE-0466) while keeping models decodable and usable off the main actor. Requires a Swift 6.1+ toolchain when enabled; output is unchanged when the option is off. Enabled in the swift6 validation sample. Fixes OpenAPITools#24903 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
danieldickison
marked this pull request as ready for review
September 23, 2026 20:31
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 26 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
|
Can you please take a look at the comments? Thanks |
Review flagged that objcCompatible model classes were left MainActor-isolated while their Identifiable/UnknownCaseCheckable extensions were marked nonisolated, which fails to compile under default MainActor isolation. Mark the objcCompatible class declaration nonisolated too (verified to build with 0 errors), and add tests for top-level, nested and oneOf enums and objcCompatible. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was generated by Claude Code but I've looked through the changes and it all looks reasonable to me.
Fixes #24903
Adds a
nonisolatedModelsboolean option (default:false) to the swift6 generator.Swift 6.2 lets a module opt into main-actor isolation by default (SE-0466,
-default-isolation MainActor;SWIFT_DEFAULT_ACTOR_ISOLATION = MainActorin Xcode 26). When generated sources are vendored into such a module, every model becomes@MainActor-isolated, so theirCodableconformances can't be used from URLSession completions, background tasks, or any other nonisolated context ("conformance of 'Foo' to protocol 'Decodable' crosses into main actor-isolated code").With
nonisolatedModels: true, the generator marks the followingnonisolated:struct/final class/enumdeclarations (including theobjcCompatibleNSObject subclasses), and theIdentifiable/UnknownCaseCheckableextensions emitted next to themParameterConvertible,CaseIterableDefaultsLast,UnknownCaseCheckable,NullEncodable,JSONValue,OpenAPIDateWithoutTime, the validation rule structsParameterConvertibleconformances and theCodingKey/ keyed-container extensions inExtensions.swiftCodableHelper,OpenAPIMutexandOpenISO8601DateFormatter, which the above depend onOutput is byte-identical when the option is off (all 14 swift6 sample configs were regenerated; only
validation, where the option is now enabled, changed). Enabling the option requires a Swift 6.1+ toolchain (nonisolatedon types and extensions, SE-0449).Scope note: the API layer (
APIs.swift,URLSessionImplementations.swift,RequestTask) is unchanged and still assumes a nonisolated module. This option targets the model layer, per the issue.Note on
objcCompatiblemodels: the option is isolation-neutral for them. Those classes are already declared@unchecked Sendablewith mutable properties, andnonisolatedonly removes a main-actor guarantee that Objective-C callers never honored anyway. It does not make them more or less thread-safe than they are today; the safe usage pattern (decode, then treat as read-only when shared, or usereadonlyProperties) is unchanged.Testing
Swift6*unit tests pass (50 run, 0 failures), including two new generation tests asserting thenonisolatedoutput with the option on and its absence with the option off.validationsample and the other swift6 samples with Swift 6.4: all 13 directories in thesamples-swift6.yamlmacOS matrix (alamofireLibrary, apiNonStaticMethod, asyncAwaitLibrary, combineDeferredLibrary, combineLibrary, default, objcCompatible, oneOf, promisekitLibrary, resultLibrary, rxswiftLibrary, urlsessionLibrary, validation) passswift build..defaultIsolation(MainActor.self)in a scratch package (API layer excluded): 0 diagnostics in model and support files with the option on. With the option off, the same builds fail with e.g.conformance of 'Banana' to 'Decodable' cannot be used in nonisolated contextandconformance of 'EnumClass' to protocol 'CaseIterableDefaultsLast' crosses into main actor-isolated code../mvnw verifyonmodules/openapi-generator: BUILD SUCCESS (checkstyle, jacoco check, javadoc, forbiddenapis all pass); surefire 5134 run, 0 failures, 12 skipped. On my local JDK 25 there are 8 errors inKotlinTestUtilsTest/KotlinSpringServerCodegenTest(the embedded Kotlin compiler can't parse the JDK version string25.0.3); those two classes pass on JDK 21 (288 run, 0 failures, 0 errors), and this change doesn't touch them.PR checklist
./mvnw clean package,./bin/generate-samples.sh bin/configs/swift6-*.yamland./bin/utils/export_docs_generators.sh; all changed files are committed.🤖 Generated with Claude Code
Summary by cubic
Adds a
nonisolatedModelsoption to the swift6 generator so generated sources stay usable when vendored into modules built with Swift 6.2 default MainActor isolation (SE-0466). Fixes #24903.Identifiable/UnknownCaseCheckableextensions, supporting protocols and helpers, andobjcCompatibleclassesnonisolated; requires a Swift 6.1+ toolchain.objcCompatiblemodels.Written for commit 37202c0. Summary will update on new commits.