Skip to content
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

remove the SemverVersion wrapper struct #7570

Merged
merged 2 commits into from
Feb 22, 2025
Merged

remove the SemverVersion wrapper struct #7570

merged 2 commits into from
Feb 22, 2025

Conversation

iliana
Copy link
Contributor

@iliana iliana commented Feb 20, 2025

What is TODO'd shall be todone:

// TODO: remove wrapper for semver::Version once this PR goes through
// https://github.com/GREsau/schemars/pull/195

We'd like to split tufaceous out into its own repo and and this wrapper struct makes it a little difficult; may as well clean this up in the process.

Comment on lines +31 to +33
{
type = "string",
pattern = r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fascinating, til!

Is there a worry that people will forget to do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several concerns about this approach but it seems least bad given that schemars decided semver::Version ought to be treated as a literal :(

If you don't add this, Progenitor generates a wrapper struct around a String. I don't think it matters that much if you leave it as-is; either you use that, or you get annoyed enough with it that you realize you can do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, does schemars come with an impl for semver::Version? If so then maybe specifying the pattern again isn't required? not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even moving the pattern into a const and using it here doesn't work; the macro wants a literal. (I think it's being directly deserialized into the relevant schemars struct but I didn't get that far into figuring out the Progenitor source.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I bet that's because it accepts a string and not a ParseWrapper<syn::Expr>.

Copy link
Contributor

@sunshowers sunshowers Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah looks like it actually needs the SchemaObject to compare at compile time against. https://github.com/oxidecomputer/progenitor/blob/4a8467a4660df4308890b690808ecb898f128cd1/progenitor-macro/src/lib.rs#L157

Seems unavoidable in that case, I think.

Copy link
Contributor

@david-crespo david-crespo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

@iliana iliana enabled auto-merge (squash) February 21, 2025 20:43
@iliana iliana merged commit b302fc6 into main Feb 22, 2025
18 checks passed
@iliana iliana deleted the iliana/semver branch February 22, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants