Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.