github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/jsonschemax/README.md (about)

     1  # JSON Schema Helpers
     2  
     3  This package contains utilities for working with JSON Schemas.
     4  
     5  ## Listing all Possible JSON Schema Paths
     6  
     7  Using `jsonschemax.ListPaths()` you can get a list of all possible JSON paths in a JSON Schema.
     8  
     9  ```go
    10  package main
    11  
    12  import (
    13  	"bytes"
    14  	"fmt"
    15  	"github.com/ory/jsonschema/v3"
    16  	"github.com/ory/x/jsonschemax"
    17  )
    18  
    19  var schema = "..."
    20  
    21  func main() {
    22  	c := jsonschema.NewCompiler()
    23  	_ = c.AddResource("test.json", bytes.NewBufferString(schema))
    24  	paths, _ := jsonschemax.ListPaths("test.json", c)
    25  	fmt.Printf("%+v", paths)
    26  }
    27  ```
    28  
    29  All keys are delimited using `.`. Please note that arrays are denoted with `#` when `ListPathsWithArraysIncluded` is used. For example, the JSON Schema
    30  
    31  ```json
    32  {
    33    "$schema": "http://json-schema.org/draft-07/schema#",
    34    "properties": {
    35      "providers": {
    36        "type": "array",
    37        "items": {
    38          "type": "object",
    39          "properties": {
    40            "id": {
    41              "type": "string"
    42            }
    43          }
    44        }
    45      }
    46    }
    47  }
    48  ```
    49  
    50  Results in paths:
    51  
    52  ```json
    53  [
    54    {
    55      "Title": "",
    56      "Description": "",
    57      "Examples": null,
    58      "Name": "providers",
    59      "Default": null,
    60      "Type": [],
    61      "TypeHint": 5,
    62      "Format": "",
    63      "Pattern": null,
    64      "Enum": null,
    65      "Constant": null,
    66      "ReadOnly": false,
    67      "MinLength": -1,
    68      "MaxLength": -1,
    69      "Required": false,
    70      "Minimum": null,
    71      "Maximum": null,
    72      "MultipleOf": null,
    73      "CustomProperties": null
    74    },
    75    {
    76      "Title": "",
    77      "Description": "",
    78      "Examples": null,
    79      "Name": "providers.#",
    80      "Default": null,
    81      "Type": {},
    82      "TypeHint": 5,
    83      "Format": "",
    84      "Pattern": null,
    85      "Enum": null,
    86      "Constant": null,
    87      "ReadOnly": false,
    88      "MinLength": -1,
    89      "MaxLength": -1,
    90      "Required": false,
    91      "Minimum": null,
    92      "Maximum": null,
    93      "MultipleOf": null,
    94      "CustomProperties": null
    95    },
    96    {
    97      "Title": "",
    98      "Description": "",
    99      "Examples": null,
   100      "Name": "providers.#.id",
   101      "Default": null,
   102      "Type": "",
   103      "TypeHint": 1,
   104      "Format": "",
   105      "Pattern": null,
   106      "Enum": null,
   107      "Constant": null,
   108      "ReadOnly": false,
   109      "MinLength": -1,
   110      "MaxLength": -1,
   111      "Required": false,
   112      "Minimum": null,
   113      "Maximum": null,
   114      "MultipleOf": null,
   115      "CustomProperties": null
   116    }
   117  ]
   118  ```