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
SecretStringandSecretBox<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
Configstruct that uses bothSecretStringandSecretBox:We derive
JsonSchemain order to add JSON Schema support.Then, we export a schema:
The schema produced looks like this:
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Config", "type": "object", "required": [ "number", "password", "username" ], "properties": { "number": { "$ref": "#/definitions/SecretBox_for_uint64" }, "password": { "$ref": "#/definitions/SecretString" }, "username": { "$ref": "#/definitions/SecretString" } }, "definitions": { "SecretBox_for_uint64": { "type": "integer", "format": "uint64", "minimum": 0.0 }, "SecretString": { "type": "string" } } }We then add a
.vscode/settings.jsonfile registering the schema and applying it againstconfig.json:{ "json.schemas": [ { "fileMatch": [ "config.json", ], "url": "./config.schema.json", }, ] }Now, the contents of
config.jsonare validated against the schema:Once the validation rules are satisfied, we end up with this configuration:
{ "username": "foo", "password": "bar", "number": 123 }Finally, we can deserialize the configuration using
serdeand 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.