Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate fields javadocs from schema description #439

Merged
merged 4 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fun FieldSpec.overrideType(typeNameOverrideMap: Map<String, String>): FieldSpec
FieldSpec.builder(type.overrideTypeName(typeNameOverrideMap).annotated(type.annotations), name)
.addModifiers(*modifiers.toTypedArray())
.addAnnotations(annotations)
.addJavadoc(javadoc)
.initializer(initializer)
.build()

Expand All @@ -28,6 +29,7 @@ fun MethodSpec.overrideReturnType(typeNameOverrideMap: Map<String, String>): Met
.returns(returnType.overrideTypeName(typeNameOverrideMap).annotated(returnType.annotations))
.addModifiers(*modifiers.toTypedArray())
.addCode(code)
.addJavadoc(javadoc)
.build()

fun TypeSpec.withValueInitConstructor(nullableValueGenerationType: NullableValueType): TypeSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,33 @@ data class Field(
val isConditional: Boolean = false,
val fields: List<Field>?,
val fragmentSpreads: List<String>?,
val inlineFragments: List<InlineFragment>?
val inlineFragments: List<InlineFragment>?,
val description: String?
) : CodeGenerator {
override fun toTypeSpec(context: CodeGenerationContext): TypeSpec =
SchemaTypeSpecBuilder(formatClassName(), fields ?: emptyList(), fragmentSpreads ?: emptyList(),
inlineFragments ?: emptyList(), context).build(Modifier.PUBLIC, Modifier.STATIC)
SchemaTypeSpecBuilder(
typeName = formatClassName(),
fields = fields ?: emptyList(),
fragmentSpreads = fragmentSpreads ?: emptyList(),
inlineFragments = inlineFragments ?: emptyList(),
context = context
).build(Modifier.PUBLIC, Modifier.STATIC)

fun accessorMethodSpec(context: CodeGenerationContext): MethodSpec {
return MethodSpec.methodBuilder(responseName)
.addModifiers(Modifier.PUBLIC)
.returns(toTypeName(methodResponseType(), context))
.addStatement("return this.\$L", responseName)
.let { if (description != null) it.addJavadoc("\$L\n", description) else it }
.build()
}

fun fieldSpec(context: CodeGenerationContext, publicModifier: Boolean = false): FieldSpec =
FieldSpec.builder(toTypeName(methodResponseType(), context), responseName)
.addModifiers(if (publicModifier) Modifier.PUBLIC else Modifier.PRIVATE, Modifier.FINAL)
.build()
fun fieldSpec(context: CodeGenerationContext, publicModifier: Boolean = false): FieldSpec {
return FieldSpec.builder(toTypeName(methodResponseType(), context), responseName)
.addModifiers(if (publicModifier) Modifier.PUBLIC else Modifier.PRIVATE, Modifier.FINAL)
.let { if (publicModifier && description != null) it.addJavadoc("\$L\n", description) else it }
.build()
}

fun argumentCodeBlock(): CodeBlock {
if (args == null || args.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,16 @@ public HeroWithReview(@Nonnull String name, @Nullable Double height) {
this.height = Optional.fromNullable(height);
}

/**
* What this human calls themselves
*/
public @Nonnull String name() {
return this.name;
}

/**
* Height in the preferred unit, default is meters
*/
public Optional<Double> height() {
return this.height;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public Hero(@Nullable String name) {
this.name = Optional.fromNullable(name);
}

/**
* The name of the character
*/
public Optional<String> name() {
return this.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,30 @@ public Hero(@Nonnull String name, @Nonnull Date birthDate,
this.fieldWithUnsupportedType = fieldWithUnsupportedType;
}

/**
* The name of the character
*/
public @Nonnull String name() {
return this.name;
}

/**
* The date character was born.
*/
public @Nonnull Date birthDate() {
return this.birthDate;
}

/**
* The dates of appearances
*/
public @Nonnull List<Date> appearanceDates() {
return this.appearanceDates;
}

/**
* The date character was born.
*/
public @Nonnull Object fieldWithUnsupportedType() {
return this.fieldWithUnsupportedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public Hero(@Nullable String name) {
this.name = Optional.fromNullable(name);
}

/**
* The name of the character
*/
public Optional<String> name() {
return this.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,23 @@ public Hero(@Nonnull String name, @Nonnull List<Episode> appearsIn,
this.firstAppearsIn = firstAppearsIn;
}

/**
* The name of the character
*/
public @Nonnull String name() {
return this.name;
}

/**
* The movies this character appears in
*/
public @Nonnull List<Episode> appearsIn() {
return this.appearsIn;
}

/**
* The movie this character first appears in
*/
public @Nonnull Episode firstAppearsIn() {
return this.firstAppearsIn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ public HeroDetails(@Nonnull String name, @Nonnull FriendsConnection friendsConne
this.friendsConnection = friendsConnection;
}

/**
* The name of the character
*/
public @Nonnull String name() {
return this.name;
}

/**
* The friends of the character exposed as a connection with edges
*/
public @Nonnull FriendsConnection friendsConnection() {
return this.friendsConnection;
}
Expand Down Expand Up @@ -130,6 +136,9 @@ public Node(@Nonnull String name) {
this.name = name;
}

/**
* The name of the character
*/
public @Nonnull String name() {
return this.name;
}
Expand Down Expand Up @@ -194,6 +203,9 @@ public Edge(@Nullable Node node) {
this.node = Optional.fromNullable(node);
}

/**
* The character represented by this friendship edge
*/
public Optional<Node> node() {
return this.node;
}
Expand Down Expand Up @@ -267,10 +279,16 @@ public FriendsConnection(@Nullable Integer totalCount, @Nullable List<Edge> edge
this.edges = Optional.fromNullable(edges);
}

/**
* The total number of friends
*/
public Optional<Integer> totalCount() {
return this.totalCount;
}

/**
* The edges for each of the character's friends.
*/
public Optional<List<Edge>> edges() {
return this.edges;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ public Edge(@Nullable Node node) {
this.node = Optional.fromNullable(node);
}

/**
* The item at the end of the edge
*/
public Optional<Node> node() {
return this.node;
}
Expand Down Expand Up @@ -356,6 +359,9 @@ public AllStarships1(@Nullable List<Edge> edges) {
this.edges = Optional.fromNullable(edges);
}

/**
* A list of edges.
*/
public Optional<List<Edge>> edges() {
return this.edges;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ public PilotFragment(@Nullable String name, @Nullable Homeworld homeworld) {
this.homeworld = Optional.fromNullable(homeworld);
}

/**
* The name of this person.
*/
public Optional<String> name() {
return this.name;
}

/**
* A planet that this person was born on or inhabits.
*/
public Optional<Homeworld> homeworld() {
return this.homeworld;
}
Expand Down Expand Up @@ -121,6 +127,9 @@ public Homeworld(@Nullable String name) {
this.name = Optional.fromNullable(name);
}

/**
* The name of this planet.
*/
public Optional<String> name() {
return this.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ public StarshipFragment(@Nonnull String id, @Nullable String name,
this.pilotConnection = Optional.fromNullable(pilotConnection);
}

/**
* The ID of an object
*/
public @Nonnull String id() {
return this.id;
}

/**
* The name of this starship. The common name, such as "Death Star".
*/
public Optional<String> name() {
return this.name;
}
Expand Down Expand Up @@ -281,6 +287,9 @@ public Edge(@Nullable Node node) {
this.node = Optional.fromNullable(node);
}

/**
* The item at the end of the edge
*/
public Optional<Node> node() {
return this.node;
}
Expand Down Expand Up @@ -351,6 +360,9 @@ public PilotConnection(@Nullable List<Edge> edges) {
this.edges = Optional.fromNullable(edges);
}

/**
* A list of edges.
*/
public Optional<List<Edge>> edges() {
return this.edges;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,16 @@ public Hero(@Nonnull String name, @Nonnull List<Episode> appearsIn,
this.fragments = fragments;
}

/**
* The name of the character
*/
public @Nonnull String name() {
return this.name;
}

/**
* The movies this character appears in
*/
public @Nonnull List<Episode> appearsIn() {
return this.appearsIn;
}
Expand Down
Loading