Fix problem parsing urls in cds-hooks formats

This commit is contained in:
Grahame Grieve 2024-10-18 20:50:53 +08:00
parent cb0759cc00
commit 6694be1ffe
2 changed files with 27 additions and 4 deletions

View File

@ -481,6 +481,8 @@ public class JsonParser extends ParserBase {
} else if (propV.hasType(type)) { } else if (propV.hasType(type)) {
pvl = new Property(propV.getContext(), propV.getDefinition(), propV.getStructure(), propV.getUtils(), propV.getContextUtils(), type); pvl = new Property(propV.getContext(), propV.getDefinition(), propV.getStructure(), propV.getUtils(), propV.getContextUtils(), type);
ok = true; ok = true;
} else if (propV.getDefinition().getType().size() == 1 && propV.typeIsConsistent(type)) {
pvl = new Property(propV.getContext(), propV.getDefinition(), propV.getStructure(), propV.getUtils(), propV.getContextUtils(), propV.getType());
} else { } else {
logError(errors, ValidationMessage.NO_RULE_DATE, line(pv.getValue()), col(pv.getValue()), path, IssueType.STRUCTURE, this.context.formatMessage(I18nConstants.UNRECOGNISED_PROPERTY_TYPE_WRONG, describeType(pv.getValue()), propV.getName(), type, propV.typeSummary()), IssueSeverity.ERROR); logError(errors, ValidationMessage.NO_RULE_DATE, line(pv.getValue()), col(pv.getValue()), path, IssueType.STRUCTURE, this.context.formatMessage(I18nConstants.UNRECOGNISED_PROPERTY_TYPE_WRONG, describeType(pv.getValue()), propV.getName(), type, propV.typeSummary()), IssueSeverity.ERROR);
} }

View File

@ -205,14 +205,35 @@ public class Property {
return ed.getType().get(0).getWorkingCode(); return ed.getType().get(0).getWorkingCode();
} }
public boolean hasType(String elementName) { public boolean typeIsConsistent(String typeName) {
for (TypeRefComponent tr : definition.getType()) {
if (typeName.equals(tr.getWorkingCode()) || typeSpecializes(tr.getWorkingCode(), typeName)) {
return true;
}
}
return false;
}
private boolean typeSpecializes(String workingCode, String typeName) {
if ("string".equals(typeName)) {
return Utilities.existsInList(workingCode, "uri", "oid", "canonical", "url", "uuid", "id", "markdown");
}
if ("integer".equals(typeName)) {
return Utilities.existsInList(workingCode, "positiveInt", "unsignedInt");
}
return false;
}
public boolean hasType(String typeName) {
if (type != null) { if (type != null) {
return false; // ? return false; // ?
} else if (definition.getType().size() == 0) { } else if (definition.getType().size() == 0) {
return false; return false;
} else if (isJsonPrimitiveChoice()) { } else if (isJsonPrimitiveChoice()) {
for (TypeRefComponent tr : definition.getType()) { for (TypeRefComponent tr : definition.getType()) {
if (elementName.equals(tr.getWorkingCode())) { if (typeName.equals(tr.getWorkingCode())) {
return true; return true;
} }
} }
@ -227,7 +248,7 @@ public class Property {
if (all) if (all)
return true; return true;
String tail = definition.getPath().substring(definition.getPath().lastIndexOf(".")+1); String tail = definition.getPath().substring(definition.getPath().lastIndexOf(".")+1);
if (tail.endsWith("[x]") && elementName.startsWith(tail.substring(0, tail.length()-3))) { if (tail.endsWith("[x]") && typeName.startsWith(tail.substring(0, tail.length()-3))) {
// String name = elementName.substring(tail.length()-3); // String name = elementName.substring(tail.length()-3);
return true; return true;
} else } else
@ -706,5 +727,5 @@ public class Property {
return false; return false;
} }
} }