Skip to content

Commit de68791

Browse files
committed
fix: parsing urls check
1 parent fb3714c commit de68791

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/main/java/io/github/isagroup/services/parsing/FeatureParser.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,17 @@ private static Integration parseMapToIntegration(String featureName, Map<String,
105105
}
106106

107107
if (integration.getIntegrationType().equals(IntegrationType.WEB_SAAS)) {
108-
integration.setPricingUrls((List<String>) map.get("pricingUrls"));
108+
if (map.get("pricingUrls") != null) {
109+
if (!(map.get("pricingUrls") instanceof List) || ((List<String>) map.get("pricingUrls")).isEmpty()
110+
|| ((List<String>) map.get("pricingUrls")).stream().anyMatch(url -> !url.matches("^(http|https)://.*"))) {
111+
throw new PricingParsingException("The feature " + featureName
112+
+ " is from type INTEGRATION with integrationType WEB_SAAS but does not have a valid pricingUrls list (each item must be a valid URL with the http or https protocol). Current value: " + map.get("pricingUrls")
113+
+ ". To specify a list you must use dash (-) before each item. Remember, it is an optional field so you can remove it from the input.");
114+
}
115+
integration.setPricingUrls((List<String>) map.get("pricingUrls"));
116+
} else {
117+
integration.setPricingUrls(List.of());
118+
}
109119
}
110120

111121
return integration;
@@ -160,7 +170,11 @@ private static Guarantee parseMapToGuarantee(String featureName, Map<String, Obj
160170

161171
if (map.get("docUrl") != null && !(map.get("docUrl") instanceof String)) {
162172
throw new PricingParsingException("\'docUrl\' must be a String but found a "
163-
+ map.get("docUrl").getClass().getSimpleName() + " instead");
173+
+ map.get("docUrl").getClass().getSimpleName() + " instead (feature affected: '" + featureName + "'). Remember, it is an optional field so you can remove it from the input.");
174+
}
175+
176+
if (map.get("docUrl") != null && !((String) map.get("docUrl")).matches("^(http|https)://.*")) {
177+
throw new PricingParsingException("The docUrl field (from feature '" + featureName + "') must be a valid URL with the http or https protocol. Received: " + map.get("docUrl") + ". Remember, it is an optional field so you can remove it from the input.");
164178
}
165179

166180
guarantee.setDocURL((String) map.get("docUrl"));

src/test/resources/negative-parsing-tests.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Throw an error if 'currency' is missing;parsing/negative/currency/currency-is-nu
3131
Throw an error if a feature is not a map of attributes;parsing/negative/feature/feature-is-key-value.yml;Feature 'foo' must be a Map but found String instead
3232
Throw an error if a feature is named 'null';parsing/negative/feature/feature-null-as-key.yml;A feature cannot have the name null
3333
# feature.docUrl
34-
Throw an error if feature 'docUrl' is not a string;parsing/negative/feature/docUrl/is-bool.yml;'docUrl' must be a String but found a Boolean instead
34+
Throw an error if feature 'docUrl' is not a string;parsing/negative/feature/docUrl/is-bool.yml;'docUrl' must be a String but found a Boolean instead (feature affected: 'guarantee'). Remember, it is an optional field so you can remove it from the input.
3535
# feature.type
3636
Throw an error if feature 'type' is missing or null;parsing/negative/feature/type/null-type.yml;feature 'type' is mandatory
3737
# feature.valueType

0 commit comments

Comments
 (0)