-
Notifications
You must be signed in to change notification settings - Fork 332
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 additional properties in schema generation #1307
Comments
It seems you can accomplish this with.. |
Where exactly do you see the problem? |
Basically, it works if you just use: #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct MigrateMsg {
pub payout: String,
} |
I see. Then we only have |
Yes, but only on the top level, not inside each variant. Or the results. |
@JakeHartnell check this out |
Should we start using I'm not a rust dev, but I'm still curious — is it possible to make a macro for the macro?
becomes super simplified, something like
which would expand into the stuff it needs. I guess it could also give us flexibility later to change whatever the macro does in case we create new methods for packaging contracts. |
I think this is fine for now. It will disallow additional fields during deserialization as a side effect which might even be helpful to detect wrong JSON requests sent by the client. A custom macro would be more work, also not trivial because of interactions with other macros. We can go that route mid term for sure but it will not be quick. Good to know what we need before. |
@webmaster128 shouldn't this be simple as like #[proc_macro_attribute]
pub fn cosmwasm_schema(_metadata: proc_macro::TokenStream, input: proc_macro::TokenStream)
-> proc_macro::TokenStream {
let input: TokenStream = input.into();
let output = quote! {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(deny_unknown_fields)]
#input
};
output.into()
} #[cosmwasm_schema]
struct QuerySomething { .. } utilizing attribute macro to modify derives. |
@uint could you check out this suggestion? 👆 |
And with attribute macro, we should theoretically, do things like #[cosmwasm_schema_mod]
mod msg {
#[cosmwasm_schema]
pub enum QueryMsg { .. }
} That is generate single |
Yeah, I tried to avoid attribute macros since derives seem less "invasive", but they also complicate things for us implementation-wise. I think we should go for the attribute macro. I don't know if I'd go so far as to create an attribute macro for the whole module. At that point we're duplicating the work Sylvia is already doing and we should probably focus on releasing Sylvia faster instead. |
@iboss-ptk I started a PR that implements your suggestion: #1345 |
This is a bit annoying with the generated typescript types, with
{[k: string]: unknown}
.We can turn it off by adding
additionalProperties: false
in the json schema we export.The text was updated successfully, but these errors were encountered: