-
Notifications
You must be signed in to change notification settings - Fork 249
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
Validate variable keys as part of schema #2530
Conversation
The unit tests that fail are angry about the capitalised
My understanding is that this is an illegal name and would be rejected when the application ran. Are we happy to modify these UI tests, or is the mixed-case variable name intentional? I'm happy to close this PR if we want to retain this existing behaviour. |
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.
A couple of non-load-bearing comments
crates/serde/src/id.rs
Outdated
@@ -8,6 +8,11 @@ use serde::{Deserialize, Serialize}; | |||
#[serde(into = "String", try_from = "String")] | |||
pub struct Id<const DELIM: char>(String); |
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 think I would either make this even more generic:
pub struct Id<const DELIM: char>(String); | |
pub struct Id<const DELIM: char, const LOWER: bool>(String); |
or flatten these all out into separate impls.
🤷
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.
The even more generic approach works out really nicely. Thanks!
crates/manifest/src/compat.rs
Outdated
@@ -149,3 +149,11 @@ fn id_from_string<const DELIM: char>(id: String) -> Result<spin_serde::id::Id<DE | |||
.try_into() | |||
.map_err(|err: String| Error::InvalidID { id, reason: err }) | |||
} | |||
|
|||
fn lower_id_from_string<const DELIM: char>( |
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.
Git tells me I wrote id_from_string
; why didn't I make a TryFrom<String>
I wonder? 🤔
I think I was vaguely thinking about forward-compatibility with value imports (which will allow mixed case like this), but given that the env provider can't currently distinguish casing like this I think its fine to enforce lowercase for now. |
0d2d77c
to
7d3d306
Compare
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
7d3d306
to
d4a67d3
Compare
This works towards #2520 by enforcing variable key constraints in the manifest schema instead of at trigger time: this allows them to get picked up by
spin build
.There's a risk this earlier validation could cause something to break, or to break in different ways. (Indeed I see some unit tests that I forgot to run already going a cheery red.) In particular, the error message at
spin up
changes from:to:
which is slightly less specific in terms of explaining the error but slightly more specific in terms of locating it in the TOML!
There is also, I guess, a risk that this could block something that was legal before, but I'm pretty sure it doesn't. Not sure how to validate this other than by the power of reviewers' brains!
I completely understand if folks feel this is not worth the extra code or the extra risk, just putting it out there if we want it.
Quick note on the implementation: I layered this onto the
Id
type rather than the rawString
type. This arguably creates unnecessary indirection, but means it is guaranteed to inherit tweaks or bug fixes to theId
reader if there ever are any. I'm happy to back this out and put it directly overString
with a shared helper for the separator stuff if people prefer!