schemars icon indicating copy to clipboard operation
schemars copied to clipboard

Custom keywords

Open clemens-msupply opened this issue 3 years ago • 2 comments

JSONSchema allows users to define custom keywords. Would it be possible to add support for it to schemars? e.g.

#[derive(JsonSchema)]
pub struct MyStruct {
    #[schemars(custom_keyword(name = "myKeyword", value = "some custom metadata"))]
    pub my_int: i32,
}

would generate:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "MyStruct",
  "type": "object",
  "required": [
    "my_int"
  ],
  "properties": {
    "my_int": {
      "type": "integer",
      "format": "int32",
      "myKeyword": "some custom metadata")
    },
  },
}

clemens-msupply avatar May 24 '22 21:05 clemens-msupply

This is currently possible though manual implementation. Not though the macro. Manual implementation of struct example: #119 Use the extensions field in the SchemaObject.

Adding support for it though macros might be added, but not any time soon I expect.

ralpha avatar Jul 09 '22 13:07 ralpha

I'm looking to add custom metadata to properties as well, ideally in-line with the type definition through an attribute. I'm building a configuration tool on top of json schemas and want to indicate for various properties whether they should be visible by default or only for advanced users.

mickvangelderen avatar Nov 18 '22 14:11 mickvangelderen