sdkmodel

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: 8 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 sdkmodel is what the Go SDK is made of, read from the full spec of the API: each service, its methods with their parameters, body and result, and each type the methods send and receive. internal/sdk/gen writes the SDK's typed services from it. A generator of the SDK's reference pages or of its examples reads the same model, so the code, the pages and the examples cannot name a method differently.

Index

Constants

View Source
const AreaExtension = "x-osapi-area"

AreaExtension is the extension of each operation of the spec that names its area, such as fleet. The endpoint layer writes it.

View Source
const AreasExtension = "x-osapi-areas"

AreasExtension is the extension of the spec that lists the areas in their order, each with its name and its label. The endpoint layer writes it.

View Source
const ExamplesExtension = "x-osapi-examples"

ExamplesExtension is the extension of an operation of the spec that has the examples of its method, each with its doc and its input. The endpoint layer writes it.

View Source
const GroupExtension = "x-osapi-group"

GroupExtension is the extension of each tag of the spec that names its group, such as dns: the segment of the paths that the service's name ends at. The endpoint layer writes it.

View Source
const MethodExtension = "x-osapi-method"

MethodExtension is the extension of each operation of the spec that names the method in its group, such as get or drain. The endpoint layer writes it.

View Source
const ProgramExtension = "x-osapi-program"

ProgramExtension marks an operation that a program calls, not a person, as internal/controller/endpoint's ProgramExtension does.

Variables

This section is empty.

Functions

func GoName

func GoName(
	name string,
) string

GoName is the exported Go name of a name of the spec, such as SearchDomains for search_domains, or Min15 for 15min: a name cannot start with a digit, so the digits go to the end.

Types

type Area

type Area struct {
	// Name is the name of the area, such as fleet.
	Name string `json:"name"`
	// Label is what a reader sees, such as Fleet.
	Label string `json:"label"`
}

Area is one area of the spec: the operations of its services are under it, such as in the folder of the SDK's pages.

type Example

type Example struct {
	// Doc says what the example shows.
	Doc string `json:"doc"`
	// Input is the value of each parameter and each property of the body
	// that the example sets, by its name in the spec.
	Input map[string]any `json:"input"`
}

Example is one example of a method: a call with an input.

type Field

type Field struct {
	// Name is the name in the spec, such as search_domains.
	Name string
	// GoName is the Go name, such as SearchDomains.
	GoName string
	// Doc is the description of the property.
	Doc string
	// Type is the Go type.
	Type *TypeRef
	// Required is true when the schema requires the property.
	Required bool
	// Enum are the values the property can have, or nil.
	Enum []string
	// Path is true for a field of an Input that goes in the path, not in
	// the body.
	Path bool
	// File is true for the content of a file in a multipart form, which a
	// method takes as an io.Reader.
	File bool
	// Default is the value that the API uses when the field is not sent,
	// or nil.
	Default any
}

Field is a property of a schema.

type Kind

type Kind int

Kind is the kind of a TypeRef.

const (
	// Scalar is a Go type of the standard library, such as string, int64
	// or time.Time, in Name.
	Scalar Kind = iota
	// Named is a type of the model, in Name.
	Named
	// Slice is a slice of Elem.
	Slice
	// Map is a map of strings to Elem.
	Map
	// Collection is a Collection of Elem: the {job_id, results} answer of a
	// node.
	Collection
	// Any is a value of any JSON type.
	Any
)

The kinds of a TypeRef.

type Method

