Skip to content

Commit 20ed10a

Browse files
[Swift] Add documentation to input structs' init
1 parent ff02fd0 commit 20ed10a

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/apollo-codegen-swift/src/__tests__/__snapshots__/codeGeneration.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,10 @@ exports[`Swift code generation #typeDeclarationForGraphQLType() should generate
20112011
public struct ReviewInput: GraphQLMapConvertible {
20122012
public var graphQLMap: GraphQLMap
20132013

2014+
/// - Parameters:
2015+
/// - stars: 0-5 stars
2016+
/// - commentary: Comment about the movie, optional
2017+
/// - favoriteColor: Favorite color, optional
20142018
public init(stars: Int, commentary: Swift.Optional<String?> = nil, favoriteColor: Swift.Optional<ColorInput?> = nil) {
20152019
graphQLMap = [\\"stars\\": stars, \\"commentary\\": commentary, \\"favorite_color\\": favoriteColor]
20162020
}

packages/apollo-codegen-swift/src/codeGeneration.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,21 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> {
11971197
this.printOnNewline(swift`public var graphQLMap: GraphQLMap`);
11981198

11991199
this.printNewlineIfNeeded();
1200+
1201+
if (properties.length > 0) {
1202+
this.comment("- Parameters:");
1203+
properties.forEach(property => {
1204+
var propertyDescription = "";
1205+
if (property.description) {
1206+
propertyDescription = `: ${property.description}`;
1207+
}
1208+
this.comment(
1209+
` - ${property.propertyName}${propertyDescription}`,
1210+
false
1211+
);
1212+
});
1213+
}
1214+
12001215
this.printOnNewline(swift`public init`);
12011216
this.print(swift`(`);
12021217
this.print(

packages/apollo-codegen-swift/src/language.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ export class SwiftGenerator<Context> extends CodeGenerator<
388388
}
389389
}
390390

391-
comment(comment?: string) {
391+
comment(comment?: string, trim: Boolean = true) {
392392
comment &&
393393
comment.split("\n").forEach(line => {
394-
this.printOnNewline(SwiftSource.raw`/// ${line.trim()}`);
394+
this.printOnNewline(SwiftSource.raw`/// ${trim ? line.trim() : line}`);
395395
});
396396
}
397397

0 commit comments

Comments
 (0)