From 62f81fb4d61df725cc3ced26d769719245e0ae32 Mon Sep 17 00:00:00 2001 From: maciej-nedza <76946708+maciej-nedza@users.noreply.github.com> Date: Thu, 14 Dec 2023 09:58:38 +0100 Subject: [PATCH] Automated commit message (#63) [DE-643] Fix types for subscription components endpoints --- doc/controllers/subscription-components.md | 18 ++- .../containers/create-usage-component-id.md | 14 ++ .../list-usages-input-component-id.md | 14 ++ .../subscription-component-subscription.md | 7 +- .../SubscriptionComponentsController.java | 14 +- .../models/ListUsagesInput.java | 73 +++++---- .../SubscriptionComponentSubscription.java | 20 +-- .../containers/CreateUsageComponentId.java | 151 ++++++++++++++++++ .../ListUsagesInputComponentId.java | 151 ++++++++++++++++++ 9 files changed, 405 insertions(+), 57 deletions(-) create mode 100644 doc/models/containers/create-usage-component-id.md create mode 100644 doc/models/containers/list-usages-input-component-id.md create mode 100644 src/main/java/com/maxio/advancedbilling/models/containers/CreateUsageComponentId.java create mode 100644 src/main/java/com/maxio/advancedbilling/models/containers/ListUsagesInputComponentId.java diff --git a/doc/controllers/subscription-components.md b/doc/controllers/subscription-components.md index 0b6e8ab4..0e6adc4e 100644 --- a/doc/controllers/subscription-components.md +++ b/doc/controllers/subscription-components.md @@ -1103,7 +1103,7 @@ A. No. Usage should be reported as one API call per component on a single subscr ```java UsageResponse createUsage( final int subscriptionId, - final int componentId, + final CreateUsageComponentId componentId, final CreateUsageRequest body) ``` @@ -1112,7 +1112,7 @@ UsageResponse createUsage( | Parameter | Type | Tags | Description | | --- | --- | --- | --- | | `subscriptionId` | `int` | Template, Required | The Chargify id of the subscription | -| `componentId` | `int` | Template, Required | Either the Chargify id for the component or the component's handle prefixed by `handle:` | +| `componentId` | [`CreateUsageComponentId`](../../doc/models/containers/create-usage-component-id.md) | Template, Required | This is a container for one-of cases. | | `body` | [`CreateUsageRequest`](../../doc/models/create-usage-request.md) | Body, Optional | - | ## Response Type @@ -1123,7 +1123,9 @@ UsageResponse createUsage( ```java int subscriptionId = 222; -int componentId = 222; +CreateUsageComponentId componentId = CreateUsageComponentId.fromNumber( + 144 +); CreateUsageRequest body = new CreateUsageRequest.Builder( new CreateUsage.Builder() .quantity(1000D) @@ -1195,11 +1197,11 @@ List listUsages( | Parameter | Type | Tags | Description | | --- | --- | --- | --- | | `subscriptionId` | `int` | Template, Required | The Chargify id of the subscription | -| `componentId` | `int` | Template, Required | Either the Chargify id for the component or the component's handle prefixed by `handle:` | +| `componentId` | [`ListUsagesInputComponentId`](../../doc/models/containers/list-usages-input-component-id.md) | Template, Required | This is a container for one-of cases. | | `sinceId` | `Integer` | Query, Optional | Returns usages with an id greater than or equal to the one specified | | `maxId` | `Integer` | Query, Optional | Returns usages with an id less than or equal to the one specified | -| `sinceDate` | `String` | Query, Optional | Returns usages with a created_at date greater than or equal to midnight (12:00 AM) on the date specified. | -| `untilDate` | `String` | Query, Optional | Returns usages with a created_at date less than or equal to midnight (12:00 AM) on the date specified. | +| `sinceDate` | `LocalDate` | Query, Optional | Returns usages with a created_at date greater than or equal to midnight (12:00 AM) on the date specified. | +| `untilDate` | `LocalDate` | Query, Optional | Returns usages with a created_at date less than or equal to midnight (12:00 AM) on the date specified. | | `page` | `Integer` | Query, Optional | Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
Use in query `page=1`.
**Default**: `1`
**Constraints**: `>= 1` | | `perPage` | `Integer` | Query, Optional | This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query `per_page=200`.
**Default**: `20`
**Constraints**: `<= 200` | @@ -1212,7 +1214,9 @@ List listUsages( ```java ListUsagesInput listUsagesInput = new ListUsagesInput.Builder( 222, - 222 + ListUsagesInputComponentId.fromNumber( + 144 + ) ) .page(2) .perPage(50) diff --git a/doc/models/containers/create-usage-component-id.md b/doc/models/containers/create-usage-component-id.md new file mode 100644 index 00000000..c721f53a --- /dev/null +++ b/doc/models/containers/create-usage-component-id.md @@ -0,0 +1,14 @@ + +# Create Usage Component Id + +## Class Name + +`CreateUsageComponentId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | CreateUsageComponentId.fromNumber(int number) | +| `String` | CreateUsageComponentId.fromString(String string) | + diff --git a/doc/models/containers/list-usages-input-component-id.md b/doc/models/containers/list-usages-input-component-id.md new file mode 100644 index 00000000..5d509284 --- /dev/null +++ b/doc/models/containers/list-usages-input-component-id.md @@ -0,0 +1,14 @@ + +# List Usages Input Component Id + +## Class Name + +`ListUsagesInputComponentId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | ListUsagesInputComponentId.fromNumber(int number) | +| `String` | ListUsagesInputComponentId.fromString(String string) | + diff --git a/doc/models/subscription-component-subscription.md b/doc/models/subscription-component-subscription.md index acad134b..966061cb 100644 --- a/doc/models/subscription-component-subscription.md +++ b/doc/models/subscription-component-subscription.md @@ -11,14 +11,17 @@ An optional object, will be returned if provided `include=subscription` query pa | Name | Type | Tags | Description | Getter | Setter | | --- | --- | --- | --- | --- | --- | -| `State` | `String` | Optional | - | String getState() | setState(String state) | +| `State` | `Object` | Optional | - | Object getState() | setState(Object state) | | `UpdatedAt` | `String` | Optional | - | String getUpdatedAt() | setUpdatedAt(String updatedAt) | ## Example (as JSON) ```json { - "state": "state0", + "state": { + "key1": "val1", + "key2": "val2" + }, "updated_at": "updated_at0" } ``` diff --git a/src/main/java/com/maxio/advancedbilling/controllers/SubscriptionComponentsController.java b/src/main/java/com/maxio/advancedbilling/controllers/SubscriptionComponentsController.java index fb061477..4aaf3550 100644 --- a/src/main/java/com/maxio/advancedbilling/controllers/SubscriptionComponentsController.java +++ b/src/main/java/com/maxio/advancedbilling/controllers/SubscriptionComponentsController.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.maxio.advancedbilling.ApiHelper; +import com.maxio.advancedbilling.DateTimeHelper; import com.maxio.advancedbilling.Server; import com.maxio.advancedbilling.exceptions.ApiException; import com.maxio.advancedbilling.exceptions.ComponentAllocationErrorException; @@ -33,6 +34,7 @@ import com.maxio.advancedbilling.models.SubscriptionStateFilter; import com.maxio.advancedbilling.models.UpdateAllocationExpirationDate; import com.maxio.advancedbilling.models.UsageResponse; +import com.maxio.advancedbilling.models.containers.CreateUsageComponentId; import io.apimatic.core.ApiCall; import io.apimatic.core.ErrorCase; import io.apimatic.core.GlobalConfiguration; @@ -696,7 +698,7 @@ private ApiCall prepareDeletePrepaidUsageAllocationRequest( */ public UsageResponse createUsage( final int subscriptionId, - final int componentId, + final CreateUsageComponentId componentId, final CreateUsageRequest body) throws ApiException, IOException { return prepareCreateUsageRequest(subscriptionId, componentId, body).execute(); } @@ -706,7 +708,7 @@ public UsageResponse createUsage( */ private ApiCall prepareCreateUsageRequest( final int subscriptionId, - final int componentId, + final CreateUsageComponentId componentId, final CreateUsageRequest body) throws JsonProcessingException, IOException { return new ApiCall.Builder() .globalConfig(getGlobalConfiguration()) @@ -717,7 +719,7 @@ private ApiCall prepareCreateUsageRequest( .bodySerializer(() -> ApiHelper.serialize(body)) .templateParam(param -> param.key("subscription_id").value(subscriptionId).isRequired(false) .shouldEncode(true)) - .templateParam(param -> param.key("component_id").value(componentId).isRequired(false) + .templateParam(param -> param.key("component_id").value(componentId) .shouldEncode(true)) .headerParam(param -> param.key("Content-Type") .value("application/json").isRequired(false)) @@ -772,16 +774,16 @@ private ApiCall, ApiException> prepareListUsagesRequest( .queryParam(param -> param.key("max_id") .value(input.getMaxId()).isRequired(false)) .queryParam(param -> param.key("since_date") - .value(input.getSinceDate()).isRequired(false)) + .value(DateTimeHelper.toSimpleDate(input.getSinceDate())).isRequired(false)) .queryParam(param -> param.key("until_date") - .value(input.getUntilDate()).isRequired(false)) + .value(DateTimeHelper.toSimpleDate(input.getUntilDate())).isRequired(false)) .queryParam(param -> param.key("page") .value(input.getPage()).isRequired(false)) .queryParam(param -> param.key("per_page") .value(input.getPerPage()).isRequired(false)) .templateParam(param -> param.key("subscription_id").value(input.getSubscriptionId()).isRequired(false) .shouldEncode(true)) - .templateParam(param -> param.key("component_id").value(input.getComponentId()).isRequired(false) + .templateParam(param -> param.key("component_id").value(input.getComponentId()) .shouldEncode(true)) .headerParam(param -> param.key("accept").value("application/json")) .authenticationKey(BaseController.AUTHENTICATION_KEY) diff --git a/src/main/java/com/maxio/advancedbilling/models/ListUsagesInput.java b/src/main/java/com/maxio/advancedbilling/models/ListUsagesInput.java index 13bd0558..05f6c420 100644 --- a/src/main/java/com/maxio/advancedbilling/models/ListUsagesInput.java +++ b/src/main/java/com/maxio/advancedbilling/models/ListUsagesInput.java @@ -9,17 +9,22 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.maxio.advancedbilling.DateTimeHelper; +import com.maxio.advancedbilling.models.containers.ListUsagesInputComponentId; +import java.time.LocalDate; /** * This is a model class for ListUsagesInput type. */ public class ListUsagesInput { private int subscriptionId; - private int componentId; + private ListUsagesInputComponentId componentId; private Integer sinceId; private Integer maxId; - private String sinceDate; - private String untilDate; + private LocalDate sinceDate; + private LocalDate untilDate; private Integer page; private Integer perPage; @@ -34,21 +39,21 @@ public ListUsagesInput() { /** * Initialization constructor. * @param subscriptionId int value for subscriptionId. - * @param componentId int value for componentId. + * @param componentId ListUsagesInputComponentId value for componentId. * @param sinceId Integer value for sinceId. * @param maxId Integer value for maxId. - * @param sinceDate String value for sinceDate. - * @param untilDate String value for untilDate. + * @param sinceDate LocalDate value for sinceDate. + * @param untilDate LocalDate value for untilDate. * @param page Integer value for page. * @param perPage Integer value for perPage. */ public ListUsagesInput( int subscriptionId, - int componentId, + ListUsagesInputComponentId componentId, Integer sinceId, Integer maxId, - String sinceDate, - String untilDate, + LocalDate sinceDate, + LocalDate untilDate, Integer page, Integer perPage) { this.subscriptionId = subscriptionId; @@ -84,20 +89,20 @@ public void setSubscriptionId(int subscriptionId) { /** * Getter for ComponentId. * Either the Chargify id for the component or the component's handle prefixed by `handle:` - * @return Returns the int + * @return Returns the ListUsagesInputComponentId */ @JsonGetter("component_id") - public int getComponentId() { + public ListUsagesInputComponentId getComponentId() { return componentId; } /** * Setter for ComponentId. * Either the Chargify id for the component or the component's handle prefixed by `handle:` - * @param componentId Value for int + * @param componentId Value for ListUsagesInputComponentId */ @JsonSetter("component_id") - public void setComponentId(int componentId) { + public void setComponentId(ListUsagesInputComponentId componentId) { this.componentId = componentId; } @@ -147,11 +152,12 @@ public void setMaxId(Integer maxId) { * Getter for SinceDate. * Returns usages with a created_at date greater than or equal to midnight (12:00 AM) on the * date specified. - * @return Returns the String + * @return Returns the LocalDate */ @JsonGetter("since_date") @JsonInclude(JsonInclude.Include.NON_NULL) - public String getSinceDate() { + @JsonSerialize(using = DateTimeHelper.SimpleDateSerializer.class) + public LocalDate getSinceDate() { return sinceDate; } @@ -159,10 +165,11 @@ public String getSinceDate() { * Setter for SinceDate. * Returns usages with a created_at date greater than or equal to midnight (12:00 AM) on the * date specified. - * @param sinceDate Value for String + * @param sinceDate Value for LocalDate */ @JsonSetter("since_date") - public void setSinceDate(String sinceDate) { + @JsonDeserialize(using = DateTimeHelper.SimpleDateDeserializer.class) + public void setSinceDate(LocalDate sinceDate) { this.sinceDate = sinceDate; } @@ -170,11 +177,12 @@ public void setSinceDate(String sinceDate) { * Getter for UntilDate. * Returns usages with a created_at date less than or equal to midnight (12:00 AM) on the date * specified. - * @return Returns the String + * @return Returns the LocalDate */ @JsonGetter("until_date") @JsonInclude(JsonInclude.Include.NON_NULL) - public String getUntilDate() { + @JsonSerialize(using = DateTimeHelper.SimpleDateSerializer.class) + public LocalDate getUntilDate() { return untilDate; } @@ -182,10 +190,11 @@ public String getUntilDate() { * Setter for UntilDate. * Returns usages with a created_at date less than or equal to midnight (12:00 AM) on the date * specified. - * @param untilDate Value for String + * @param untilDate Value for LocalDate */ @JsonSetter("until_date") - public void setUntilDate(String untilDate) { + @JsonDeserialize(using = DateTimeHelper.SimpleDateDeserializer.class) + public void setUntilDate(LocalDate untilDate) { this.untilDate = untilDate; } @@ -276,11 +285,11 @@ public Builder toBuilder() { */ public static class Builder { private int subscriptionId; - private int componentId; + private ListUsagesInputComponentId componentId; private Integer sinceId; private Integer maxId; - private String sinceDate; - private String untilDate; + private LocalDate sinceDate; + private LocalDate untilDate; private Integer page = 1; private Integer perPage = 20; @@ -293,9 +302,9 @@ public Builder() { /** * Initialization constructor. * @param subscriptionId int value for subscriptionId. - * @param componentId int value for componentId. + * @param componentId ListUsagesInputComponentId value for componentId. */ - public Builder(int subscriptionId, int componentId) { + public Builder(int subscriptionId, ListUsagesInputComponentId componentId) { this.subscriptionId = subscriptionId; this.componentId = componentId; } @@ -312,10 +321,10 @@ public Builder subscriptionId(int subscriptionId) { /** * Setter for componentId. - * @param componentId int value for componentId. + * @param componentId ListUsagesInputComponentId value for componentId. * @return Builder */ - public Builder componentId(int componentId) { + public Builder componentId(ListUsagesInputComponentId componentId) { this.componentId = componentId; return this; } @@ -342,20 +351,20 @@ public Builder maxId(Integer maxId) { /** * Setter for sinceDate. - * @param sinceDate String value for sinceDate. + * @param sinceDate LocalDate value for sinceDate. * @return Builder */ - public Builder sinceDate(String sinceDate) { + public Builder sinceDate(LocalDate sinceDate) { this.sinceDate = sinceDate; return this; } /** * Setter for untilDate. - * @param untilDate String value for untilDate. + * @param untilDate LocalDate value for untilDate. * @return Builder */ - public Builder untilDate(String untilDate) { + public Builder untilDate(LocalDate untilDate) { this.untilDate = untilDate; return this; } diff --git a/src/main/java/com/maxio/advancedbilling/models/SubscriptionComponentSubscription.java b/src/main/java/com/maxio/advancedbilling/models/SubscriptionComponentSubscription.java index 1c32d003..71778aec 100644 --- a/src/main/java/com/maxio/advancedbilling/models/SubscriptionComponentSubscription.java +++ b/src/main/java/com/maxio/advancedbilling/models/SubscriptionComponentSubscription.java @@ -14,7 +14,7 @@ * This is a model class for SubscriptionComponentSubscription type. */ public class SubscriptionComponentSubscription { - private String state; + private Object state; private String updatedAt; /** @@ -25,11 +25,11 @@ public SubscriptionComponentSubscription() { /** * Initialization constructor. - * @param state String value for state. + * @param state Object value for state. * @param updatedAt String value for updatedAt. */ public SubscriptionComponentSubscription( - String state, + Object state, String updatedAt) { this.state = state; this.updatedAt = updatedAt; @@ -37,20 +37,20 @@ public SubscriptionComponentSubscription( /** * Getter for State. - * @return Returns the String + * @return Returns the Object */ @JsonGetter("state") @JsonInclude(JsonInclude.Include.NON_NULL) - public String getState() { + public Object getState() { return state; } /** * Setter for State. - * @param state Value for String + * @param state Value for Object */ @JsonSetter("state") - public void setState(String state) { + public void setState(Object state) { this.state = state; } @@ -99,17 +99,17 @@ public Builder toBuilder() { * Class to build instances of {@link SubscriptionComponentSubscription}. */ public static class Builder { - private String state; + private Object state; private String updatedAt; /** * Setter for state. - * @param state String value for state. + * @param state Object value for state. * @return Builder */ - public Builder state(String state) { + public Builder state(Object state) { this.state = state; return this; } diff --git a/src/main/java/com/maxio/advancedbilling/models/containers/CreateUsageComponentId.java b/src/main/java/com/maxio/advancedbilling/models/containers/CreateUsageComponentId.java new file mode 100644 index 00000000..bbbaf7e4 --- /dev/null +++ b/src/main/java/com/maxio/advancedbilling/models/containers/CreateUsageComponentId.java @@ -0,0 +1,151 @@ +/* + * AdvancedBilling + * + * This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). + */ + +package com.maxio.advancedbilling.models.containers; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.maxio.advancedbilling.ApiHelper; +import io.apimatic.core.annotations.TypeCombinator.TypeCombinatorCase; +import io.apimatic.core.annotations.TypeCombinator.TypeCombinatorStringCase; +import java.io.IOException; +import java.util.Arrays; + +/** + * This is a container class for one-of types. + */ +@JsonDeserialize(using = CreateUsageComponentId.CreateUsageComponentIdDeserializer.class) +public abstract class CreateUsageComponentId { + + /** + * This is Number case. + * @param number int value for number. + * @return The NumberCase object. + */ + public static CreateUsageComponentId fromNumber(int number) { + return new NumberCase(number); + } + + /** + * This is String case. + * @param string String value for string. + * @return The StringCase object. + */ + public static CreateUsageComponentId fromString(String string) { + return string == null ? null : new StringCase(string); + } + + /** + * Method to match from the provided one-of cases. + * @param The type to return after applying callback. + * @param cases The one-of type cases callback. + * @return The one-of matched case. + */ + public abstract R match(Cases cases); + + /** + * This is interface for one-of cases. + * @param The type to return after applying callback. + */ + public interface Cases { + R number(int number); + + R string(String string); + } + + /** + * This is a implementation class for NumberCase. + */ + @JsonDeserialize(using = JsonDeserializer.None.class) + @TypeCombinatorCase(type = "int") + private static class NumberCase extends CreateUsageComponentId { + + @JsonValue + private int number; + + NumberCase(int number) { + this.number = number; + } + + @Override + public R match(Cases cases) { + return cases.number(this.number); + } + + @JsonCreator + private NumberCase(JsonNode jsonNode) throws IOException { + if (jsonNode.isInt()) { + this.number = ApiHelper.deserialize(jsonNode, Integer.class); + } else { + throw new IllegalArgumentException(); + } + } + + @Override + public String toString() { + return String.valueOf(number); + } + } + + /** + * This is a implementation class for StringCase. + */ + @JsonDeserialize(using = JsonDeserializer.None.class) + @TypeCombinatorStringCase + @TypeCombinatorCase(type = "String") + private static class StringCase extends CreateUsageComponentId { + + @JsonValue + private String string; + + StringCase(String string) { + this.string = string; + } + + @Override + public R match(Cases cases) { + return cases.string(this.string); + } + + @JsonCreator + private StringCase(JsonNode jsonNode) throws IOException { + if (jsonNode.isTextual()) { + this.string = ApiHelper.deserialize(jsonNode, String.class); + } else { + throw new IllegalArgumentException(); + } + } + + @Override + public String toString() { + return string.toString(); + } + } + + /** + * This is a custom deserializer class for CreateUsageComponentId. + */ + protected static class CreateUsageComponentIdDeserializer + extends JsonDeserializer { + + @Override + public CreateUsageComponentId deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + ObjectCodec oc = jp.getCodec(); + JsonNode node = oc.readTree(jp); + return ApiHelper.deserialize(node, Arrays.asList(NumberCase.class, + StringCase.class), true); + } + } + +} diff --git a/src/main/java/com/maxio/advancedbilling/models/containers/ListUsagesInputComponentId.java b/src/main/java/com/maxio/advancedbilling/models/containers/ListUsagesInputComponentId.java new file mode 100644 index 00000000..236e5b06 --- /dev/null +++ b/src/main/java/com/maxio/advancedbilling/models/containers/ListUsagesInputComponentId.java @@ -0,0 +1,151 @@ +/* + * AdvancedBilling + * + * This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). + */ + +package com.maxio.advancedbilling.models.containers; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.maxio.advancedbilling.ApiHelper; +import io.apimatic.core.annotations.TypeCombinator.TypeCombinatorCase; +import io.apimatic.core.annotations.TypeCombinator.TypeCombinatorStringCase; +import java.io.IOException; +import java.util.Arrays; + +/** + * This is a container class for one-of types. + */ +@JsonDeserialize(using = ListUsagesInputComponentId.ListUsagesInputComponentIdDeserializer.class) +public abstract class ListUsagesInputComponentId { + + /** + * This is Number case. + * @param number int value for number. + * @return The NumberCase object. + */ + public static ListUsagesInputComponentId fromNumber(int number) { + return new NumberCase(number); + } + + /** + * This is String case. + * @param string String value for string. + * @return The StringCase object. + */ + public static ListUsagesInputComponentId fromString(String string) { + return string == null ? null : new StringCase(string); + } + + /** + * Method to match from the provided one-of cases. + * @param The type to return after applying callback. + * @param cases The one-of type cases callback. + * @return The one-of matched case. + */ + public abstract R match(Cases cases); + + /** + * This is interface for one-of cases. + * @param The type to return after applying callback. + */ + public interface Cases { + R number(int number); + + R string(String string); + } + + /** + * This is a implementation class for NumberCase. + */ + @JsonDeserialize(using = JsonDeserializer.None.class) + @TypeCombinatorCase(type = "int") + private static class NumberCase extends ListUsagesInputComponentId { + + @JsonValue + private int number; + + NumberCase(int number) { + this.number = number; + } + + @Override + public R match(Cases cases) { + return cases.number(this.number); + } + + @JsonCreator + private NumberCase(JsonNode jsonNode) throws IOException { + if (jsonNode.isInt()) { + this.number = ApiHelper.deserialize(jsonNode, Integer.class); + } else { + throw new IllegalArgumentException(); + } + } + + @Override + public String toString() { + return String.valueOf(number); + } + } + + /** + * This is a implementation class for StringCase. + */ + @JsonDeserialize(using = JsonDeserializer.None.class) + @TypeCombinatorStringCase + @TypeCombinatorCase(type = "String") + private static class StringCase extends ListUsagesInputComponentId { + + @JsonValue + private String string; + + StringCase(String string) { + this.string = string; + } + + @Override + public R match(Cases cases) { + return cases.string(this.string); + } + + @JsonCreator + private StringCase(JsonNode jsonNode) throws IOException { + if (jsonNode.isTextual()) { + this.string = ApiHelper.deserialize(jsonNode, String.class); + } else { + throw new IllegalArgumentException(); + } + } + + @Override + public String toString() { + return string.toString(); + } + } + + /** + * This is a custom deserializer class for ListUsagesInputComponentId. + */ + protected static class ListUsagesInputComponentIdDeserializer + extends JsonDeserializer { + + @Override + public ListUsagesInputComponentId deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + ObjectCodec oc = jp.getCodec(); + JsonNode node = oc.readTree(jp); + return ApiHelper.deserialize(node, Arrays.asList(NumberCase.class, + StringCase.class), true); + } + } + +}