Skip to content

New schema; no codegen yet #2495

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

New schema; no codegen yet #2495

wants to merge 8 commits into from

Conversation

aumetra
Copy link
Member

@aumetra aumetra commented Jun 10, 2025

I dunno. I mean the PR is huge lines wise, yeah, but most of that is lockfiles being regenerated and schema files that have to be generated. Kinda necessary.

The codegen will be PR'd separately in an attempt to make it kinda smaller focus-wise?

@aumetra aumetra force-pushed the aw/only-schema branch 2 times, most recently from 2e2323f to d039224 Compare June 10, 2025 08:39
@aumetra aumetra requested a review from chipshort June 10, 2025 10:28
Copy link
Collaborator

@chipshort chipshort left a comment

Choose a reason for hiding this comment

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

Nice work! I like the insta tests. I left some comments inline.

where
T: ?Sized,
{
// Taken from <sagebind/castaway>: https://github.com/sagebind/castaway/blob/a7baeab32d75d0f105d1415210a2867d213f8818/src/utils.rs#L36
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wild stuff. At first, I wasn't quite sure that the transmute is fine, but should be ok given that it's transmuting a PhantomData that is never used.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, its basically the implementation that's currently in castaway. checked through it and it seems to be fine. just a cast to 'static so the lifetimes can be ignored.

Copy link
Member Author

Choose a reason for hiding this comment

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

and yep, due to the hacky nature the id is intentionally completely opaque. meaning if there's a better/less hacky way possible, it can be swapped out in future releases without any semver breakage

Copy link
Member Author

Choose a reason for hiding this comment

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

(i mean for peace of mind we can also run the tests for cw-schema with miri. that way we can be sure it doesn't produce any UB)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just today, I found this crate. Maybe it's better to use that? The underlying implementation seems to be the same, but I would assume dtolnay would notice earlier than us if a problem with that implementation was found.


const DISABLE_WARNINGS_VAR: &str = "SHUT_UP_CW_SCHEMA_DERIVE";

fn print_warning(title: impl Display, content: impl Display) -> io::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to add a code location to the warning?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. probably from the span. gonna look into that

Comment on lines +101 to +102
#[doc(hidden)]
pub use self::idl::JsonCwApi;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the reexport needed? It doesn't seem to be used anywhere.

@@ -70,13 +72,21 @@ pub trait QueryResponses: JsonSchema {
}

fn response_schemas_impl() -> BTreeMap<String, RootSchema>;

fn response_schemas_cw() -> Result<BTreeMap<String, cw_schema::Schema>, IntegrityError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is there even a Result here if it never fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

just copied the above definitions to duplicate and tweak it as a quick hack to get the automatic codegen working. but agreed, the errors can be omitted (on both schemas actually)

Comment on lines +111 to +121
/*print_warning(
"unknown serde attribute",
format!(
"unknown attribute \"{}\"",
meta.path
.get_ident()
.map(|ident| ident.to_string())
.unwrap_or_else(|| "[error]".into())
),
)
.unwrap();*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

With this commented out, it would be easy to miss incorrect schema being generated, but it's also quite annoying to get lots of warnings.
Can we add some attribute to suppress the warnings locally (on the field or on the container level?). Like #[allow(unknown_serde_attr)]? Only having the env var seems a bit coarse.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, an attribute would be possible. didn't think about that tbh, gonna implement that

)
.unwrap();*/

// TODO: support other serde attributes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we create an issue to track this (and the other TODO for SerdeFieldOptions)?

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.

2 participants