14

It is possible to add additional or custom metadata (other than title and description) to a json schema property?

Ideally I'd like to add some metadata like so:

//...
"properties": {
  "contactFullName": {
    "$ref": "#/definitions/fullName",
    "custom": "my custom metadata here"
  }
}
//...

Can you add something to definitions to allow that?

kreek
  • 8,774
  • 8
  • 44
  • 69

2 Answers2

26

You don't have to do anything special to use additional metadata keywords. You can just use them. In JSON Schema it is not an error to include undefined keywords. Anything that doesn't have JSON Schema semantics should be quietly ignored. So, the following schema is completely valid and should not conflict with any validator implementation.

{
  "title": "Foo",
  "description": "All the foo you can GET",
  "version": "1.0.3",
  "author": "Jason Desrosiers",
  "type": "object",
  "properties": {
    "id": { "type": "string" }
  }
}
Jason Desrosiers
  • 22,479
  • 5
  • 47
  • 53
  • 11
    I think that the answer should point out that there is no custom metadata in json schema. You can create own but there is no guarantee that name wouldn't be used in next json schema version. – S.R Apr 20 '20 at 07:29
2

You could use the description property and put a certain structure in there that could then be interpreted and applied as needed (like JSON within a JSON schema, so to speak).

rasmeister
  • 1,986
  • 1
  • 13
  • 19