-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#353] Validation of external $ref property values should show error … #358
Conversation
…on unexpected object type Validation of reference types has been moved to ReferenceValidator that previously only validate correctness of references pointer/URIs. It now checks the type of the reference if this one is valid, this allow to reuse the code for loading the JSON document which is referenced by it. This validation could be slow because it will parse the referenced documents into Models.
…on unexpected object type
val resolvedURI = new URI(null, null, "/components/parameters/Valid") | ||
val errors = validator(#{resolvedURI -> document.asJson}).validate(baseURI, document) | ||
|
||
assertEquals(0, errors.size()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
if (file == null || !file.exists()) { | ||
return null; | ||
} | ||
|
||
try { | ||
return getDocument(uri.toURL()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are passing an entire URL to JsonDocumentManager.getDocument(URL)
which includes both the file
and ref
parts. JsonDocumentManager.getDocument(URL)
has a table whose keys are URL
s in a form we are passing the here. As a result, for two different refs from the same external model will load the model twice. For example, for the beamup_path_estimates_price.yaml
from the Multi-file Beamup (v3) example the documents
map will contain a different JsonNode model for each parameter:
{<...>/Multi-file%20Beamup%20(v3)/models/components/beamup_parameters.yaml#/components/parameters/start_longitude
={"openapi":"3.0.0", <...>},
<...>/Multi-file%20Beamup%20(v3)/models/components/beamup_parameters.yaml#/components/parameters/end_longitude
={"openapi":"3.0.0",<...>}
}
But it should be a single entry for <...>/Multi-file%20Beamup%20(v3)/models/components/beamup_parameters.yaml
!
We should fix JsonDocumentManager.getDocument(URL)
.
@@ -223,4 +216,19 @@ public static JsonPointer getPointer(ObjectNode node) { | |||
} | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc for JsonReference.isMissing()
should be corrected:
/**
* Returns true if the reference points to an existing JSON document and the pointer to an existing node inside that
* document.
*
* @param baseURI
* @return true if the reference can be resolved.
*/
public boolean isMissing(JsonDocument document, URI baseURI) {
if (isInvalid()) {
return false;
}
JsonNode resolved = resolve(document, baseURI);
return resolved == null || resolved.isMissingNode();
}
It returns true if the reference cannot be resolved and the pointer points to an inexistent element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left several comments including a comment about the documents
cache.
Also, we have several test failures on this branch:
Failed tests:
CodeTemplateTextTest.test_code_template_text:148 JSON Schema validation error:
Tests in error:
ValidatorTest.testValidationShouldFail_ForInvalidPointers:314 » IllegalArgument
ValidatorTest.testValidationShouldFail_refNotJson:368 » Scanner null; mapping ...
…on unexpected object type Fix cache of model documents in DocumentManager. Fix javadoc.
@tfesenko The PR has been updated. |
@ghillairet , I am still getting two test failures on this branch (after merge master in to the task branch, the master is green):
|
Passed code review and QA. |
…on unexpected object type Fix tests
Tests have been fixed. |
MyType1: | ||
type: object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
Looks good. Thanks!! |
…on unexpected object type
Validation of reference types has been moved to ReferenceValidator that previously only validate correctness of references pointer/URIs.
It now checks the type of the reference if this one is valid, this allow to reuse the code for loading the JSON document which is referenced by it.
This validation could be slow because it will parse the referenced documents into Models.
See #353