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
23 changes: 16 additions & 7 deletions Sources/GRPCCodeGen/Internal/StructuredSwift+ServiceMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extension VariableDescription {
@available(gRPCSwift 2.0, *)
extension EnumDescription {
/// ```
/// enum <Method> {
/// enum <Method>: Sendable {
/// typealias Input = <InputType>
/// typealias Output = <OutputType>
/// static let descriptor = GRPCCore.MethodDescriptor(
Expand All @@ -209,6 +209,7 @@ extension EnumDescription {
return EnumDescription(
accessModifier: accessModifier,
name: name,
conformances: ["Sendable"],
members: [
.commentable(
.doc("Request type for \"\(literalMethod)\"."),
Expand All @@ -235,7 +236,7 @@ extension EnumDescription {

/// ```
/// enum Method {
/// enum <Method> {
/// enum <Method>: Sendable {
/// typealias Input = <MethodInput>
/// typealias Output = <MethodOutput>
/// static let descriptor = GRPCCore.MethodDescriptor(
Expand All @@ -256,7 +257,11 @@ extension EnumDescription {
methods: [MethodDescriptor],
namer: Namer = Namer()
) -> EnumDescription {
var description = EnumDescription(accessModifier: accessModifier, name: "Method")
var description = EnumDescription(
accessModifier: accessModifier,
name: "Method",
conformances: ["Sendable"]
)

// Add a namespace for each method.
let methodNamespaces: [Declaration] = methods.map { method in
Expand Down Expand Up @@ -294,9 +299,9 @@ extension EnumDescription {
}

/// ```
/// enum <Name> {
/// enum <Name>: Sendable {
/// static let descriptor = GRPCCore.ServiceDescriptor.<namespacedServicePropertyName>
/// enum Method {
/// enum Method: Sendable {
/// ...
/// }
/// }
Expand All @@ -308,7 +313,11 @@ extension EnumDescription {
methods: [MethodDescriptor],
namer: Namer = Namer()
) -> EnumDescription {
var description = EnumDescription(accessModifier: accessModifier, name: name)
var description = EnumDescription(
accessModifier: accessModifier,
name: name,
conformances: ["Sendable"]
)

// static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "...")
let descriptor = VariableDescription.serviceDescriptor(
Expand Down Expand Up @@ -344,7 +353,7 @@ extension EnumDescription {
@available(gRPCSwift 2.0, *)
extension [CodeBlock] {
/// ```
/// enum <Service> {
/// enum <Service>: Sendable {
/// ...
/// }
///
Expand Down
28 changes: 14 additions & 14 deletions Tests/GRPCCodeGenTests/Internal/StructuredSwift+MetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension StructuredSwiftTests {
#expect(render(.variable(decl)) == expected)
}

@Test("enum <Method> { ... }", arguments: AccessModifier.allCases)
@Test("enum <Method>: Sendable { ... }", arguments: AccessModifier.allCases)
@available(gRPCSwift 2.0, *)
func methodNamespaceEnum(access: AccessModifier) {
let decl: EnumDescription = .methodNamespace(
Expand All @@ -127,7 +127,7 @@ extension StructuredSwiftTests {
)

let expected = """
\(access) enum Foo {
\(access) enum Foo: Sendable {
/// Request type for "Foo".
\(access) typealias Input = FooInput
/// Response type for "Foo".
Expand All @@ -142,7 +142,7 @@ extension StructuredSwiftTests {
#expect(render(.enum(decl)) == expected)
}

@Test("enum Method { ... }", arguments: AccessModifier.allCases)
@Test("enum Method: Sendable { ... }", arguments: AccessModifier.allCases)
@available(gRPCSwift 2.0, *)
func methodsNamespaceEnum(access: AccessModifier) {
let decl: EnumDescription = .methodsNamespace(
Expand All @@ -161,9 +161,9 @@ extension StructuredSwiftTests {
)

let expected = """
\(access) enum Method {
\(access) enum Method: Sendable {
/// Namespace for "Foo" metadata.
\(access) enum Foo {
\(access) enum Foo: Sendable {
/// Request type for "Foo".
\(access) typealias Input = FooInput
/// Response type for "Foo".
Expand All @@ -183,7 +183,7 @@ extension StructuredSwiftTests {
#expect(render(.enum(decl)) == expected)
}

@Test("enum Method { ... } (no methods)", arguments: AccessModifier.allCases)
@Test("enum Method: Sendable { ... } (no methods)", arguments: AccessModifier.allCases)
@available(gRPCSwift 2.0, *)
func methodsNamespaceEnumNoMethods(access: AccessModifier) {
let decl: EnumDescription = .methodsNamespace(
Expand All @@ -193,15 +193,15 @@ extension StructuredSwiftTests {
)

let expected = """
\(access) enum Method {
\(access) enum Method: Sendable {
/// Descriptors for all methods in the "bar.Bar" service.
\(access) static let descriptors: [GRPCCore.MethodDescriptor] = []
}
"""
#expect(render(.enum(decl)) == expected)
}

@Test("enum <Service> { ... }", arguments: AccessModifier.allCases)
@Test("enum <Service>: Sendable { ... }", arguments: AccessModifier.allCases)
@available(gRPCSwift 2.0, *)
func serviceNamespaceEnum(access: AccessModifier) {
let decl: EnumDescription = .serviceNamespace(
Expand All @@ -221,13 +221,13 @@ extension StructuredSwiftTests {
)

let expected = """
\(access) enum Foo {
\(access) enum Foo: Sendable {
/// Service descriptor for the "Foo" service.
\(access) static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "Foo")
/// Namespace for method metadata.
\(access) enum Method {
\(access) enum Method: Sendable {
/// Namespace for "Bar" metadata.
\(access) enum Bar {
\(access) enum Bar: Sendable {
/// Request type for "Bar".
\(access) typealias Input = BarInput
/// Response type for "Bar".
Expand All @@ -248,7 +248,7 @@ extension StructuredSwiftTests {
#expect(render(.enum(decl)) == expected)
}

@Test("enum <Service> { ... } (no methods)", arguments: AccessModifier.allCases)
@Test("enum <Service>: Sendable { ... } (no methods)", arguments: AccessModifier.allCases)
@available(gRPCSwift 2.0, *)
func serviceNamespaceEnumNoMethods(access: AccessModifier) {
let decl: EnumDescription = .serviceNamespace(
Expand All @@ -259,11 +259,11 @@ extension StructuredSwiftTests {
)

let expected = """
\(access) enum Foo {
\(access) enum Foo: Sendable {
/// Service descriptor for the "Foo" service.
\(access) static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "Foo")
/// Namespace for method metadata.
\(access) enum Method {
\(access) enum Method: Sendable {
/// Descriptors for all methods in the "Foo" service.
\(access) static let descriptors: [GRPCCore.MethodDescriptor] = []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ final class IDLToStructuredSwiftTranslatorSnippetBasedTests: XCTestCase {

/// Namespace containing generated types for the "namespaceA.ServiceA" service.
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public enum NamespaceA_ServiceA {
public enum NamespaceA_ServiceA: Sendable {
/// Service descriptor for the "namespaceA.ServiceA" service.
public static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "namespaceA.ServiceA")
/// Namespace for method metadata.
public enum Method {
public enum Method: Sendable {
/// Descriptors for all methods in the "namespaceA.ServiceA" service.
public static let descriptors: [GRPCCore.MethodDescriptor] = []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ struct TypealiasTranslatorSnippetBasedTests {
let expectedSwift = """
/// Namespace containing generated types for the "namespaceA.ServiceA" service.
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
public enum NamespaceA_ServiceA {
public enum NamespaceA_ServiceA: Sendable {
/// Service descriptor for the "namespaceA.ServiceA" service.
public static let descriptor = GRPCCore.ServiceDescriptor(fullyQualifiedService: "namespaceA.ServiceA")
/// Namespace for method metadata.
public enum Method {
public enum Method: Sendable {
/// Namespace for "MethodA" metadata.
public enum MethodA {
public enum MethodA: Sendable {
/// Request type for "MethodA".
public typealias Input = NamespaceA_ServiceARequest
/// Response type for "MethodA".
Expand Down