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
4 changes: 2 additions & 2 deletions internal/sidekick/swift/generate_deprecated_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sidekick/swift/generate_deprecated_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func TestGenerateService_DeprecatedMethods(t *testing.T) {
},
{
start: " @available(*, deprecated)\n public func paginationMethodByItems(\n request: Request",
end: "-> some AsyncSequence<Item, Swift.Error> & Sendable",
want: " @available(*, deprecated)\n public func paginationMethodByItems(\n request: Request, options: GoogleGax.RequestOptions\n) -> some AsyncSequence<Item, Swift.Error> & Sendable",
end: "-> some AsyncSequence<Item, any Swift.Error> & Sendable",
want: " @available(*, deprecated)\n public func paginationMethodByItems(\n request: Request, options: GoogleGax.RequestOptions\n) -> some AsyncSequence<Item, any Swift.Error> & Sendable",
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions internal/sidekick/swift/generate_enum_swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/sidekick/swift/generate_field_swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/sidekick/swift/generate_method_signatures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestGenerateService_MethodSignatures(t *testing.T) {
want: `public func paginationMethodByItems(
name: Swift.String,
optionalField: Swift.String?,
) -> some AsyncSequence<Item, Swift.Error> & Sendable
) -> some AsyncSequence<Item, any Swift.Error> & Sendable
{
let request = Request().with {
$0.name = name
Expand All @@ -86,7 +86,7 @@ func TestGenerateService_MethodSignatures(t *testing.T) {
want: `public func paginationMethodByItems(
name: Swift.String,
normalField: Swift.String,
) -> some AsyncSequence<Item, Swift.Error> & Sendable
) -> some AsyncSequence<Item, any Swift.Error> & Sendable
{
let request = Request().with {
$0.name = name
Expand Down
8 changes: 4 additions & 4 deletions internal/sidekick/swift/generate_oneof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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`" + ` {
Expand Down
1 change: 1 addition & 0 deletions internal/sidekick/swift/generate_package_swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/sidekick/swift/generate_service_swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<Secret, Swift.Error> & Sendable
) -> some AsyncSequence<Secret, any Swift.Error> & Sendable
{
let listRpc = { @Sendable (token: Swift.String) async throws -> GoogleCloudSecretmanagerV1.ListSecretsResponse in
var request = request
Expand Down Expand Up @@ -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<Workflow>.State in",
"let poll = { @Sendable () async throws -> GoogleGax._PollableOperationImpl<Workflow>.State in",
Expand Down
2 changes: 1 addition & 1 deletion internal/sidekick/swift/generate_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bucket, Swift.Error> & Sendable") ||
!strings.Contains(protocolStr, "some AsyncSequence<Bucket, any Swift.Error> & Sendable") ||
!strings.Contains(protocolStr, "return GoogleGax.PaginatedResponseSequence(listRpc: listRpc, initialPageToken: request.pageToken)") {
t.Errorf("StorageControlProtocol.swift missing paginated helper method:\n%s", protocolStr)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sidekick/swift/templates/common/enum.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions internal/sidekick/swift/templates/common/message.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions internal/sidekick/swift/templates/common/string_enum.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ let package = Package(
],
{{- end }}
swiftSettings: [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
Expand Down
Loading