Documentation ¶
Index ¶
- Constants
- Variables
- type Adapter
- type Field
- func (f Field) Allow(values ...interface{}) Field
- func (f Field) Default(value interface{}) Field
- func (f Field) Description(description string) Field
- func (f Field) Enum(values ...interface{}) Field
- func (f Field) Example(ex interface{}) Field
- func (f Field) Format(format string) Field
- func (f Field) Initialized() bool
- func (f Field) Items(item Field) Field
- func (f Field) Kind() string
- func (f Field) Max(max float64) Field
- func (f Field) Min(min float64) Field
- func (f Field) Pattern(pattern string) Field
- func (f Field) Required() Field
- func (f Field) String() string
- func (f Field) Strip(strip bool) Field
- func (f *Field) ToJsonSchema() JsonSchema
- func (f *Field) ToSwaggerParameters(in string) (parameters []Parameter)
- func (f Field) Unknown(allow bool) Field
- func (f *Field) Validate(value interface{}) error
- type Info
- type JsonSchema
- type MiddlewareFunc
- type Operation
- type Parameter
- type Path
- type Ref
- type Response
- type Router
- type ServeMuxAdapter
- type Spec
- type Swagger
- type Validate
Constants ¶
const ( KindNumber = "number" KindString = "string" KindBoolean = "boolean" KindObject = "object" KindArray = "array" KindFile = "file" KindInteger = "integer" )
These kinds correlate to swagger and json types.
const ( FormatDate = "date" FormatDateTime = "dateTime" )
Variables ¶
var SwaggerPathPattern = regexp.MustCompile("\\{([^}]+)\\}")
SwaggerPathPattern regex captures swagger path params.
var SwaggerUiTemplate []byte
SwaggerUiTemplate contains the html for swagger UI.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field allows specification of swagger or json schema types using the builder pattern.
func (Field) Allow ¶
Allow lets you break rules For example, String().Required() excludes "", unless you Allow("")
func (Field) Default ¶
Default specifies a default value to use if the field is nil. Can't be used with Required.
func (Field) Description ¶
Description specifies a human-readable explanation of the field
func (Field) Format ¶ added in v1.2.0
Format is used to set custom format types. Note that formats with special validation in this library also have their own constructor. See DateTime for example.
func (Field) Initialized ¶
Initialized returns true if the field has been initialized with Number, String, etc. When the Swagger is being built, often an uninitialized field will be ignored.
func (Field) Strip ¶
Strip overrides the global "strip unknown" setting just for this field, and all children of this field
func (*Field) ToJsonSchema ¶
func (f *Field) ToJsonSchema() JsonSchema
ToJsonSchema transforms a field into a Swagger Schema. TODO this is an extension of JsonSchema, rename in v2 ToSchema() Schema
func (*Field) ToSwaggerParameters ¶
ToSwaggerParameters transforms a field into a slice of Parameter.
type JsonSchema ¶
type JsonSchema struct { Type string `json:"type,omitempty"` Format string `json:"format,omitempty"` Properties map[string]JsonSchema `json:"properties,omitempty"` Items *JsonSchema `json:"items,omitempty"` Required []string `json:"required,omitempty"` Example interface{} `json:"example,omitempty"` Description string `json:"description,omitempty"` Minimum float64 `json:"minimum,omitempty"` Maximum float64 `json:"maximum,omitempty"` Enum []interface{} `json:"enum,omitempty"` Default interface{} `json:"default,omitempty"` Pattern string `json:"pattern,omitempty"` }
type Parameter ¶
type Parameter struct { In string `json:"in"` Name string `json:"name"` // one of path, query, header, body, or form Type string `json:"type,omitempty"` Schema *Ref `json:"schema,omitempty"` Required *bool `json:"required,omitempty"` Description string `json:"description,omitempty"` Minimum *float64 `json:"minimum,omitempty"` Maximum *float64 `json:"maximum,omitempty"` Enum []interface{} `json:"enum,omitempty"` Pattern string `json:"pattern,omitempty"` Default interface{} `json:"default,omitempty"` Items *JsonSchema `json:"items,omitempty"` CollectionFormat string `json:"collectionFormat,omitempty"` }
type Response ¶
type Response struct { Schema JsonSchema `json:"schema"` Description string `json:"description"` Example interface{} `json:"interface,omitempty"` Ref *Ref `json:"$ref,omitempty"` Headers map[string]string `json:"headers,omitempty"` }
type Router ¶
type Router struct { // Swagger is exposed so the user can edit additional optional fields. Swagger Swagger // contains filtered or unexported fields }
Router is the main object that is used to generate swagger and holds the underlying router.
func (*Router) Add ¶
Add routes to the swagger spec and installs a handler with built-in validation. Some validation of the route itself occurs on Add so this is the kind of error that can be returned.
type ServeMuxAdapter ¶ added in v1.5.0
func NewServeMuxAdapter ¶ added in v1.5.0
func NewServeMuxAdapter() *ServeMuxAdapter
type Spec ¶
type Spec struct { // Method is the http method of the route, e.g. GET, POST Method string // Path is the URL path of the routes, w.g. /widgets/{id} Path string // PreHandlers run before validation. Good for authorization PreHandlers interface{} // Handler runs after validation. This is where you take over Handler interface{} // Description is the longer text that will appear in the Swagger under the endpoint Description string // Tags are how the Swagger groups paths together, e.g. []string{"Widgets"} Tags []string // Summary is a short description of what an endpoint does in the Swagger Summary string // Validate is used to automatically validate the various inputs to the endpoint Validate Validate // Responses specifies the responses in Swagger. If none provided a default is used. Responses map[string]Response }
Spec is used to generate swagger paths and automatic handler validation