-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat: add JSON Schema support #1287
base: main
Are you sure you want to change the base?
Conversation
It seems that the MSRV has to be at least 1.61.0 due to jsonschema v0.8.22 -> serde_json 1.0.217 -> memchr v2.7.4. However, other packages seem to also require a MSRV higher than 1.60.0, since I get the following error whenever I try to run
|
It won't scale for You can get around the problem by copying and pasting the relevant types into your code and adding the relevant trait impls there. |
This isn't an arbitrary 3rd-party crate. This covers a very common use case of |
The other way to do it would be to open a PR to |
I think it would be out of scope to open a PR there, since |
First of all, thank you for your wonderful work on
secrecy
!This PR adds JSON Schema support to
SecretString
andSecretBox<T>
usingschemars
.My use case for JSON Schema is validation of JSON configuration files used by a web server.
Here is a simplified example of how this works.
We start with a
Config
struct that uses bothSecretString
andSecretBox
:We derive
JsonSchema
in order to add JSON Schema support.Then, we export a schema:
The schema produced looks like this:
We then add a
.vscode/settings.json
file registering the schema and applying it againstconfig.json
:Now, the contents of
config.json
are validated against the schema:Once the validation rules are satisfied, we end up with this configuration:
Finally, we can deserialize the configuration using
serde
and use the credentials provided, as normal:I hope this is a suitable contribution to the project and would appreciate feedback if there are any improvements or fixes needed.