Skip to content

Commit 55bac29

Browse files
fix: Fixes description indenting & commenting
1 parent 7a25a01 commit 55bac29

3 files changed

Lines changed: 33 additions & 25 deletions

File tree

Sources/GraphQLGeneratorCore/Generator/SchemaGenerator.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ package struct SchemaGenerator {
269269
output += """
270270
,
271271
description: \"\"\"
272-
\(description)
272+
\(description.indent(1, includeFirst: false))
273273
\"\"\"
274274
"""
275275
}
@@ -311,15 +311,15 @@ package struct SchemaGenerator {
311311
output += """
312312
,
313313
description: \"\"\"
314-
\(description)
314+
\(description.indent(3, includeFirst: false))
315315
\"\"\"
316316
"""
317317
}
318318
if let deprecationReason = field.deprecationReason {
319319
output += """
320320
,
321321
deprecationReason: \"\"\"
322-
\(deprecationReason)
322+
\(deprecationReason.indent(3, includeFirst: false))
323323
\"\"\"
324324
"""
325325
}
@@ -351,7 +351,7 @@ package struct SchemaGenerator {
351351
output += """
352352
,
353353
description: \"\"\"
354-
\(description)
354+
\(description.indent(1, includeFirst: false))
355355
\"\"\",
356356
"""
357357
}
@@ -432,7 +432,7 @@ package struct SchemaGenerator {
432432
output += """
433433
,
434434
description: \"\"\"
435-
\(description)
435+
\(description.indent(1, includeFirst: false))
436436
\"\"\"
437437
"""
438438
}
@@ -505,20 +505,20 @@ package struct SchemaGenerator {
505505

506506
var output = """
507507
let \(varName) = try GraphQLUnionType(
508-
name: "\(type.name)",
508+
name: "\(type.name)"
509509
"""
510510

511511
if let description = type.description {
512512
output += """
513-
513+
,
514514
description: \"\"\"
515-
\(description)
516-
\"\"\",
515+
\(description.indent(1, includeFirst: false))
516+
\"\"\"
517517
"""
518518
}
519519

520520
output += """
521-
521+
,
522522
types: [
523523
"""
524524
for type in try type.types() {
@@ -612,7 +612,7 @@ package struct SchemaGenerator {
612612
output += """
613613
,
614614
description: \"\"\"
615-
\(description)
615+
\(description.indent(1, includeFirst: false))
616616
\"\"\"
617617
"""
618618
}
@@ -621,7 +621,7 @@ package struct SchemaGenerator {
621621
output += """
622622
,
623623
deprecationReason: \"\"\"
624-
\(deprecationReason)
624+
\(deprecationReason.indent(1, includeFirst: false))
625625
\"\"\"
626626
"""
627627
}
@@ -644,7 +644,7 @@ package struct SchemaGenerator {
644644
output += """
645645
,
646646
description: \"\"\"
647-
\(description)
647+
\(description.indent(3, includeFirst: false))
648648
\"\"\"
649649
"""
650650
}

Sources/GraphQLGeneratorCore/Generator/TypeGenerator.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ package struct TypeGenerator {
8383
if let description = type.description {
8484
output += """
8585
86-
/// \(description)
86+
\(description.docComment())
8787
"""
8888
}
8989
let swiftTypeName = try swiftTypeDeclaration(for: type, nameGenerator: nameGenerator)
@@ -163,7 +163,7 @@ package struct TypeGenerator {
163163
if let description = type.description {
164164
output += """
165165
166-
/// \(description)
166+
\(description.docComment())
167167
"""
168168
}
169169

@@ -178,7 +178,7 @@ package struct TypeGenerator {
178178
if let description = value.description {
179179
output += """
180180
181-
/// \(description)
181+
\(description.docComment().indent(1, includeFirst: false))
182182
"""
183183
}
184184
// Use safe name generator for case names
@@ -204,7 +204,7 @@ package struct TypeGenerator {
204204
if let description = type.description {
205205
output += """
206206
207-
/// \(description)
207+
\(description.docComment())
208208
"""
209209
}
210210

@@ -217,7 +217,7 @@ package struct TypeGenerator {
217217
if let description = field.description {
218218
output += """
219219
220-
/// \(description)
220+
\(description.docComment().indent(1, includeFirst: false))
221221
"""
222222
}
223223

@@ -245,7 +245,7 @@ package struct TypeGenerator {
245245
if let description = type.description {
246246
output += """
247247
248-
/// \(description)
248+
\(description.docComment())
249249
"""
250250
}
251251

@@ -265,7 +265,7 @@ package struct TypeGenerator {
265265
if let description = field.description {
266266
output += """
267267
268-
/// \(description)
268+
\(description.docComment().indent(1, includeFirst: false))
269269
"""
270270
}
271271

@@ -309,7 +309,7 @@ package struct TypeGenerator {
309309
if let description = type.description {
310310
output += """
311311
312-
/// \(description)
312+
\(description.docComment())
313313
"""
314314
}
315315

@@ -333,7 +333,7 @@ package struct TypeGenerator {
333333
if let description = field.description {
334334
output += """
335335
336-
/// \(description)
336+
\(description.docComment().indent(1, includeFirst: false))
337337
"""
338338
}
339339

@@ -379,7 +379,7 @@ package struct TypeGenerator {
379379
if let description = type.description {
380380
output += """
381381
382-
/// \(description)
382+
\(description.docComment())
383383
"""
384384
}
385385

@@ -395,7 +395,7 @@ package struct TypeGenerator {
395395
if let description = field.description {
396396
output += """
397397
398-
/// \(description)
398+
\(description.docComment().indent(1, includeFirst: false))
399399
"""
400400
}
401401

Sources/GraphQLGeneratorCore/Utilities/indent.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
extension String {
22
func indent(_ num: Int, includeFirst: Bool = true) -> String {
33
let indent = String(repeating: " ", count: num)
4+
return prefixLines(with: indent, includeFirst: includeFirst)
5+
}
6+
7+
func docComment() -> String {
8+
return prefixLines(with: "/// ", includeFirst: true)
9+
}
10+
11+
private func prefixLines(with prefix: any StringProtocol, includeFirst: Bool) -> String {
412
var firstLine = true
513
return split(separator: "\n").map { line in
614
var result = line
715
if !line.isEmpty {
816
if !firstLine || includeFirst {
9-
result = indent + line
17+
result = prefix + line
1018
}
1119
}
1220
firstLine = false

0 commit comments

Comments
 (0)