Skip to content

Commit 35c11cf

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

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- `apollo-codegen-scala`
1111
- <First `apollo-codegen-scala` related entry goes here>
1212
- `apollo-codegen-swift`
13-
- <First `apollo-codegen-swift` related entry goes here>
13+
- Add documentation to input structs' constructors [#1619](https://github.com/apollographql/apollo-tooling/pull/1619)
1414
- `apollo-codegen-typescript`
1515
- <First `apollo-codegen-typescript` related entry goes here>
1616
- `apollo-env`

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)