jsonschema

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package jsonschema is a tiny stdlib-only JSON-schema validator scoped to the keyword subset that the Clockify MCP server's one-user tool input schemas actually use. It is intentionally narrow:

Supported keywords:

  • type: object, string, integer, number, boolean, array, null
  • required (array of strings on objects)
  • additionalProperties: false (true is a no-op)
  • properties (recursive)
  • items (array element schema)
  • minItems (array)
  • minimum / maximum (integer and number)
  • minLength / maxLength (string)
  • pattern (regexp; anchored via ^...$ if not already)
  • format: date / date-time (lenient time.Parse) / email (minimal shape)
  • enum (array of any; exact JSON-equal match)
  • anyOf (array of schemas; at least one must validate)

Not supported (deliberately): $ref, $defs, allOf/oneOf, not, conditionals (if/then/else), dependentSchemas, const, exclusiveMinimum/exclusiveMaximum, multipleOf, propertyNames, patternProperties. None of those keywords appear in the current tool surface and adding them would pull complexity with no caller.

Values are validated against the JSON-shaped tree the caller passes in, which in the server is always a map[string]any produced by json.Unmarshal. Integer-vs-number distinction follows Go's native type system: json.Unmarshal decodes every numeric literal as float64, so `type: integer` accepts any float64 whose fractional part is zero.

The validator returns *ValidationError on failure. The caller is expected to wrap that inside a protocol-specific error type (e.g. mcp.InvalidParamsError) and emit the wire response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(schema map[string]any, value any) error

Validate reports whether value conforms to schema. A nil schema is treated as "no constraints" and always succeeds. A nil value against a schema with type: object is rejected as a type error so the caller sees the failing path rather than a segfault.

Types

type ValidationError

type ValidationError struct {
	Pointer string
	Message string
}

ValidationError reports a single validation failure with its JSON Pointer path (RFC 6901). Pointer is empty ("") when the root value itself is the offender.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL