endpointdsl

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 14 Imported by: 0 modules, 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 endpointdsl is the endpoint group under osapi controller: the commands that list, describe, scaffold, teach and check the endpoint groups of the controller. The package is not named endpoint, which is the DSL itself.

Index

Constants

This section is empty.

Variables

View Source
var Group = command.Register(command.Define(
	"endpoint",
	"List, describe and validate the controller's own endpoints, and print their DSL",
	command.Under(command.ParentDSL),
	command.Long("An endpoint is one operation of the controller itself, such as\n"+
		"`GET /api/agent`. It runs on the controller, not on a host. Work on a host\n"+
		"is a behavior: see `osapi dsl behavior`. These commands read the definitions in\n"+
		"the binary. Thus they need no config file and no running controller."),
	command.Uses[Deps](),
	command.SubDoc(
		"spec",
		"Print the endpoint DSL: each option, method, refinement, error and field tag",
	),
	command.SubDoc("openapi", "Print the OpenAPI spec of an endpoint group"),
	command.SubDoc("method", "Show one method of an endpoint group in full"),
	command.Method[ListInput, ListOutput]("list").
		Short("List the endpoint groups this binary has").
		Example("").
		Prints(sampleList).
		Example("--json").
		Handle(List),
	command.Method[GetInput, GetOutput]("get").
		Short("Describe one endpoint group: its routes, permissions and operation IDs").
		Long("`osapi dsl endpoint openapi get` prints the group's part of the\n"+
			"OpenAPI spec.").
		Example("--name agent").
		Prints(sampleGet).
		Example("--name agent --json").
		Fails("no name", GetInput{}).
		Handle(Get),
	command.Method[MethodInput, MethodOutput]("get").
		Sub("method").
		Short("Show one method of an endpoint group: its route, fields, output, examples and errors").
		Long("Each input field shows where the request carries it: the path, the query,\n"+
			"a form or the body. `--json` has the JSON Schema of the input and the\n"+
			"output. `osapi dsl behavior method get` shows a method of a behavior the same\n"+
			"way.").
		Example("--name agent --method drain").
		Prints(sampleMethod).
		Example("--name agent --method drain --json").
		Fails("no name", MethodInput{Method: "list"}).
		Fails("no method", MethodInput{Name: "agent"}).
		Handle(MethodGet),
	command.Method[GetInput, OpenAPIOutput]("get").
		Sub("openapi").
		Short("Print the group's part of the OpenAPI spec, as YAML").
		Long("It prints the spec as the definition makes it. Read it beside the\n"+
			"hand-written spec of the group to compare the prose. `TestEndpointParity`\n"+
			"compares the rest.").
		Example("--name agent").
		Prints(sampleOpenAPI).
		Fails("no name", GetInput{}).
		Handle(OpenAPIGet),
	command.Method[CreateInput, CreateOutput]("create").
		Short("Write a new endpoint group that builds and passes its tests").
		Long("It writes `internal/controller/endpoints/<name>/` in the osapi checkout in\n"+
			"the current directory, and adds its import to\n"+
			"`internal/controller/endpoints/all`. The group has a list and a get, an\n"+
			"empty `Deps` and the tests of its methods. Then run the steps that it\n"+
			"prints. While its `Deps` is empty, the controller needs no wiring.\n"+
			"`osapi dsl endpoint spec get` lists each part of the DSL.").
		Example(`--name trace --description "The traces of the controller"`).
		Prints(sampleCreate).
		Fails("no name", CreateInput{Description: "x"}).
		Fails("no description", CreateInput{Name: "x"}).
		Handle(Create),
	command.Method[SpecInput, SpecOutput]("get").
		Sub("spec").
		Short("Print the endpoint DSL: each option, method, refinement, error and field tag").
		Long("Print each part of the endpoint DSL, what it makes osapi do and when to use\n"+
			"it, and what it cannot do yet. The list comes from this binary. Thus it\n"+
			"agrees with the build that you run. Read it before you write a group, then\n"+
			"check the result with `osapi dsl endpoint validate`.").
		Example("").
		Prints(sampleSpec).
		Example("--json").
		Handle(Spec),
	command.Method[ValidateInput, ValidateOutput]("validate").
		Short("Check every endpoint group against the rules of a definition").
		Long("It prints each problem with its group, method, rule and message, then the\n"+
			"fix of each rule, and exits 1 when a rule fails. `osapi dsl endpoint\n"+
			"spec get` describes each part of a group.\n\n"+
			"The rules:\n\n"+endpoint.Checks.Help()).
		Example("").
		Prints(sampleValidate).
		Example("--json").
		Handle(Validate),
))

