-
Notifications
You must be signed in to change notification settings - Fork 142
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
StrictXmir #3652
StrictXmir #3652
Conversation
@volodya-lombrozo please, check this one |
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.
/** | ||
* XMIR that validates itself right after construction. | ||
* | ||
* <p>This class is supposed to be used ONLY for testing, because |
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.
@yegor256 I'm a bit confused here. You mentioned in the PR description that this PR closes #3636. And here, in the javadoc you write
This class is supposed to be used ONLY for testing
It means, I won't be able to use StrictXmir
in jeo-maven-plugin
production code. However, I'm using StrictXML
during the xmir
generation. In other words, I use it in the production code.
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.
@volodya-lombrozo you can try to do this, on your side: 1) create XML
object, 2) save it on disc, 3) make StrictXmir(xml)
and 4) either fail, or continue. If you fail, you fail. If you continue, you have a clean XML on disc.
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.
@yegor256 [NIT] I mean, this class might be used not only for testing. Actually it's an important part of validation in a production code. Maybe we need to remove this line from javadoc:
This class is supposed to be used ONLY for testing
and replace it with something like
ATTENTION!
what do you think?
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.
@volodya-lombrozo explained better in 04af5af
).asBytes() | ||
); | ||
} catch (final IOException | URISyntaxException ex) { | ||
throw new IllegalArgumentException(ex); |
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.
@yegor256 [NIT] It's a bad idea by a several reasons:
- Exception without context: https://www.yegor256.com/2015/12/01/rethrow-exceptions.html
- Grouped exceptions: https://www.yegor256.com/2022/08/30/dont-group-exception-catchers.html
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.
@volodya-lombrozo fixed
.xpath("/program") | ||
.attr( | ||
"noNamespaceSchemaLocation xsi http://www.w3.org/2001/XMLSchema-instance", | ||
"https://www.eolang.org/XMIR.xsd" |
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.
@yegor256 You tested only one positive scenario. What will happen if we have a corrupted address? What will happen if we don't have the internet?
https://www.eCORRUPTEDolang.org/XMIR.xsd
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.
@volodya-lombrozo added test in 6f07f8f
).toString().replace("\\", "/") | ||
); | ||
} | ||
new Xembler( |
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.
@yegor256 Do we need to change the xmir
in case !uri.startWith("http")
?
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.
@volodya-lombrozo nope, when it's file://....
we keep it as is
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.
@yegor256 I see. I've overlooked indentations. Thank you.
@volodya-lombrozo we can't stay entirely offline. The schema (XSD) must come from somewhere. Either you download it and then provide to |
@yegor256 Is it possible to place |
@volodya-lombrozo we don't know which version to place there: there are many of them published at www.eolang.org. We can possibly try to download them all during build and put into JAR, but this sounds like a hack. |
@volodya-lombrozo please, check the code one more time, I made some changes |
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.
/** | ||
* XMIR that validates itself right after construction. | ||
* | ||
* <p>This class is supposed to be used ONLY for testing, because |
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.
@yegor256 [NIT] I mean, this class might be used not only for testing. Actually it's an important part of validation in a production code. Maybe we need to remove this line from javadoc:
This class is supposed to be used ONLY for testing
and replace it with something like
ATTENTION!
what do you think?
).toString().replace("\\", "/") | ||
); | ||
} | ||
new Xembler( |
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.
@yegor256 I see. I've overlooked indentations. Thank you.
@yegor256 As I understand it, you publish them from XMIR.xsd. So, when you publish version |
@volodya-lombrozo when you do |
@volodya-lombrozo what we can do is this: |
@yegor256 To be honest, I don't see any reason why we might need such flexibility. We have a single I will try to use |
|
@volodya-lombrozo you can try to use this:
However, 1) this won't work with |
@yegor256
Let me investigate these questions. Maybe it will become clear. And thank you very much for your help. |
@volodya-lombrozo check this one: d0bf3b8 With this feature you will be fine. Just use |
@volodya-lombrozo XML documents that JEO (or any other tool) produces are supposed to be "valid" in terms of compliance with XSD schema. Technically this means that |
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.
@yegor256 There is one common part in all tests:
new StrictXmir(
new Xmir(
new XMLDocument(
new Xembler(
new Directives()
.append(new DrProgram("foo3"))
.xpath("/program")
.attr(
"noNamespaceSchemaLocation xsi http://www.w3.org/2001/XMLSchema-instance",
String.format(
"https://www.eolang.org/xsd/XMIR-%s.xsd",
Manifests.read("EO-Version")
)
)
.add("objects")
).xml()
)
),
tmp
).validate(),
What do you think if we will move into a separate method?
@volodya-lombrozo you are right, duplication reduced: 809adde |
@yegor256 As far as I know, we have several ways to validate an XML document against an XSD schema, and we are not obligated to use only |
@volodya-lombrozo indeed, it's possible to validate it against any XSD schema, but relying on |
related to #3636