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
32 changes: 16 additions & 16 deletions Sources/GRPCCodeGen/Internal/Translator/ClientCodeTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
/// ```swift
/// public protocol Foo_BarClientProtocol: Sendable {
/// func baz<R: Sendable>(
/// request: ClientRequest.Single<foo.Bar.Methods.baz.Input>,
/// serializer: some MessageSerializer<foo.Bar.Methods.baz.Input>,
/// deserializer: some MessageDeserializer<foo.Bar.Methods.baz.Output>,
/// _ body: @Sendable @escaping (ClientResponse.Single<foo.Bar.Methods.Baz.Output>) async throws -> R
/// ) async throws -> ServerResponse.Stream<foo.Bar.Methods.Baz.Output>
/// request: ClientRequest.Single<foo.Bar.Method.baz.Input>,
/// serializer: some MessageSerializer<foo.Bar.Method.baz.Input>,
/// deserializer: some MessageDeserializer<foo.Bar.Method.baz.Output>,
/// _ body: @Sendable @escaping (ClientResponse.Single<foo.Bar.Method.Baz.Output>) async throws -> R
/// ) async throws -> ServerResponse.Stream<foo.Bar.Method.Baz.Output>
/// }
/// extension Foo.Bar.ClientProtocol {
/// public func get<R: Sendable>(
/// request: ClientRequest.Single<Foo.Bar.Methods.Baz.Input>,
/// _ body: @Sendable @escaping (ClientResponse.Single<Foo.Bar.Methods.Baz.Output>) async throws -> R
/// request: ClientRequest.Single<Foo.Bar.Method.Baz.Input>,
/// _ body: @Sendable @escaping (ClientResponse.Single<Foo.Bar.Method.Baz.Output>) async throws -> R
/// ) async rethrows -> R {
/// try await self.baz(
/// request: request,
/// serializer: ProtobufSerializer<Foo.Bar.Methods.Baz.Input>(),
/// deserializer: ProtobufDeserializer<Foo.Bar.Methods.Baz.Output>(),
/// serializer: ProtobufSerializer<Foo.Bar.Method.Baz.Input>(),
/// deserializer: ProtobufDeserializer<Foo.Bar.Method.Baz.Output>(),
/// body
/// )
/// }
Expand All @@ -48,14 +48,14 @@
/// self.client = client
/// }
/// public func methodA<R: Sendable>(
/// request: ClientRequest.Stream<namespaceA.ServiceA.Methods.methodA.Input>,
/// serializer: some MessageSerializer<namespaceA.ServiceA.Methods.methodA.Input>,
/// deserializer: some MessageDeserializer<namespaceA.ServiceA.Methods.methodA.Output>,
/// _ body: @Sendable @escaping (ClientResponse.Single<namespaceA.ServiceA.Methods.methodA.Output>) async throws -> R
/// request: ClientRequest.Stream<namespaceA.ServiceA.Method.methodA.Input>,
/// serializer: some MessageSerializer<namespaceA.ServiceA.Method.methodA.Input>,
/// deserializer: some MessageDeserializer<namespaceA.ServiceA.Method.methodA.Output>,
/// _ body: @Sendable @escaping (ClientResponse.Single<namespaceA.ServiceA.Method.methodA.Output>) async throws -> R
/// ) async rethrows -> R {
/// try await self.client.clientStreaming(
/// request: request,
/// descriptor: NamespaceA.ServiceA.Methods.MethodA.descriptor,
/// descriptor: NamespaceA.ServiceA.Method.MethodA.descriptor,
/// serializer: serializer,
/// deserializer: deserializer,
/// handler: body
Expand Down Expand Up @@ -399,7 +399,7 @@ extension ClientCodeTranslator {
.init(
label: "descriptor",
expression: .identifierPattern(
"\(service.namespacedTypealiasGeneratedName).Methods.\(method.name.generatedUpperCase).descriptor"
"\(service.namespacedTypealiasGeneratedName).Method.\(method.name.generatedUpperCase).descriptor"
)
),
.init(label: "serializer", expression: .identifierPattern("serializer")),
Expand Down Expand Up @@ -439,7 +439,7 @@ extension ClientCodeTranslator {
type: InputOutputType
) -> String {
var components: String =
"\(service.namespacedTypealiasGeneratedName).Methods.\(method.name.generatedUpperCase)"
"\(service.namespacedTypealiasGeneratedName).Method.\(method.name.generatedUpperCase)"

switch type {
case .input:
Expand Down
20 changes: 10 additions & 10 deletions Sources/GRPCCodeGen/Internal/Translator/ServerCodeTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@
/// extension foo.Bar.StreamingServiceProtocol {
/// public func registerRPCs(with router: inout RPCRouter) {
/// router.registerHandler(
/// for: foo.Method.baz.descriptor,
/// deserializer: ProtobufDeserializer<foo.Methods.baz.Input>(),
/// serializer: ProtobufSerializer<foo.Methods.baz.Output>(),
/// forMethod: foo.Method.baz.descriptor,
/// deserializer: ProtobufDeserializer<foo.Method.baz.Input>(),
/// serializer: ProtobufSerializer<foo.Method.baz.Output>(),
/// handler: { request in try await self.baz(request: request) }
/// )
/// }
/// }
/// public protocol foo_BarServiceProtocol: foo.Bar.StreamingServiceProtocol {
/// func baz(
/// request: ServerRequest.Single<foo.Bar.Methods.baz.Input>
/// ) async throws -> ServerResponse.Single<foo.Bar.Methods.baz.Output>
/// request: ServerRequest.Single<foo.Bar.Method.baz.Input>
/// ) async throws -> ServerResponse.Single<foo.Bar.Method.baz.Output>
/// }
/// // Generated partial conformance to `foo_BarStreamingServiceProtocol`.
/// extension foo.Bar.ServiceProtocol {
/// public func baz(
/// request: ServerRequest.Stream<foo.Bar.Methods.baz.Input>
/// ) async throws -> ServerResponse.Stream<foo.Bar.Methods.baz.Output> {
/// request: ServerRequest.Stream<foo.Bar.Method.baz.Input>
/// ) async throws -> ServerResponse.Stream<foo.Bar.Method.baz.Output> {
/// let response = try await self.baz(request: ServerRequest.Single(stream: request)
/// return ServerResponse.Stream(single: response)
/// }
Expand Down Expand Up @@ -221,7 +221,7 @@ extension ServerCodeTranslator {
var arguments = [FunctionArgumentDescription]()
arguments.append(
.init(
label: "for",
label: "forMethod",
expression: .identifierPattern(
self.methodDescriptorPath(for: method, service: service)
)
Expand Down Expand Up @@ -460,7 +460,7 @@ extension ServerCodeTranslator {
type: InputOutputType
) -> String {
var components: String =
"\(service.namespacedTypealiasGeneratedName).Methods.\(method.name.generatedUpperCase)"
"\(service.namespacedTypealiasGeneratedName).Method.\(method.name.generatedUpperCase)"

switch type {
case .input:
Expand All @@ -478,7 +478,7 @@ extension ServerCodeTranslator {
service: CodeGenerationRequest.ServiceDescriptor
) -> String {
return
"\(service.namespacedTypealiasGeneratedName).Methods.\(method.name.generatedUpperCase).descriptor"
"\(service.namespacedTypealiasGeneratedName).Method.\(method.name.generatedUpperCase).descriptor"
}

/// Generates the fully qualified name of the type alias for a service protocol.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
/// // ...
///
/// public static let descriptors: [MethodDescriptor] = [
/// echo.Echo.Get.descriptor,
/// echo.Echo.Collect.descriptor,
/// Echo.Echo.Method.Get.descriptor,
/// Echo.Echo.Method.Collect.descriptor,
/// // ...
/// ]
/// }
Expand Down Expand Up @@ -222,7 +222,9 @@ extension TypealiasTranslator {
for methodName in methodNames {
let methodDescriptorPath = Expression.memberAccess(
MemberAccessDescription(
left: .identifierType(.member(["Methods", methodName])),
left: .identifierType(
.member([service.namespacedTypealiasGeneratedName, "Method", methodName])
),
right: "descriptor"
)
)
Expand All @@ -245,7 +247,7 @@ extension TypealiasTranslator {
let streamingServiceProtocolTypealias = Declaration.typealias(
accessModifier: self.accessModifier,
name: "StreamingServiceProtocol",
existingType: .member("\(service.namespacedGeneratedName)ServiceStreamingProtocol")
existingType: .member("\(service.namespacedGeneratedName)StreamingServiceProtocol")
)
let serviceProtocolTypealias = Declaration.typealias(
accessModifier: self.accessModifier,
Expand Down
Loading