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

Add a static TYPE variable to java models #201

Merged
merged 1 commit into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Board {

public static final String TYPE = "board";

@SerializedName("id") private @Nullable String uid;
@SerializedName("contributors") private @Nullable Set<User> contributors;
@SerializedName("counts") private @Nullable Map<String, Integer> counts;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Everything.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public enum EverythingStringEnum {
@SerializedName("case1") CASE1, @SerializedName("case2") CASE2, @SerializedName("case3") CASE3;
}

public static final String TYPE = "everything";

@SerializedName("array_prop") private @Nullable List<Object> arrayProp;
@SerializedName("boolean_prop") private @Nullable Boolean booleanProp;
@SerializedName("date_prop") private @Nullable Date dateProp;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Image {

public static final String TYPE = "image";

@SerializedName("height") private @Nullable Integer height;
@SerializedName("url") private @Nullable String url;
@SerializedName("width") private @Nullable Integer width;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Model {

public static final String TYPE = "model";

@SerializedName("id") private @Nullable String uid;

static final private int ID_SET = 1 << 0;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Pin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public int getValue() {
}
}

public static final String TYPE = "pin";

@SerializedName("attribution") private @Nullable Map<String, String> attribution;
@SerializedName("attribution_objects") private @Nullable List<PinAttributionObjects> attributionObjects;
@SerializedName("board") private @Nullable Board board;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public enum UserEmailFrequency {
@SerializedName("unset") UNSET, @SerializedName("immediate") IMMEDIATE, @SerializedName("daily") DAILY;
}

public static final String TYPE = "user";

@SerializedName("bio") private @Nullable String bio;
@SerializedName("counts") private @Nullable Map<String, Integer> counts;
@SerializedName("created_at") private @Nullable Date createdAt;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/VariableSubtitution.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class VariableSubtitution {

public static final String TYPE = "variable_subtitution";

@SerializedName("alloc_prop") private @Nullable Integer allocProp;
@SerializedName("copy_prop") private @Nullable Integer copyProp;
@SerializedName("mutable_copy_prop") private @Nullable Integer mutableCopyProp;
Expand Down
6 changes: 5 additions & 1 deletion Sources/Core/JavaModelRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public struct JavaModelRenderer: JavaFileRenderer {
}
}

func renderStaticTypeString() -> JavaIR.Property {
return JavaIR.Property(annotations: [], modifiers: [.public, .static, .final], type: "String", name: "TYPE", initialValue: "\"" + rootSchema.typeIdentifier + "\"")
}

func renderModelHashCode() -> JavaIR.Method {
let bodyHashCode = transitiveProperties.map { param, _ in
Languages.java.snakeCaseToPropertyName(param)
Expand Down Expand Up @@ -73,7 +77,7 @@ public struct JavaModelRenderer: JavaFileRenderer {
index += 1
}

return [props, bitmasks, [bits]]
return [[renderStaticTypeString()], props, bitmasks, [bits]]
}

func propertyGetterForParam(param: String, schemaObj: SchemaObjectProperty) -> JavaIR.Method {
Expand Down