WardrikRest.Schema (wardrik_rest v0.1.0-rc.1)

Copy Markdown

Fits an operation's arguments into a size budget, as the JSON Schema of its tool.

Objects are listed as deep as the budget allows, the same depth for every argument, whether they're the spec's types or written in place. An object past that depth is left as an object that names it: a type by its name, and one written in place by its path from the tool or the type it's in. One inside itself is "A FilterExpression, as above.".

%{"type" => "object", "description" => "A Campaign; ads__describe gives its fields."}

%{"type" => "object",
  "description" => ~s(An object; stripe__describe gives its fields as "stripe__PostCharges/shipping".)}

Only arguments keep their descriptions; describe/4 gives an object's.

Summary

Types

JSON Schemas by name, which may refer to each other as %{"$ref" => name}.

Functions

Returns the object name names, with its fields' descriptions, and the objects inside it as named objects. name is a type of types, or a path from one or from a tool of tools, the JSON Schema of each tool's arguments by its name. describe names the tool that describes them.

Returns the JSON Schema of each of parameters, by name, within budget bytes of JSON where it can be, and the names of the objects it left out. tool is the tool's name, which paths start from, and describe names the tool that describes them.

Types

types()

@type types() :: %{required(String.t()) => map()}

JSON Schemas by name, which may refer to each other as %{"$ref" => name}.

Functions

describe(types, tools, name, describe)

@spec describe(types(), %{required(String.t()) => map()}, String.t(), String.t()) ::
  {:ok, map()} | :error

Returns the object name names, with its fields' descriptions, and the objects inside it as named objects. name is a type of types, or a path from one or from a tool of tools, the JSON Schema of each tool's arguments by its name. describe names the tool that describes them.

fit(parameters, types, budget, arg)

@spec fit(
  [WardrikRest.Parameter.t()],
  types(),
  pos_integer(),
  {String.t(), String.t()}
) ::
  {%{required(String.t()) => map()}, [String.t()]}

Returns the JSON Schema of each of parameters, by name, within budget bytes of JSON where it can be, and the names of the objects it left out. tool is the tool's name, which paths start from, and describe names the tool that describes them.