type Method struct {
	// Name is the Go name of the method, such as Get.
	Name string
	// OperationID is the operationId of the operation.
	OperationID string
	// HTTPMethod is the method of the request, such as GET.
	HTTPMethod string
	// Path is the path of the operation, such as
	// /api/node/{hostname}/network/dns/{interface_name}.
	Path string
	// Summary is the summary of the operation.
	Summary string
	// Description is the description of the operation.
	Description string
	// Permission is the permission the operation needs, or "".
	Permission string
	// Program is a method that a program calls, not a person, such as the
	// agent's join: it needs no example.
	Program bool
	// PathParams are the parameters in the path, in the order of the path.
	PathParams []*Param
	// Query are the parameters of the query, in the order of the spec.
	Query []*Param
	// Input is the one struct that a method with a JSON body takes: a field
	// for each parameter of the path but the target, then a field for each
	// property of the body. It is nil when the method has no JSON body.
	Input *Type
	// Multipart is true when the body is a multipart form, such as the
	// upload of a file. The generator writes no method for it: a person
	// writes it, with the arguments that FormArgs gives.
	Multipart bool
	// Form is the fields of a multipart form, in the order of their names,
	// or nil when the body is not a form.
	Form []*Field
	// Result is the type of a success's body, or nil when a success has
	// none, such as a 204.
	Result *TypeRef
	// Statuses are the status codes that the spec declares, in order.
	Statuses []int
	// Examples are the examples of the method's definition, in their
	// order.
	Examples []*Example
}

Method is one operation of the spec.

func (*Method) FormArgs

func (m *Method) FormArgs() ([]*Field, error)

FormArgs is the arguments after the context of the method that a person writes for a multipart form, in order: each key of the path, then each required field of the form, then each optional one, then the file, which the method takes as an io.Reader. The fields of each part are in the order of their names. It is an error when the form has no file, or more than one.

func (*Method) Keys

func (m *Method) Keys() []*Param

Keys is the parameters of the path but the target, such as the name of a service.

func (*Method) OptionalQuery

func (m *Method) OptionalQuery() []*Param

OptionalQuery is the parameters of the query that the request can leave out.

func (*Method) RequiredQuery

func (m *Method) RequiredQuery() []*Param

RequiredQuery is the parameters of the query that the request must have.

func (*Method) Target

func (m *Method) Target() *Param

Target is the parameter of the path that names the hosts, hostname, or nil when the path has none.

type Model

type Model struct {
	// Areas are the areas of the spec, in its order.
	Areas []*Area
	// Services are the services of the SDK, in the order of their names.
	Services []*Service
	// Types are the types that the methods send and receive, in the order
	// of their names. A collection is not one: it is a Collection of its
	// item type.
	Types []*Type
}

Model is the SDK that the spec describes.

func New

func New(
	doc *openapi3.T,
) (*Model, error)

New is the model of doc.

type Param

type Param struct {
	// Name is the name in the spec, such as interface_name.
	Name string
	// GoName is the Go name of a field, such as InterfaceName.
	GoName string
	// ArgName is the Go name of an argument, such as interfaceName.
	ArgName string
	// Doc is the description of the parameter.
	Doc string
	// Type is the type of the parameter: a string, an int, a bool, or a
	// Named enum of strings.
	Type *TypeRef
	// Required is true when the request must have it.
	Required bool
}

Param is a parameter of an operation.

type Service

type Service struct {
	// Name is the Go name of the service, such as NetworkDNS.
	Name string
	// Doc is the description of the group's tag.
	Doc string
	// Methods are the service's methods, in the order of their paths.
	Methods []*Method
	// Node is true for a group of a node, whose paths start with
	// /api/node/, and false for a group of the controller.
	Node bool
	// Area is the name of the area of the service's operations, one of the
	// Areas of the model.
	Area string
}

Service is the methods of one group of the API, such as NetworkDNS.

type Type

type Type struct {
	// Name is the Go name, the name of the schema, such as NetworkDnsEntry.
	Name string
	// Doc is the description of the schema.
	Doc string
	// Fields are the properties of the schema, in the order of their names.
	Fields []*Field
	// Scalar is the Go type under a schema that is not an object, such as
	// string for the enum Permission, or empty for a struct.
	Scalar string
	// Enum are the values of a scalar type, in the order of the spec, or
	// nil.
	Enum []string
}

Type is a struct of the SDK, from a schema of the spec.

type TypeRef

type TypeRef struct {
	Kind Kind
	// Name is the Go name of a Scalar or a Named type, such as string or
	// NetworkDnsEntry.
	Name string
	// Elem is the type of the items of a Slice, a Map or a Collection.
	Elem *TypeRef
}

TypeRef is the Go type of a value.

func (*TypeRef) String

func (t *TypeRef) String() string

String is the Go spelling of the type, such as []string or Collection[NetworkDnsEntry].

Jump to

Keyboard shortcuts

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