Documentation ¶
Index ¶
- type API
- func (api *API) AddTags(tag *openapi3.Tag)
- func (api *API) Connect(pattern string) (r *Route)
- func (api *API) Delete(pattern string) (r *Route)
- func (api *API) Get(pattern string) (r *Route)
- func (api *API) Head(pattern string) (r *Route)
- func (api *API) Merge(r Route)
- func (api *API) Options(pattern string) (r *Route)
- func (api *API) Patch(pattern string) (r *Route)
- func (api *API) Post(pattern string) (r *Route)
- func (api *API) Put(pattern string) (r *Route)
- func (api *API) RegisterModel(model Model, opts ...ModelOpts) (name string, schema *openapi3.Schema, err error)
- func (api *API) Route(method, pattern string) (r *Route)
- func (api *API) Spec() (spec *openapi3.T, err error)
- func (api *API) Trace(pattern string) (r *Route)
- type APIOpts
- type CustomSchemaApplier
- type Method
- type MethodToRoute
- type Model
- type ModelOpts
- type Models
- type Params
- type PathParam
- type Pattern
- type PrimitiveType
- type QueryParam
- type Route
- func (rm *Route) HasDescription(description string) *Route
- func (rm *Route) HasOperationID(operationID string) *Route
- func (rm *Route) HasPathParameter(name string, p PathParam) *Route
- func (rm *Route) HasQueryParameter(name string, q QueryParam) *Route
- func (rm *Route) HasRequestModel(request Model) *Route
- func (rm *Route) HasResponseModel(status int, response Model) *Route
- func (rm *Route) HasTags(tags []string) *Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { // Name of the API. Name string // Routes of the API. // From patterns, to methods, to route. Routes map[Pattern]MethodToRoute // StripPkgPaths to strip from the type names in the OpenAPI output to avoid // leaking internal implementation details such as internal repo names. // // This increases the risk of type clashes in the OpenAPI output, i.e. two types // in different namespaces that are set to be stripped, and have the same type Name // could clash. // // Example values could be "github.com/praneeth200244/rest". StripPkgPaths []string // Tags is a section in openapi specification. The name, description and external docs has be given as user input. Tags []*openapi3.Tag // KnownTypes are added to the OpenAPI specification output. // The default implementation: // Maps time.Time to a string. KnownTypes map[reflect.Type]openapi3.Schema // ApplyCustomSchemaToType callback to customise the OpenAPI specification for a given type. // Apply customisation to a specific type by checking the t parameter. // Apply customisations to all types by ignoring the t parameter. ApplyCustomSchemaToType func(t reflect.Type, s *openapi3.Schema) // contains filtered or unexported fields }
API is a model of a REST API's routes, along with their request and response types.
func (*API) AddTags ¶
AddTags appends a new tag to the API's list of tags. This function ensures that the provided tag is included in the API's documentation, allowing for better organization and categorization of API endpoints.
func (*API) Merge ¶
Merge route data into the existing configuration. This is typically used by adapters, such as the chiadapter to take information that the router already knows and add it to the specification.
func (*API) RegisterModel ¶
func (api *API) RegisterModel(model Model, opts ...ModelOpts) (name string, schema *openapi3.Schema, err error)
RegisterModel allows a model to be registered manually so that additional configuration can be applied. The schema returned can be modified as required.
type APIOpts ¶
type APIOpts func(*API)
func WithApplyCustomSchemaToType ¶
WithApplyCustomSchemaToType enables customisation of types in the OpenAPI specification. Apply customisation to a specific type by checking the t parameter. Apply customisations to all types by ignoring the t parameter.
type CustomSchemaApplier ¶
CustomSchemaApplier is a type that customises its OpenAPI schema.
type MethodToRoute ¶
MethodToRoute maps from a HTTP method to a Route.
type ModelOpts ¶
ModelOpts defines options that can be set when registering a model.
func WithDescription ¶
WithDescription sets the description field on the schema.
func WithEnumConstants ¶
func WithEnumConstants[T ~string | constraints.Integer]() ModelOpts
WithEnumConstants sets the property to be an enum containing the values of the type found in the package.
func WithEnumValues ¶
func WithEnumValues[T ~string | constraints.Integer](values ...T) ModelOpts
WithEnumValues sets the property to be an enum value with the specific values.
type Params ¶
type Params struct { // Path parameters are used in the path of the URL, e.g. /users/{id} would // have a name of "id". Path map[string]PathParam // Query parameters are used in the querystring of the URL, e.g. /users/?sort={sortOrder} would // have a name of "sort". Query map[string]QueryParam }
Params is a route parameter.
type PathParam ¶
type PathParam struct { // Description of the param. Description string // Regexp is a regular expression used to validate the param. // An empty string means that no validation is applied. Regexp string // Type of the param (string, number, integer, boolean). Type PrimitiveType // ApplyCustomSchema customises the OpenAPI schema for the path parameter. ApplyCustomSchema func(s *openapi3.Parameter) }
PathParam is a paramater that's used in the path of a URL.
type PrimitiveType ¶
type PrimitiveType string
const ( PrimitiveTypeString PrimitiveType = "string" PrimitiveTypeBool PrimitiveType = "boolean" PrimitiveTypeInteger PrimitiveType = "integer" PrimitiveTypeFloat64 PrimitiveType = "number" )
type QueryParam ¶
type QueryParam struct { // Description of the param. Description string // Regexp is a regular expression used to validate the param. // An empty string means that no validation is applied. Regexp string // Required sets whether the querystring parameter must be present in the URL. Required bool // AllowEmpty sets whether the querystring parameter can be empty. AllowEmpty bool // Type of the param (string, number, integer, boolean). Type PrimitiveType // ApplyCustomSchema customises the OpenAPI schema for the query parameter. ApplyCustomSchema func(s *openapi3.Parameter) }
QueryParam is a paramater that's used in the querystring of a URL.
type Route ¶
type Route struct { // Method is the HTTP method of the route, e.g. http.MethodGet Method Method // Pattern of the route, e.g. /posts/list, or /users/{id} Pattern Pattern // Params of the route. Params Params // Models used in the route. Models Models // Tags used in the route. Tags []string // OperationID for the route. OperationID string // Description for the route. Description string }
Route models a single API route.
func (*Route) HasDescription ¶
HasDescription sets the description for the route.
func (*Route) HasOperationID ¶
HasOperationID sets the OperationID for the route.
func (*Route) HasPathParameter ¶
HasPathParameter configures a path parameter for the route.
func (*Route) HasQueryParameter ¶
func (rm *Route) HasQueryParameter(name string, q QueryParam) *Route
HasQueryParameter configures a query parameter for the route.
func (*Route) HasRequestModel ¶
HasResponseModel configures the request model of the route. Example:
api.Post("/user").HasRequestModel(http.StatusOK, rest.ModelOf[User]())
func (*Route) HasResponseModel ¶
HasResponseModel configures a response for the route. Example:
api.Get("/user").HasResponseModel(http.StatusOK, rest.ModelOf[User]())