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

Add a command line flag to prevent writing 'deny_unknown_fields' #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ehiggs
Copy link

@ehiggs ehiggs commented Nov 13, 2022

Problem:
A server can add backwards compatible optional fields which will break the client if it fails when we parse a response because we deny unknown fields.

Solution: Rather than remove that altogether (I assume you put it in for a good reason), I added a command line flag to prevent writing deny_unknown_fields to files. Plumbed this through in a more general 'options' field so further fields can be added without changing signatures in the future, or adding a large number of arguments to functions.

Without flag

❯ ./target/release/schemafy ActorInput.json --root ActorInput 
#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ActorInput {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<Vec<String>>,
}

With flag:

schemafy on  fix/allow-unknown-parameters is 📦 v0.6.0 via 🦀 v1.65.0 
❯ ./target/release/schemafy ActorInput.json --root ActorInput --allow-unknown-fields
#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)]
pub struct ActorInput {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<Vec<String>>,
}

files. Plumb this through in a more general 'options' field so further
fields can be added without changing signatures in the future, or adding
a large number of arguments to functions.
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