diff --git a/internal/sidekick/swift/generate_deprecated_message_test.go b/internal/sidekick/swift/generate_deprecated_message_test.go index bf674c06a0..5148677f3b 100644 --- a/internal/sidekick/swift/generate_deprecated_message_test.go +++ b/internal/sidekick/swift/generate_deprecated_message_test.go @@ -162,8 +162,8 @@ func TestGenerateMessage_Diagnose(t *testing.T) { } contentStr := string(content) - checkDiagnose(t, contentStr, " ", "public init(from decoder: Decoder) throws {", test.want) - checkDiagnose(t, contentStr, " ", "public func encode(to encoder: Encoder) throws {", test.want) + checkDiagnose(t, contentStr, " ", "public init(from decoder: any Decoder) throws {", test.want) + checkDiagnose(t, contentStr, " ", "public func encode(to encoder: any Encoder) throws {", test.want) }) } } diff --git a/internal/sidekick/swift/generate_deprecated_method_test.go b/internal/sidekick/swift/generate_deprecated_method_test.go index fd3f1de15c..3137a0c37a 100644 --- a/internal/sidekick/swift/generate_deprecated_method_test.go +++ b/internal/sidekick/swift/generate_deprecated_method_test.go @@ -124,8 +124,8 @@ func TestGenerateService_DeprecatedMethods(t *testing.T) { }, { start: " @available(*, deprecated)\n public func paginationMethodByItems(\n request: Request", - end: "-> some AsyncSequence & Sendable", - want: " @available(*, deprecated)\n public func paginationMethodByItems(\n request: Request, options: GoogleGax.RequestOptions\n) -> some AsyncSequence & Sendable", + end: "-> some AsyncSequence & Sendable", + want: " @available(*, deprecated)\n public func paginationMethodByItems(\n request: Request, options: GoogleGax.RequestOptions\n) -> some AsyncSequence & Sendable", }, }, }, diff --git a/internal/sidekick/swift/generate_enum_swift_test.go b/internal/sidekick/swift/generate_enum_swift_test.go index f67c5e7ab8..640aa23691 100644 --- a/internal/sidekick/swift/generate_enum_swift_test.go +++ b/internal/sidekick/swift/generate_enum_swift_test.go @@ -103,8 +103,8 @@ func TestGenerateEnum_UniqueNumbers(t *testing.T) { t.Errorf("mismatch (-want +got):\n%s", diff) } - gotEncode := extractBlock(t, string(contentsB), "public func encode(to encoder: Encoder) throws {", "\n }") - wantEncode := `public func encode(to encoder: Encoder) throws { + gotEncode := extractBlock(t, string(contentsB), "public func encode(to encoder: any Encoder) throws {", "\n }") + wantEncode := `public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() switch self { case .test: return try container.encode("KIND_TEST") @@ -321,18 +321,18 @@ func TestGenerateEnum_Discovery(t *testing.T) { } // Verify decoder - wantDecoder := ` public init(from decoder: Decoder) throws { + wantDecoder := ` public init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() let s = try container.decode(Swift.String.self) self.init(stringValue: s) }` - gotDecoder := extractBlock(t, contentStr, " public init(from decoder: Decoder) throws {", "\n }") + gotDecoder := extractBlock(t, contentStr, " public init(from decoder: any Decoder) throws {", "\n }") if diff := cmp.Diff(wantDecoder, gotDecoder); diff != "" { t.Errorf("mismatch (-want +got):\n%s", diff) } // Verify encoder - wantEncoder := ` public func encode(to encoder: Encoder) throws { + wantEncoder := ` public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() switch self { case .done: return try container.encode("DONE") @@ -341,7 +341,7 @@ func TestGenerateEnum_Discovery(t *testing.T) { case .unknownStringValue(let v): return try container.encode(v) } }` - gotEncoder := extractBlock(t, contentStr, " public func encode(to encoder: Encoder) throws {", "\n }") + gotEncoder := extractBlock(t, contentStr, " public func encode(to encoder: any Encoder) throws {", "\n }") if diff := cmp.Diff(wantEncoder, gotEncoder); diff != "" { t.Errorf("mismatch (-want +got):\n%s", diff) } diff --git a/internal/sidekick/swift/generate_field_swift_test.go b/internal/sidekick/swift/generate_field_swift_test.go index 2c6c9083d4..a1d8dfda81 100644 --- a/internal/sidekick/swift/generate_field_swift_test.go +++ b/internal/sidekick/swift/generate_field_swift_test.go @@ -63,9 +63,9 @@ func TestGenerateField_InitFromDecoder(t *testing.T) { } contentStr := string(content) - // Verify init(from decoder: Decoder) content - gotBlock := extractBlock(t, contentStr, " public init(from decoder: Decoder) throws {", "\n }") - wantBlock := ` public init(from decoder: Decoder) throws { + // Verify init(from decoder: any Decoder) content + gotBlock := extractBlock(t, contentStr, " public init(from decoder: any Decoder) throws {", "\n }") + wantBlock := ` public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) if let value = try container.decodeIfPresent(Swift.String.self, forKey: .normalField) { self.normalField = value diff --git a/internal/sidekick/swift/generate_method_signatures_test.go b/internal/sidekick/swift/generate_method_signatures_test.go index 92909468ad..e3e2c02b18 100644 --- a/internal/sidekick/swift/generate_method_signatures_test.go +++ b/internal/sidekick/swift/generate_method_signatures_test.go @@ -72,7 +72,7 @@ func TestGenerateService_MethodSignatures(t *testing.T) { want: `public func paginationMethodByItems( name: Swift.String, optionalField: Swift.String?, -) -> some AsyncSequence & Sendable +) -> some AsyncSequence & Sendable { let request = Request().with { $0.name = name @@ -86,7 +86,7 @@ func TestGenerateService_MethodSignatures(t *testing.T) { want: `public func paginationMethodByItems( name: Swift.String, normalField: Swift.String, -) -> some AsyncSequence & Sendable +) -> some AsyncSequence & Sendable { let request = Request().with { $0.name = name diff --git a/internal/sidekick/swift/generate_oneof_test.go b/internal/sidekick/swift/generate_oneof_test.go index e4fe3e9486..2ea9fb997b 100644 --- a/internal/sidekick/swift/generate_oneof_test.go +++ b/internal/sidekick/swift/generate_oneof_test.go @@ -140,7 +140,7 @@ func TestGenerateOneOf(t *testing.T) { ] } - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) if let value = try container.decodeIfPresent(Swift.Int32.self, forKey: .regularInt32) { self.regularInt32 = value @@ -169,7 +169,7 @@ func TestGenerateOneOf(t *testing.T) { } } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(self.regularInt32, forKey: .regularInt32) try container.encode(self.regularString, forKey: .regularString) @@ -299,7 +299,7 @@ func TestGenerateOneOfWithKeyword(t *testing.T) { ] } - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) var ` + "`in`" + `: InOneOf? = nil @@ -325,7 +325,7 @@ func TestGenerateOneOfWithKeyword(t *testing.T) { } } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) if let choice = self.` + "`in`" + ` { diff --git a/internal/sidekick/swift/generate_package_swift_test.go b/internal/sidekick/swift/generate_package_swift_test.go index d43220b86b..832f517e9c 100644 --- a/internal/sidekick/swift/generate_package_swift_test.go +++ b/internal/sidekick/swift/generate_package_swift_test.go @@ -98,6 +98,7 @@ func TestGeneratePackageSwift_WithDependencies(t *testing.T) { gotSwiftSettings := extractBlock(t, contentStr, " swiftSettings: [", "\n ]") wantSwiftSettings := ` swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), .enableUpcomingFeature("InternalImportsByDefault"), .enableUpcomingFeature("MemberImportVisibility"), .enableUpcomingFeature("NonisolatedNonsendingByDefault"), diff --git a/internal/sidekick/swift/generate_pagination_swift_test.go b/internal/sidekick/swift/generate_pagination_swift_test.go index 6e83c5b785..697686ac00 100644 --- a/internal/sidekick/swift/generate_pagination_swift_test.go +++ b/internal/sidekick/swift/generate_pagination_swift_test.go @@ -129,7 +129,7 @@ func verifyGeneratedMapService(t *testing.T, outDir string) { request: `, "\n }") wantMethodOverload := ` public func listSecretsByItems( request: ListSecretsRequest, options: GoogleGax.RequestOptions -) -> some AsyncSequence<(Swift.String, Secret), Swift.Error> & Sendable +) -> some AsyncSequence<(Swift.String, Secret), any Swift.Error> & Sendable { let listRpc = { @Sendable (token: Swift.String) async throws -> GoogleCloudSecretmanagerV1.ListSecretsResponse in var request = request diff --git a/internal/sidekick/swift/generate_service_swift_test.go b/internal/sidekick/swift/generate_service_swift_test.go index 7da452999a..11fc3b83d7 100644 --- a/internal/sidekick/swift/generate_service_swift_test.go +++ b/internal/sidekick/swift/generate_service_swift_test.go @@ -627,7 +627,7 @@ func verifyGeneratedService(t *testing.T, outDir string) { request: ListSecretsRequest, options: `, "\n }") wantMethodOverload := ` public func listSecretsByItems( request: ListSecretsRequest, options: GoogleGax.RequestOptions -) -> some AsyncSequence & Sendable +) -> some AsyncSequence & Sendable { let listRpc = { @Sendable (token: Swift.String) async throws -> GoogleCloudSecretmanagerV1.ListSecretsResponse in var request = request @@ -783,8 +783,8 @@ func TestGenerateService_LRO(t *testing.T) { wantContains := []string{ "public import GoogleCloudLongrunningV1", - "let pollingErrorPolicy: GoogleGax.PollingErrorPolicy", - "let pollingBackoffPolicy: GoogleGax.PollingBackoffPolicy", + "let pollingErrorPolicy: any GoogleGax.PollingErrorPolicy", + "let pollingBackoffPolicy: any GoogleGax.PollingBackoffPolicy", "public func createWorkflowPollingUntilDone(request: CreateWorkflowRequest) async throws -> Workflow", "let extractStatus = { @Sendable (op: GoogleCloudLongrunningV1.Operation) throws -> GoogleGax._PollableOperationImpl.State in", "let poll = { @Sendable () async throws -> GoogleGax._PollableOperationImpl.State in", diff --git a/internal/sidekick/swift/generate_storage_test.go b/internal/sidekick/swift/generate_storage_test.go index 249c43409c..21d88cc0ec 100644 --- a/internal/sidekick/swift/generate_storage_test.go +++ b/internal/sidekick/swift/generate_storage_test.go @@ -202,7 +202,7 @@ func TestGenerateStorage_MultiModel(t *testing.T) { t.Errorf("StorageControlProtocol.swift missing unified methods:\n%s", protocolStr) } if !strings.Contains(protocolStr, "request: ListBucketsRequest, options: GoogleGax.RequestOptions") || - !strings.Contains(protocolStr, "some AsyncSequence & Sendable") || + !strings.Contains(protocolStr, "some AsyncSequence & Sendable") || !strings.Contains(protocolStr, "return GoogleGax.PaginatedResponseSequence(listRpc: listRpc, initialPageToken: request.pageToken)") { t.Errorf("StorageControlProtocol.swift missing paginated helper method:\n%s", protocolStr) } diff --git a/internal/sidekick/swift/templates/common/enum.gotmpl b/internal/sidekick/swift/templates/common/enum.gotmpl index 1e78cc12aa..a47110cd6c 100644 --- a/internal/sidekick/swift/templates/common/enum.gotmpl +++ b/internal/sidekick/swift/templates/common/enum.gotmpl @@ -119,7 +119,7 @@ public enum {{ .Codec.Name }}: Codable, Equatable, Hashable, Sendable { } } - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() if let v = try? container.decode(Int.self) { self.init(intValue: v) @@ -137,7 +137,7 @@ public enum {{ .Codec.Name }}: Codable, Equatable, Hashable, Sendable { in: container, debugDescription: "Expected enum value, must be integer or string.") } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() switch self { {{- range .UniqueNumberValues }} diff --git a/internal/sidekick/swift/templates/common/message.gotmpl b/internal/sidekick/swift/templates/common/message.gotmpl index cdcab8ce69..a498e1e876 100644 --- a/internal/sidekick/swift/templates/common/message.gotmpl +++ b/internal/sidekick/swift/templates/common/message.gotmpl @@ -101,7 +101,7 @@ public struct {{ .Codec.Name }}: Codable, Equatable, {{ .Codec.Model.WktPackage {{- if .Codec.DiagnoseCodable }} {{- include "templates/common/diagnose" . | indent 2 }} {{- end }} - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) {{- range .Fields }} {{- if not .IsOneOf }} @@ -137,7 +137,7 @@ public struct {{ .Codec.Name }}: Codable, Equatable, {{ .Codec.Model.WktPackage {{- if .Codec.DiagnoseCodable }} {{- include "templates/common/diagnose" . | indent 2 }} {{- end }} - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) {{- range .Fields }} {{- if not .IsOneOf }} diff --git a/internal/sidekick/swift/templates/common/method_signature/pagination.gotmpl b/internal/sidekick/swift/templates/common/method_signature/pagination.gotmpl index 310b42047f..cedf8215d9 100644 --- a/internal/sidekick/swift/templates/common/method_signature/pagination.gotmpl +++ b/internal/sidekick/swift/templates/common/method_signature/pagination.gotmpl @@ -15,4 +15,4 @@ limitations under the License. */ -}} {{ .Codec.Name }}ByItems( request: {{ .InputType.Codec.ParameterTypeName }} -) -> some AsyncSequence<{{ .OutputType.Codec.PageableItemType }}, Swift.Error> & Sendable +) -> some AsyncSequence<{{ .OutputType.Codec.PageableItemType }}, any Swift.Error> & Sendable diff --git a/internal/sidekick/swift/templates/common/method_signature/pagination_options.gotmpl b/internal/sidekick/swift/templates/common/method_signature/pagination_options.gotmpl index 49e9e4bec3..7197a99b6a 100644 --- a/internal/sidekick/swift/templates/common/method_signature/pagination_options.gotmpl +++ b/internal/sidekick/swift/templates/common/method_signature/pagination_options.gotmpl @@ -15,4 +15,4 @@ limitations under the License. */ -}} {{ .Codec.Name }}ByItems( request: {{ .InputType.Codec.ParameterTypeName }}, options: GoogleGax.RequestOptions -) -> some AsyncSequence<{{ .OutputType.Codec.PageableItemType }}, Swift.Error> & Sendable +) -> some AsyncSequence<{{ .OutputType.Codec.PageableItemType }}, any Swift.Error> & Sendable diff --git a/internal/sidekick/swift/templates/common/method_signature/pagination_overload.gotmpl b/internal/sidekick/swift/templates/common/method_signature/pagination_overload.gotmpl index 9faf86a24d..926400b49a 100644 --- a/internal/sidekick/swift/templates/common/method_signature/pagination_overload.gotmpl +++ b/internal/sidekick/swift/templates/common/method_signature/pagination_overload.gotmpl @@ -17,4 +17,4 @@ limitations under the License. {{- range .Fields }} {{ .Codec.Name }}: {{ .Codec.FieldType }}, {{- end }} -) -> some AsyncSequence<{{ .Method.OutputType.Codec.PageableItemType }}, Swift.Error> & Sendable +) -> some AsyncSequence<{{ .Method.OutputType.Codec.PageableItemType }}, any Swift.Error> & Sendable diff --git a/internal/sidekick/swift/templates/common/service.swift.gotmpl b/internal/sidekick/swift/templates/common/service.swift.gotmpl index 6fa819704e..33ece6165d 100644 --- a/internal/sidekick/swift/templates/common/service.swift.gotmpl +++ b/internal/sidekick/swift/templates/common/service.swift.gotmpl @@ -48,8 +48,8 @@ import Foundation public final class {{ .Codec.ClientName }}: Clients.{{ .Codec.StubPrefix }}Protocol, Sendable { let inner: any Clients.{{ .Codec.StubPrefix }}Stub {{- if .Codec.HasLROs }} - let pollingErrorPolicy: GoogleGax.PollingErrorPolicy - let pollingBackoffPolicy: GoogleGax.PollingBackoffPolicy + let pollingErrorPolicy: any GoogleGax.PollingErrorPolicy + let pollingBackoffPolicy: any GoogleGax.PollingBackoffPolicy {{- end }} /// Creates a new `{{ .Codec.ClientName }}` instance. diff --git a/internal/sidekick/swift/templates/common/string_enum.gotmpl b/internal/sidekick/swift/templates/common/string_enum.gotmpl index ce53993475..2c5740b316 100644 --- a/internal/sidekick/swift/templates/common/string_enum.gotmpl +++ b/internal/sidekick/swift/templates/common/string_enum.gotmpl @@ -72,13 +72,13 @@ public enum {{ .Codec.Name }}: Codable, Equatable, Hashable, Sendable { } } - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() let s = try container.decode(Swift.String.self) self.init(stringValue: s) } - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() switch self { {{- range .Values }} diff --git a/internal/sidekick/swift/templates/package/Package.swift.gotmpl b/internal/sidekick/swift/templates/package/Package.swift.gotmpl index 08afe33dd2..ccd5aff78e 100644 --- a/internal/sidekick/swift/templates/package/Package.swift.gotmpl +++ b/internal/sidekick/swift/templates/package/Package.swift.gotmpl @@ -81,6 +81,7 @@ let package = Package( ], {{- end }} swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), .enableUpcomingFeature("InternalImportsByDefault"), .enableUpcomingFeature("MemberImportVisibility"), .enableUpcomingFeature("NonisolatedNonsendingByDefault"),