Skip to content

Commit 5260579

Browse files
authored
Simplify typealias translator (#2126)
Motivation: The typealias used to generte an enum per package name and nested enums for each service within that namespace. In order for that to work, the services had to be grouped by namespace. This is no longer the case, each service is generated within a combined package-service enum. It's simpler to just generate the services in the order they are created. Modifications: - Remove the sorting - Remove tests which test the unwanted behaviour Result: Less code
1 parent 3cbc033 commit 5260579

File tree

2 files changed

+12
-384
lines changed

2 files changed

+12
-384
lines changed

Sources/GRPCCodeGen/Internal/Translator/TypealiasTranslator.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,22 @@ struct TypealiasTranslator: SpecializedTranslator {
8181

8282
func translate(from codeGenerationRequest: CodeGenerationRequest) throws -> [CodeBlock] {
8383
var codeBlocks = [CodeBlock]()
84-
let services = codeGenerationRequest.services
85-
let servicesByEnumName = Dictionary(
86-
grouping: services,
87-
by: { $0.namespacedGeneratedName }
88-
)
8984

90-
// Sorting the keys of the dictionary is necessary so that the generated enums are deterministically ordered.
91-
for (generatedEnumName, services) in servicesByEnumName.sorted(by: { $0.key < $1.key }) {
92-
for service in services {
93-
codeBlocks.append(
94-
CodeBlock(
95-
item: .declaration(try self.makeServiceEnum(from: service, named: generatedEnumName))
85+
for service in codeGenerationRequest.services {
86+
codeBlocks.append(
87+
CodeBlock(
88+
item: .declaration(
89+
try self.makeServiceEnum(
90+
from: service,
91+
named: service.namespacedGeneratedName
92+
)
9693
)
9794
)
95+
)
9896

99-
codeBlocks.append(
100-
CodeBlock(item: .declaration(self.makeServiceDescriptorExtension(for: service)))
101-
)
102-
}
97+
codeBlocks.append(
98+
CodeBlock(item: .declaration(self.makeServiceDescriptorExtension(for: service)))
99+
)
103100
}
104101

105102
return codeBlocks

0 commit comments

Comments
 (0)