Group is the endpoint group's definition.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name        string `json:"name"        validate:"required" doc:"The group's name: its path segment and CLI group"`
	Description string `json:"description" validate:"required" doc:"What the group is, in one line"`
}

CreateInput is the name and the doc of the group to create.

type CreateOutput

type CreateOutput struct {
	Name  string `                       json:"name"`
	Files []File `                       json:"files"`
	Next  []Step `                       json:"next"`
	// contains filtered or unexported fields
}

CreateOutput is the files that create wrote, and the steps after it.

func Create

func Create(
	_ context.Context,
	d Deps,
	in CreateInput,
) (CreateOutput, error)

Create writes a new endpoint group in the checkout, and is its files and the steps after it.

type Deps

type Deps struct {
	Groups  func() []*endpoint.Group
	OpenAPI func(g *endpoint.Group) (any, error)
	Dir     string
}

Deps is what the methods use: the endpoint groups, what makes a group's part of the OpenAPI spec, and the directory of the osapi checkout that create writes into.

type Error

type Error struct {
	Code   int    `json:"code"`
	Reason string `json:"reason"`
	Doc    string `json:"doc"`
}

Error is an error that the method maps to a status, with its reason.

type Example

type Example struct {
	Flags string `json:"flags" none:"(none)"`
	Doc   string `json:"doc"`
}

Example is one example of the method's command: its flags and what it shows.

type Field

type Field struct {
	Field       string `json:"field"`
	In          string `json:"in"`
	Type        string `json:"type"`
	Required    bool   `json:"required"`
	Constraints string `json:"constraints"`
	Description string `json:"description"`
}

Field is one input field: where the request carries it, its type and its constraints.

type File

type File struct {
	Path string `json:"path"`
}

File is a file that create wrote.

type GetInput

type GetInput struct {
	Name string `json:"name" validate:"required" doc:"The endpoint group, such as agent"`
}

GetInput names the group.

type GetOutput

type GetOutput struct {
	Name    string    `                       json:"name"`
	Doc     string    `                       json:"doc"     label:"Description"`
	Area    area.Name `                       json:"area"`
	Methods []Method  `                       json:"methods"`
	Types   []Type    `                       json:"types"`
	// contains filtered or unexported fields
}

GetOutput is a group and each of its methods.

func Get

func Get(
	_ context.Context,
	d Deps,
	in GetInput,
) (GetOutput, error)

Get is the group with the name, and the route, permission and operation of each method.

type ListInput

type ListInput struct{}

ListInput is the input of list, which has none.

type ListOutput

type ListOutput struct {
	Items []Summary `                        json:"items"`
	// contains filtered or unexported fields
}

ListOutput is each endpoint group.

func List

func List(
	_ context.Context,
	d Deps,
	_ ListInput,
) (ListOutput, error)

List is each endpoint group, with the names of its methods.

type Method

type Method struct {
	Name        string `json:"name"`
	Verb        string `json:"verb"`
	Path        string `json:"path"`
	Permission  string `json:"permission"   none:"none (public)"`
	OperationID string `json:"operation_id"                      label:"Operation ID"`
}

Method is one method of a group: its route, permission and operation.

type MethodInput

type MethodInput struct {
	Name   string `json:"name"   validate:"required" doc:"The endpoint group, such as agent"`
	Method string `json:"method" validate:"required" doc:"The method, from osapi dsl endpoint get"`
}

MethodInput is the group and the method to show.

type MethodOutput

