mailschema

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 8 Imported by: 0

README

MailSchema for Go

Typed Mail Action Protocol 0.1 documents and canonical JSON Schemas for Go.

go get github.com/mailschema/go@v0.1.0
package main

import (
    "os"

    mailschema "github.com/mailschema/go"
)

func main() {
    request, err := mailschema.Decode[mailschema.Request](os.Stdin)
    if err != nil {
        panic(err)
    }
    if err := mailschema.ValidateRequest(request); err != nil {
        panic(err)
    }
}

Schema(mailschema.MAP01Schema), Schema(mailschema.ContentReview01Schema) and Schema(mailschema.ContributionSchema) return independent copies of the bundled schemas. The validation helpers check the fixed MAP identifiers and core references; use the bundled Draft 2020-12 schemas when complete schema validation is required.

The package performs no network requests. It does not send email, establish endpoint trust or grant service authorization.

MIT licensed.

Documentation

Index

Constants

View Source
const (
	Profile01         = "https://mailschema.org/profiles/map/0.1"
	Context01         = "https://mailschema.org/contexts/map-0.1.jsonld"
	ContentReviewType = "https://mailschema.org/types/content-review"
)

Variables

This section is empty.

Functions

func Decode

func Decode[T any](reader io.Reader) (T, error)

Decode reads one strict JSON document. Unknown fields and trailing values are rejected.

func Schema

func Schema(name SchemaName) ([]byte, error)

Schema returns an independent copy of a bundled JSON Schema document.

func ValidateDescription

func ValidateDescription(value Description) error

ValidateDescription checks the fixed MAP 0.1 identifiers and core trust-relevant fields. Use the bundled JSON Schema for complete structural validation.

func ValidateRequest

func ValidateRequest(value Request) error

ValidateRequest checks a MAP 0.1 request's fixed identifiers and references. Type-specific input constraints remain in the type schema.

Types

type Authorization

type Authorization struct {
	Kind     string   `json:"kind"`
	Schemes  []string `json:"schemes"`
	Audience string   `json:"audience,omitempty"`
}

type Description

type Description struct {
	Context     string        `json:"@context"`
	Kind        string        `json:"@type"`
	ID          string        `json:"@id"`
	Profile     string        `json:"profile"`
	Type        TypeReference `json:"type"`
	DescribedAt time.Time     `json:"describedAt"`
	ExpiresAt   time.Time     `json:"expiresAt"`
	Service     Service       `json:"service"`
	Target      Target        `json:"target"`
	Operations  []Operation   `json:"operations"`
}

type Execution

type Execution struct {
	URL                    string `json:"url"`
	Method                 string `json:"method"`
	RequestMediaType       string `json:"requestMediaType"`
	ResultMediaType        string `json:"resultMediaType"`
	ResultURLTemplate      string `json:"resultUrlTemplate"`
	ResultRetentionSeconds int    `json:"resultRetentionSeconds"`
}

type Operation

type Operation struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	InputSchema string `json:"inputSchema"`
}

type Problem

type Problem struct {
	Type          string  `json:"type"`
	Title         string  `json:"title"`
	Status        int     `json:"status"`
	Detail        string  `json:"detail"`
	Instance      string  `json:"instance"`
	Profile       string  `json:"profile"`
	RequestID     string  `json:"requestId"`
	InteractionID string  `json:"interactionId"`
	Code          string  `json:"code"`
	Target        *Target `json:"target,omitempty"`
}

type Request

type Request struct {
	Kind          string         `json:"kind"`
	Profile       string         `json:"profile"`
	RequestID     string         `json:"requestId"`
	InteractionID string         `json:"interactionId"`
	RequestedAt   time.Time      `json:"requestedAt"`
	Type          TypeReference  `json:"type"`
	Operation     string         `json:"operation"`
	Target        Target         `json:"target"`
	Input         map[string]any `json:"input"`
}

type Result

type Result struct {
	Kind          string         `json:"kind"`
	Profile       string         `json:"profile"`
	RequestID     string         `json:"requestId"`
	InteractionID string         `json:"interactionId"`
	Operation     string         `json:"operation"`
	State         string         `json:"state"`
	Target        Target         `json:"target"`
	RecordedAt    time.Time      `json:"recordedAt"`
	ResultURL     string         `json:"resultUrl"`
	Output        map[string]any `json:"output"`
}

type SchemaName

type SchemaName string

SchemaName identifies a schema bundled with this module.

const (
	ContributionSchema    SchemaName = "contribution"
	MAP01Schema           SchemaName = "map-0.1"
	ContentReview01Schema SchemaName = "content-review-0.1"
)

type Service

type Service struct {
	ID            string        `json:"id"`
	Name          string        `json:"name"`
	Execution     Execution     `json:"execution"`
	HumanURL      string        `json:"humanUrl"`
	Authorization Authorization `json:"authorization"`
}

type Target

type Target struct {
	ID       string `json:"id"`
	Revision string `json:"revision"`
	Title    string `json:"title,omitempty"`
	Digest   string `json:"digest"`
}

type TypeReference

type TypeReference struct {
	ID           string `json:"id"`
	Version      string `json:"version"`
	RecordDigest string `json:"recordDigest"`
}

Jump to

Keyboard shortcuts

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