-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add a schema validator / checker #129
Comments
I agree that this would be a useful addition. I know that lxml has some XSD-based validation capabilities already. Since lxml is already a dependency, maybe we can look at whether it would suffice? |
That looks great if we can leverage what we already have as a dependency! |
Does it make the most sense to automatically try to validate against the schema upon instantiation of the |
Probably if it is a quick check, we already have the built-in dependency, and it doesn't raise on valid but complex schemas. It would be good to make sure wherever we add it that we add useful information saying why the schema match failed. |
Here is a little example of doing schema validation with lxml. TIL that
The results of this validation are absolutely useless for debugging (True/False) so I used this tool to fix things: |
Indeed. BTW, I started exploring this—I have a branch called I've found that using the assertion-based validation is a lot better/more useful than just the boolean |
@cgobat That's great! Do you want to own this feature or would you rather someone else use that as a starting point? I would like to add automatic retrieval of XTCE XSD via the I'm almost ready with a PR that handles namespaces much better, which might help with this. |
Yeah I'm happy to own the initial implementation at least. That's good to know that you're in favor of automatic retrieval of the specified XSD. I was going to do that but held off since I wasn't sure how we felt about fetching content from online. Are you okay with adding |
Actually, nevermind. I think I can do it with just the standard library |
Yeah, let's avoid another dependency if we don't need it. If we start doing a lot of HTTP requests for some other reason, then let's consider including requests. |
And as for fetching XML online, it is technically a security vulnerability since parsing XML with lxml is vulnerable to things like XML bombs if you're using an old version of libxml. We could limit the XSD retrieval to a validation method that is only called if the user explicitly requests it. This has the dual purpose of not inherently slowing down definition instantiation from XTCE, which has been a problem in the past. |
It would be helpful to add a schema validation step or point to advice for how to do this for new users just setting up their initial XTCE documents. There is an official xsd document: https://www.omg.org/spec/XTCE/20180204/SpaceSystem.xsd
This would also catch incorrect implementations on our end, like with the float naming identified in #128
A quick search shows there are some packages that do this, although I have no idea how robust/useful they would be: https://xmlschema.readthedocs.io/en/latest/usage.html
Some questions to think about:
The text was updated successfully, but these errors were encountered: