RockSolid. Traversal
(rock_solid v0.0.6)
Copy Markdown
Utilities and functions to traverse schemas, collect keywords, etc.
Summary
Functions
Returns whether the reversed path is a definiiton.
Returns whether the reversed path is part of a dependency definition
Returns the value at the given location in the schema.
Returns whether the reversed path should be treated as a literal
Returns whether the current (reversed) path is properties
Returns a map of all references ($id, $anchor, $ref) and their corresponding values in the format
Converts a JSON pointer to a path
Converts a JSON path list to a pointer.
Sets a value in the given (existing) path and returns the updated schema
Types
@type path_t() :: [String.t()]
Functions
Returns whether the reversed path is a definiiton.
Examples
iex> RockSolid.Traversal.definition?(["type", "#"])
false
iex> RockSolid.Traversal.definition?(["$defs", "#"])
true
Returns whether the reversed path is part of a dependency definition
Examples
iex> RockSolid.Traversal.dependencies?(["dependentSchemas", "#"])
true
iex> RockSolid.Traversal.dependencies?(["dependentSchemas", "properties", "#"])
false
Returns the value at the given location in the schema.
The path argument may contain a leading "#". You can convert a JSON Pointer string
to a valid path by calling to_path/1
Examples
iex> RockSolid.Traversal.get_in_schema(%{"foo" => %{"bar" => "baz"}}, ["#", "foo", "bar"])
"baz"
iex> RockSolid.Traversal.get_in_schema(%{"foo" => ["a", "b"]}, ["#", "foo", "1"])
"b"
Returns whether the reversed path should be treated as a literal
Returns whether the current (reversed) path is properties
Examples
iex> RockSolid.Traversal.property?(["type", "#"])
false
iex> RockSolid.Traversal.property?(["properties", "person", "$defs", "#"])
true
iex> RockSolid.Traversal.property?(["properties", "properties", "meta", "$defs", "#"])
false
Returns a map of all references ($id, $anchor, $ref) and their corresponding values in the format
%{"$ref" => %{["#", "path"] => value}, "$id" => %{}}
Converts a JSON pointer to a path
Examples
iex> RockSolid.Traversal.to_path("#/$defs/something")
["#", "$defs", "something"]
iex> RockSolid.Traversal.to_path("#/paths/~1users")
["#", "paths", "/users"]
iex> RockSolid.Traversal.to_path("/path/to/0/foo")
["path", "to", "0", "foo"]Options
:include_root?-boolean/0whether to include the root"#". Defaults totrue
Converts a JSON path list to a pointer.
If the list does not start with "#" it is assumed to be a reversed path
Examples
iex> RockSolid.Traversal.to_pointer(["#", "$defs", "foo"])
"#/$defs/foo"
iex> RockSolid.Traversal.to_pointer(["bar", "$defs", "#"])
"#/$defs/bar"
iex> RockSolid.Traversal.to_pointer(["#", "/users", "GET"])
"#/~1users/GET"
Sets a value in the given (existing) path and returns the updated schema
Examples
iex> RockSolid.Traversal.update_in_schema(%{"foo" => ["a", "b"]}, ["#", "foo", "1"], "c")
%{"foo" => ["a", "c"]}