contract

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package contract enforces the funcd contract type profile (ADR-0058): the bounded, language-agnostic subset of JSON Schema 2020-12 that a function's I/O contract may use — "the def" (the discipline JTD and WIT apply). A contract is GENERATED from the author's code type (typia / pydantic) and then run through Check before it is shipped or embedded, so a contract can never advertise a shape a peer runtime (or the registry) can't honor.

Supported: scalars (string + format date-time/uuid/email/uri, pattern, length; integer + format int32/int64; number; boolean), string enums, CLOSED objects (additionalProperties:false), arrays, string-keyed maps (additionalProperties:<type>, no properties), DISCRIMINATED unions (oneOf + discriminator), optional/nullable, and the explicit `Json` form (the empty schema {} — arbitrary JSON).

Forbidden (Check returns a fault.Invalid naming the construct): OPEN records (additionalProperties true/absent on a record), NON-DISCRIMINATED oneOf/anyOf/allOf, not, if/then/else, external/recursive $ref, and recursive types (which require $ref).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(schemaJSON []byte) error

Check reports whether a JSON Schema (a generated function I/O contract) lies within the funcd profile. It returns nil when every construct is supported, or a fault.Invalid whose message names the first unsupported construct and its JSON-pointer-ish path. A nil/empty input is treated as the `Json` (any) form — valid.

Types

type TypeField added in v0.2.4

type TypeField struct {
	// contains filtered or unexported fields
}

TypeField captures JSON Schema's `type`, which is a string OR an array of strings. The type generator (pkg/sdk) decodes `type` with it too, so it reads every contract the gate accepts.

func (TypeField) Nullable added in v0.2.4

func (t TypeField) Nullable() bool

Nullable reports the ADR-0058 nullable form: a type list that holds "null" beside another type.

func (TypeField) Primary added in v0.2.4

func (t TypeField) Primary() string

Primary returns the first non-"null" type, or "" when no type keyword is present.

func (*TypeField) UnmarshalJSON added in v0.2.4

func (t *TypeField) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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