Skip to content

Commit 3873bb3

Browse files
Merge pull request #1619 from kevinmbeaulieu/kb/document-input-init
[Swift] Add documentation to input structs' init
2 parents 51fad9e + eb11edc commit 3873bb3

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
@@ -9,7 +9,7 @@
99
- `apollo-codegen-scala`
1010
- <First `apollo-codegen-scala` related entry goes here>
1111
- `apollo-codegen-swift`
12-
- <First `apollo-codegen-swift` related entry goes here>
12+
- Add documentation to input structs' constructors [#1619](https://github.com/apollographql/apollo-tooling/pull/1619)
1313
- `apollo-codegen-typescript`
1414
- <First `apollo-codegen-typescript` related entry goes here>
1515
- `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
@@ -1203,6 +1203,21 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> {
12031203
this.printOnNewline(swift`public var graphQLMap: GraphQLMap`);
12041204

12051205
this.printNewlineIfNeeded();
1206+
1207+
if (properties.length > 0) {
1208+
this.comment("- Parameters:");
1209+
properties.forEach(property => {
1210+
var propertyDescription = "";
1211+
if (property.description) {
1212+
propertyDescription = `: ${property.description}`;
1213+
}
1214+
this.comment(
1215+
` - ${property.propertyName}${propertyDescription}`,
1216+
false
1217+
);
1218+
});
1219+
}
1220+
12061221
this.printOnNewline(swift`public init`);
12071222
this.print(swift`(`);
12081223
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)