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 ¶
- Variables
- type CreateInput
- type CreateOutput
- type Deps
- type Error
- type Example
- type Field
- type File
- type GetInput
- type GetOutput
- type ListInput
- type ListOutput
- type Method
- type MethodInput
- type MethodOutput
- type OpenAPIOutput
- type Result
- type SpecInput
- type SpecOutput
- type Step
- type Summary
- type Type
- type ValidateInput
- type ValidateOutput
Constants ¶
This section is empty.
Variables ¶
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 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 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.
type ListOutput ¶
type ListOutput struct {
Items []Summary ` json:"items"`
// contains filtered or unexported fields
}
ListOutput is each endpoint group.
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 ¶
OpenAPIOutput is a group's part of the OpenAPI spec, as YAML, which prints as it is.
func OpenAPIGet ¶
OpenAPIGet is the group's part of the OpenAPI spec, as YAML.
type SpecOutput ¶
SpecOutput is each kind of term of the DSL, with its terms.
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.