-
Notifications
You must be signed in to change notification settings - Fork 536
Description
Referencing to the issue #1619 , where empty strings are allowed, if we check the following code in version 2.0.31:
public Contact getContact(ObjectNode node, String location, ParseResult result) {
.....
value = getString("url", node, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
try {
new URL(value);
} catch (Exception e) {
result.warning(location, value);
}
contact.setUrl(value);
}
Info contact url:
https://github.com/swagger-api/swagger-parser/pull/1619/files#diff-6817a7685b85bf60e0859476689df9be7ef2433a4c3e5ffdaaf90ea562da03edR1003
This means that an empty url like the following will end in a validation error.
info:
contact:
url: ""
This is a breaking change since in previous versions if the contact url is empty, it does not add a warning. This is because the code
new URL("") will end in an exception because it is not a valid url.
All of this makes the need to disable the validation with skipValidateSpec, but it is not the best way I think, because I do not want to skip all the validations. I think that the best approach would be to recover the previous behaviour, which is that if the url is empty, not set the url, because it is a conflict to allow empty strings for urls in places where they are being validated by new URL("") call.
value = getString("url", node, false, location, result);
if (StringUtils.isNotBlank(value)) {
try {
new URL(value);
} catch (Exception e) {
result.warning(location, value);
}
contact.setUrl(value);
}
This would not set any url, it would be null.
I would be glad to contribute once determined the solution.
Thank you very much for your time :)