mamori schema

Emits a JSON Schema (draft 2020-12) derived from each qualifying struct’s field types and validate: tags, ready to feed straight into a JSON Schema validator.

mamori schema [patterns...] [--type=Name]
  • --type=Name narrows to one struct by name.
  • If exactly one struct qualifies, the output is a single schema document. If more than one qualifies, it is a JSON array of documents, each carrying a title of package.TypeName.

Schema output

$ mamori schema ./... --type=Config
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "main.Config",
  "type": "object",
  "properties": {
    "Redis": {
      "type": "object",
      "properties": {
        "Addr": { "type": "string" },
        "Password": { "type": "string" }
      },
      "required": ["Addr", "Password"]
    },
    "Timeout": { "type": "integer", "minimum": 1, "default": 30 }
  }
}

How validate tags map

validate: ruleJSON Schema
requiredfield listed in the object’s required array
oneof=a b cenum
gte / lte (numeric only)minimum / maximum
min / max on a number fieldminimum / maximum
min / max on a string fieldminLength / maxLength

A field is also required when it has no default: and is not optional:"true". A default: tag becomes the schema’s default, typed as a JSON number where the field is numeric.

Custom provider schemes

Sensitivity is computed from the same built-in scheme set mamori vet uses, which only knows the providers mamori ships. If you wrote your own provider, name its scheme so its fields are treated as secrets here too:

mamori schema --secret-schemes=mysecrets ./...

The flag adds to the built-in set rather than replacing it, takes a bare scheme token (not a full ref), and is accepted by explain, schema, policy, vet, and doctor --compare, so every command agrees on what counts as a secret.

See also

mamori explain lists the same structs as a table. CLI overview.