Files
upstream-mirror 9456a4e922
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/keto.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:08:34 +05:00

121 lines
2.2 KiB
Markdown

# JSON Schema Helpers
This package contains utilities for working with JSON Schemas.
## Listing all Possible JSON Schema Paths
Using `jsonschemax.ListPaths()` you can get a list of all possible JSON paths in
a JSON Schema.
```go
package main
import (
"bytes"
"fmt"
"github.com/ory/jsonschema/v3"
"github.com/ory/x/jsonschemax"
)
var schema = "..."
func main() {
c := jsonschema.NewCompiler()
_ = c.AddResource("test.json", bytes.NewBufferString(schema))
paths, _ := jsonschemax.ListPaths("test.json", c)
fmt.Printf("%+v", paths)
}
```
All keys are delimited using `.`. Please note that arrays are denoted with `#`
when `ListPathsWithArraysIncluded` is used. For example, the JSON Schema
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"providers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
}
}
}
}
```
Results in paths:
```json
[
{
"Title": "",
"Description": "",
"Examples": null,
"Name": "providers",
"Default": null,
"Type": [],
"TypeHint": 5,
"Format": "",
"Pattern": null,
"Enum": null,
"Constant": null,
"ReadOnly": false,
"MinLength": -1,
"MaxLength": -1,
"Required": false,
"Minimum": null,
"Maximum": null,
"MultipleOf": null,
"CustomProperties": null
},
{
"Title": "",
"Description": "",
"Examples": null,
"Name": "providers.#",
"Default": null,
"Type": {},
"TypeHint": 5,
"Format": "",
"Pattern": null,
"Enum": null,
"Constant": null,
"ReadOnly": false,
"MinLength": -1,
"MaxLength": -1,
"Required": false,
"Minimum": null,
"Maximum": null,
"MultipleOf": null,
"CustomProperties": null
},
{
"Title": "",
"Description": "",
"Examples": null,
"Name": "providers.#.id",
"Default": null,
"Type": "",
"TypeHint": 1,
"Format": "",
"Pattern": null,
"Enum": null,
"Constant": null,
"ReadOnly": false,
"MinLength": -1,
"MaxLength": -1,
"Required": false,
"Minimum": null,
"Maximum": null,
"MultipleOf": null,
"CustomProperties": null
}
]
```