Skip to content

Commit

Permalink
fix: go enum schema changes (#189)
Browse files Browse the repository at this point in the history
* fix: added enum schema changes support for go

* fix: updated enum schema for yaml

* fix: reverting test changes

* fix: enum schema update

* fix: java generate code and remove extra enums

* fix: fixed failing test

* fix: adding node example files

* fix: updated isEnum flag

Co-authored-by: chsingh <[email protected]>
  • Loading branch information
kridai and charan678 authored Jul 15, 2022
1 parent 53342be commit 4b807ac
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 150 deletions.
6 changes: 3 additions & 3 deletions examples/go/go-client/helper/rest/api/v2010/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ Class | Method | HTTP request | Description

## Documentation For Models

- [ListAccountResponse](docs/ListAccountResponse.md)
- [ListCredentialAwsResponse](docs/ListCredentialAwsResponse.md)
- [ListCredentialAwsResponseMeta](docs/ListCredentialAwsResponseMeta.md)
- [ListAccountResponse](docs/ListAccountResponse.md)
- [TestResponseObjectTestObject](docs/TestResponseObjectTestObject.md)
- [TestResponseObject](docs/TestResponseObject.md)
- [ListCredentialAwsResponseMeta](docs/ListCredentialAwsResponseMeta.md)
- [TestResponseObjectTestArrayOfObjects](docs/TestResponseObjectTestArrayOfObjects.md)
- [TestResponseObjectTestObject](docs/TestResponseObjectTestObject.md)


## Documentation For Authorization
Expand Down
4 changes: 2 additions & 2 deletions examples/go/go-client/helper/rest/api/v2010/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestPost(t *testing.T) {
params.SetTestNumberInt64(222)
params.SetTestDateTime(time.Now())
params.SetTestDate("2022-01-01")
params.SetTestEnum("consumer-checking")
params.SetTestEnum("completed")

// "Any" type should expect any type of value. We'll test with an array of maps, but any type should work.
params.SetTestAnyType([]map[string]interface{}{{
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestCustomHeaders(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, resp)
assert.Equal(t, float32(100.22), *resp.TestNumberFloat)
assert.Equal(t, "Trunking", *resp.TestEnum)
assert.Equal(t, "completed", *resp.TestEnum)
}

func TestRequiredParameters(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type TestResponseObject struct {
TestArrayOfIntegers []int `json:"test_array_of_integers,omitempty"`
TestArrayOfArrayOfIntegers [][]int `json:"test_array_of_array_of_integers,omitempty"`
TestArrayOfObjects *[]TestResponseObjectTestArrayOfObjects `json:"test_array_of_objects,omitempty"`
// Permissions authorized to the app
TestArrayOfEnum *[]string `json:"test_array_of_enum,omitempty"`
}

func (response *TestResponseObject) UnmarshalJSON(bytes []byte) (err error) {
Expand All @@ -52,6 +54,7 @@ func (response *TestResponseObject) UnmarshalJSON(bytes []byte) (err error) {
TestArrayOfIntegers []int `json:"test_array_of_integers"`
TestArrayOfArrayOfIntegers [][]int `json:"test_array_of_array_of_integers"`
TestArrayOfObjects *[]TestResponseObjectTestArrayOfObjects `json:"test_array_of_objects"`
TestArrayOfEnum *[]string `json:"test_array_of_enum"`
}{}

if err = json.Unmarshal(bytes, &raw); err != nil {
Expand All @@ -70,6 +73,7 @@ func (response *TestResponseObject) UnmarshalJSON(bytes []byte) (err error) {
TestArrayOfIntegers: raw.TestArrayOfIntegers,
TestArrayOfArrayOfIntegers: raw.TestArrayOfArrayOfIntegers,
TestArrayOfObjects: raw.TestArrayOfObjects,
TestArrayOfEnum: raw.TestArrayOfEnum,
}

responseTestNumber, err := client.UnmarshalFloat32(raw.TestNumber)
Expand Down
41 changes: 15 additions & 26 deletions examples/java/src/main/java/com/twilio/rest/api/v2010/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class Account extends Resource {
private static final long serialVersionUID = 259833493148625L;
private static final long serialVersionUID = 195758856312528L;

public static AccountCreator creator(){
return new AccountCreator();
Expand Down Expand Up @@ -162,25 +162,6 @@ public static Status forValue(final String value) {
return Promoter.enumFromString(value, Status.values());
}
}
public enum TestEnum {
DIALVERB("DialVerb"),
TRUNKING("Trunking");

private final String value;

private TestEnum(final String value) {
this.value = value;
}

public String toString() {
return value;
}

@JsonCreator
public static TestEnum forValue(final String value) {
return Promoter.enumFromString(value, TestEnum.values());
}
}
public enum XTwilioWebhookEnabled {
TRUE("true"),
FALSE("false");
Expand Down Expand Up @@ -210,10 +191,11 @@ public static XTwilioWebhookEnabled forValue(final String value) {
private final BigDecimal testNumber;
private final Currency priceUnit;
private final Float testNumberFloat;
private final Account.TestEnum testEnum;
private final Account.Status testEnum;
private final List<Integer> testArrayOfIntegers;
private final List<List<Integer>> testArrayOfArrayOfIntegers;
private final List<FeedbackIssue> testArrayOfObjects;
private final List<Account.Status> testArrayOfEnum;

@JsonCreator
private Account(
Expand Down Expand Up @@ -246,7 +228,7 @@ private Account(
final Float testNumberFloat,

@JsonProperty("test_enum")
final Account.TestEnum testEnum,
final Account.Status testEnum,

@JsonProperty("test_array_of_integers")
final List<Integer> testArrayOfIntegers,
Expand All @@ -255,7 +237,10 @@ private Account(
final List<List<Integer>> testArrayOfArrayOfIntegers,

@JsonProperty("test_array_of_objects")
final List<FeedbackIssue> testArrayOfObjects
final List<FeedbackIssue> testArrayOfObjects,

@JsonProperty("test_array_of_enum")
final List<Account.Status> testArrayOfEnum
) {
this.accountSid = accountSid;
this.sid = sid;
Expand All @@ -270,6 +255,7 @@ private Account(
this.testArrayOfIntegers = testArrayOfIntegers;
this.testArrayOfArrayOfIntegers = testArrayOfArrayOfIntegers;
this.testArrayOfObjects = testArrayOfObjects;
this.testArrayOfEnum = testArrayOfEnum;
}

public final String getAccountSid() {
Expand Down Expand Up @@ -299,7 +285,7 @@ public final Currency getPriceUnit() {
public final Float getTestNumberFloat() {
return this.testNumberFloat;
}
public final Account.TestEnum getTestEnum() {
public final Account.Status getTestEnum() {
return this.testEnum;
}
public final List<Integer> getTestArrayOfIntegers() {
Expand All @@ -311,6 +297,9 @@ public final List<List<Integer>> getTestArrayOfArrayOfIntegers() {
public final List<FeedbackIssue> getTestArrayOfObjects() {
return this.testArrayOfObjects;
}
public final List<Account.Status> getTestArrayOfEnum() {
return this.testArrayOfEnum;
}

@Override
public boolean equals(final Object o) {
Expand All @@ -324,12 +313,12 @@ public boolean equals(final Object o) {

Account other = (Account) o;

return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) ;
return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) && Objects.equals(testArrayOfEnum, other.testArrayOfEnum) ;
}

@Override
public int hashCode() {
return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects);
return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects, testArrayOfEnum);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class Call extends Resource {
private static final long serialVersionUID = 67961494484503L;
private static final long serialVersionUID = 193205363285633L;

public static CallCreator creator(final String requiredStringProperty){
return new CallCreator(requiredStringProperty);
Expand Down Expand Up @@ -133,13 +133,17 @@ public static Call fromJson(final InputStream json, final ObjectMapper objectMap
throw new ApiConnectionException(e.getMessage(), e);
}
}
public enum TestEnum {
DIALVERB("DialVerb"),
TRUNKING("Trunking");
public enum Status {
IN_PROGRESS("in-progress"),
PAUSED("paused"),
STOPPED("stopped"),
PROCESSING("processing"),
COMPLETED("completed"),
ABSENT("absent");

private final String value;

private TestEnum(final String value) {
private Status(final String value) {
this.value = value;
}

Expand All @@ -148,8 +152,8 @@ public String toString() {
}

@JsonCreator
public static TestEnum forValue(final String value) {
return Promoter.enumFromString(value, TestEnum.values());
public static Status forValue(final String value) {
return Promoter.enumFromString(value, Status.values());
}
}

Expand All @@ -162,10 +166,11 @@ public static TestEnum forValue(final String value) {
private final BigDecimal testNumber;
private final Currency priceUnit;
private final Float testNumberFloat;
private final Call.TestEnum testEnum;
private final Call.Status testEnum;
private final List<Integer> testArrayOfIntegers;
private final List<List<Integer>> testArrayOfArrayOfIntegers;
private final List<FeedbackIssue> testArrayOfObjects;
private final List<Call.Status> testArrayOfEnum;

@JsonCreator
private Call(
Expand Down Expand Up @@ -198,7 +203,7 @@ private Call(
final Float testNumberFloat,

@JsonProperty("test_enum")
final Call.TestEnum testEnum,
final Call.Status testEnum,

@JsonProperty("test_array_of_integers")
final List<Integer> testArrayOfIntegers,
Expand All @@ -207,7 +212,10 @@ private Call(
final List<List<Integer>> testArrayOfArrayOfIntegers,

@JsonProperty("test_array_of_objects")
final List<FeedbackIssue> testArrayOfObjects
final List<FeedbackIssue> testArrayOfObjects,

@JsonProperty("test_array_of_enum")
final List<Call.Status> testArrayOfEnum
) {
this.accountSid = accountSid;
this.sid = sid;
Expand All @@ -222,6 +230,7 @@ private Call(
this.testArrayOfIntegers = testArrayOfIntegers;
this.testArrayOfArrayOfIntegers = testArrayOfArrayOfIntegers;
this.testArrayOfObjects = testArrayOfObjects;
this.testArrayOfEnum = testArrayOfEnum;
}

public final String getAccountSid() {
Expand Down Expand Up @@ -251,7 +260,7 @@ public final Currency getPriceUnit() {
public final Float getTestNumberFloat() {
return this.testNumberFloat;
}
public final Call.TestEnum getTestEnum() {
public final Call.Status getTestEnum() {
return this.testEnum;
}
public final List<Integer> getTestArrayOfIntegers() {
Expand All @@ -263,6 +272,9 @@ public final List<List<Integer>> getTestArrayOfArrayOfIntegers() {
public final List<FeedbackIssue> getTestArrayOfObjects() {
return this.testArrayOfObjects;
}
public final List<Call.Status> getTestArrayOfEnum() {
return this.testArrayOfEnum;
}

@Override
public boolean equals(final Object o) {
Expand All @@ -276,12 +288,12 @@ public boolean equals(final Object o) {

Call other = (Call) o;

return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) ;
return Objects.equals(accountSid, other.accountSid) && Objects.equals(sid, other.sid) && Objects.equals(testString, other.testString) && Objects.equals(testInteger, other.testInteger) && Objects.equals(testObject, other.testObject) && Objects.equals(testDateTime, other.testDateTime) && Objects.equals(testNumber, other.testNumber) && Objects.equals(priceUnit, other.priceUnit) && Objects.equals(testNumberFloat, other.testNumberFloat) && Objects.equals(testEnum, other.testEnum) && Objects.equals(testArrayOfIntegers, other.testArrayOfIntegers) && Objects.equals(testArrayOfArrayOfIntegers, other.testArrayOfArrayOfIntegers) && Objects.equals(testArrayOfObjects, other.testArrayOfObjects) && Objects.equals(testArrayOfEnum, other.testArrayOfEnum) ;
}

@Override
public int hashCode() {
return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects);
return Objects.hash(accountSid, sid, testString, testInteger, testObject, testDateTime, testNumber, priceUnit, testNumberFloat, testEnum, testArrayOfIntegers, testArrayOfArrayOfIntegers, testArrayOfObjects, testArrayOfEnum);
}

}
Expand Down
Loading

0 comments on commit 4b807ac

Please sign in to comment.