type MethodOutput struct {
	Name        string           `               json:"name"`
	Doc         string           `               json:"doc"                  label:"Description"`
	Long        string           `               json:"long,omitempty"       label:"Detail"`
	HTTPMethod  string           `               json:"http_method"          label:"HTTP"`
	Route       string           `               json:"route"`
	Keys        []string         `               json:"keys"                                      empty:"The method has no key."`
	Permission  string           `               json:"permission,omitempty"                                                         none:"none (public)"`
	AdminOnly   bool             `               json:"admin_only"           label:"Admin only"`
	OperationID string           `               json:"operation_id"         label:"Operation ID"`
	Command     string           `               json:"command"`
	InputType   string           `               json:"input_type"           label:"Input type"`
	OutputType  string           `` /* 135-byte string literal not displayed */
	Fields      []Field          `               json:"fields"               label:"Input"        empty:"The method takes no input."`
	Results     []Result         `               json:"results"              label:"Output"`
	Examples    []Example        `               json:"examples"                                  empty:"The method has no example."`
	Refuses     []string         `               json:"refuses,omitempty"`
	Errors      []Error          `               json:"errors,omitempty"`
	Input       *behavior.Schema `` /* 146-byte string literal not displayed */
	Output      *behavior.Schema `` /* 146-byte string literal not displayed */
	// contains filtered or unexported fields
}

MethodOutput is one method of a group in full: its route, permission and command, its input fields with where each comes from and its constraints, its output, its examples and what it refuses. It is the shape of osapi dsl behavior method get. --json has the JSON Schema of the input and the output.

func MethodGet

func MethodGet(
	_ context.Context,
	d Deps,
	in MethodInput,
) (MethodOutput, error)

MethodGet is one method of the group in full: its route, permission, command, input fields, output, examples, refusals and errors.

type OpenAPIOutput

type OpenAPIOutput struct {
	Name string `json:"name"`
	YAML string `json:"yaml" render:"body"`
}

OpenAPIOutput is a group's part of the OpenAPI spec, as YAML, which prints as it is.

func OpenAPIGet

func OpenAPIGet(
	_ context.Context,
	d Deps,
	in GetInput,
) (OpenAPIOutput, error)

OpenAPIGet is the group's part of the OpenAPI spec, as YAML.

type Result

type Result = behaviordsl.Result

Result is one field of the output.

type SpecInput

type SpecInput struct{}

SpecInput is the input of spec get, which has none.

type SpecOutput

type SpecOutput struct {
	Kinds []guide.Section `json:"kinds" table:"sections"`
}

SpecOutput is each kind of term of the DSL, with its terms.

func Spec

func Spec(
	_ context.Context,
	_ Deps,
	_ SpecInput,
) (SpecOutput, error)

Spec is each part of the endpoint DSL, by kind.

type Step

type Step struct {
	Command string `json:"command"`
}

Step is a command to run after create.

type Summary

type Summary struct {
	Name    string    `json:"name"`
	Area    area.Name `json:"area"`
	Methods []string  `json:"methods"`
	Doc     string    `json:"doc"     label:"Description"`
}

Summary is one endpoint group and the names of its methods.

type Type

type Type struct {
	Name   string `json:"name"`
	Input  string `json:"input"`
	Output string `json:"output"`
}

Type is the input and the output type of one method, with their fields: a required input field is marked *.

type ValidateInput

type ValidateInput struct{}

ValidateInput is the input of validate, which has none.

type ValidateOutput

type ValidateOutput struct {
	Groups   int                `                   json:"groups"`
	Valid    bool               `                   json:"valid"`
	Problems []endpoint.Problem `                   json:"problems,omitempty"`
	Fixes    map[string]any     `                   json:"fixes,omitempty"`
	// contains filtered or unexported fields
}

ValidateOutput is each problem of each endpoint group, and the fix of each rule that one breaks.

func Validate

func Validate(
	_ context.Context,
	d Deps,
	_ ValidateInput,
) (ValidateOutput, error)

Validate checks each endpoint group. When a rule fails, it is the report with command.Fail: the report prints, then the command exits 1.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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