Skip to content

Commit 8fdc36f

Browse files
committed
Type validation
1 parent 3e1691a commit 8fdc36f

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

constructorio-client/src/main/java/io/constructor/client/ConstructorIO.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public boolean shouldSkipClass(Class<?> clazz) {
8080
})
8181
.create();
8282

83+
private static final Set<String> VALID_FACET_V2_TYPES =
84+
new LinkedHashSet<>(Arrays.asList("multiple", "hierarchical", "range"));
85+
8386
/**
8487
* @param newClient the OkHttpClient to use by all instances
8588
*/
@@ -3520,6 +3523,14 @@ public SortOptionsResponse retrieveSortOptions() throws ConstructorException {
35203523

35213524
// ==================== Facet Configuration V2 API ====================
35223525

3526+
private static void validateFacetConfigurationV2Type(String type) {
3527+
if (type == null || !VALID_FACET_V2_TYPES.contains(type)) {
3528+
throw new IllegalArgumentException(
3529+
"type is a required parameter and must be one of: multiple, hierarchical, or"
3530+
+ " range");
3531+
}
3532+
}
3533+
35233534
/**
35243535
* Retrieves all facet configurations (v2)
35253536
*
@@ -3658,14 +3669,20 @@ public String retrieveFacetConfigurationV2(String facetName) throws ConstructorE
36583669
*
36593670
* @param facetConfigurationV2Request the facet configuration v2 request
36603671
* @return returns the created facet as JSON string
3661-
* @throws IllegalArgumentException if request is null
3672+
* @throws IllegalArgumentException if request is null, facet configuration is null, or type is
3673+
* not one of {@code multiple}, {@code hierarchical}, {@code range}
36623674
* @throws ConstructorException if the request fails
36633675
*/
36643676
public String createFacetConfigurationV2(
36653677
FacetConfigurationV2Request facetConfigurationV2Request) throws ConstructorException {
36663678
if (facetConfigurationV2Request == null) {
36673679
throw new IllegalArgumentException("facetConfigurationV2Request is required");
36683680
}
3681+
if (facetConfigurationV2Request.getFacetConfiguration() == null) {
3682+
throw new IllegalArgumentException("facetConfiguration is required");
3683+
}
3684+
validateFacetConfigurationV2Type(
3685+
facetConfigurationV2Request.getFacetConfiguration().getType());
36693686

36703687
try {
36713688
HttpUrl url = this.makeUrl(Arrays.asList("v2", "facets"));
@@ -3692,7 +3709,8 @@ public String createFacetConfigurationV2(
36923709
*
36933710
* @param facetConfigurationV2Request the facet configuration v2 request
36943711
* @return returns the replaced facet as JSON string
3695-
* @throws IllegalArgumentException if request is null or facetName is missing
3712+
* @throws IllegalArgumentException if request is null, facetName is missing, or type is not
3713+
* one of {@code multiple}, {@code hierarchical}, {@code range}
36963714
* @throws ConstructorException if the request fails
36973715
*/
36983716
public String replaceFacetConfigurationV2(
@@ -3708,6 +3726,8 @@ public String replaceFacetConfigurationV2(
37083726
if (facetName == null || facetName.trim().isEmpty()) {
37093727
throw new IllegalArgumentException("facetName is required");
37103728
}
3729+
validateFacetConfigurationV2Type(
3730+
facetConfigurationV2Request.getFacetConfiguration().getType());
37113731

37123732
try {
37133733
HttpUrl url =

0 commit comments

Comments
 (0)