validate

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package validate checks arguments against the contract before a request goes out.

This is the most direct payoff of reading OpenAPI rather than linking a generated SDK. In generated Go a field is just `Name string`; it does not know it is capped at 128 characters, and `DiskTypeId string` does not know it must be a UUID. Those constraints exist only in the contract.

$ leaflow compute disk create --name <129 chars> --size-gb 0
error: --name is longer than 128 characters (got 129)
       --size-gb must be at least 1 (got 0)

The alternative is a 400 written for API callers, which does not contain the word "--size-gb" and has to be translated back to the flag by hand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Value

func Value(schema *openapi3.Schema, value any, label Labeler) error

Types

type Error

type Error struct {
	Problems []string
}

Error carries every problem at once. Reporting one at a time would make someone fix three mistakes in three round trips.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap places a validation failure among the transport's kinds, so that one question — "were the arguments wrong?" — has one answer whether the contract caught it here or the service caught it there.

type Labeler

type Labeler func(path []string) string

Labeler translates a JSON field path into the name the user typed. The validator knows `/size_gb`; the user typed `--size-gb`.

Jump to

Keyboard shortcuts

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