Documentation
¶
Index ¶
- Constants
- Variables
- func DeRef(defName string) string
- func Decompose(sampledata []byte, baseType string, cnf Conf) (m map[string]*Schema, err error)
- func GetMartiniInstance(cnf Conf) *martini.ClassicMartini
- func MakeCommonAPIs(prefix string, pathRoot string, schemaName string, ...) map[string]*PathItem
- func MakeRef(defName string) string
- func NewAPIFromSpec(path string, pathitem *PathItem, rd *Swagger, m *martini.ClassicMartini)
- func RegisterType(d DbBackend, byt []byte, cnf Conf, resourceType string, path string) error
- func ServeDocSet(m *martini.ClassicMartini, db DbBackend, cnf Conf)
- func TranslatePath(path string) (outpath string)
- type Authorization
- type Conf
- type ContactLicences
- type Container
- type ContainerMeta
- type DbBackend
- type ExternalDoc
- type Items
- type Operation
- type Parameter
- type PathItem
- type QueryParams
- type Response
- type Schema
- type SecurityScheme
- type Swagger
- type Tag
- type XMLRef
Constants ¶
const ( REFPREFIX = "#/definitions/" ENUMSPLIT = "|" MINMAXSPLIT = "<>" METALIST = "Metalist" )
const ( RANGESTART = "RangeStart" RANGEEND = "RangeEnd" )
const ( GET = iota PUT PATCH POST DELETE )
const ( ContainerName = "container" SwaggerResourceDB = "swagger_docs" ResourceRootName = "resource-root" ResourceDescriptionName = "swagger_resource" ResourceStem = "resource_" )
const (
NOTFOUNDERROR = "Entity not found."
)
Variables ¶
Functions ¶
func Decompose ¶
Decompose is the only exported function in this file. It takes a set of sample data, introspects it and converts it into a map of Swagger models. It returns a schema map and any errors.
func GetMartiniInstance ¶
func GetMartiniInstance(cnf Conf) *martini.ClassicMartini
GetMartiniInstance returns a Martini instance (so that it can be used by a larger Martini app)
func MakeCommonAPIs ¶
func MakeCommonAPIs( prefix string, pathRoot string, schemaName string, schemaMap map[string]*Schema, upstreamParams []*Parameter, cnf Conf, ) map[string]*PathItem
MakeCommonAPIs creates a set of operations and APIs for a model. For any model passed to the function, two paths are created with the following operations on each: /{pathRoot} (GET and POST) /{pathRoot}/{id} (GET, PUT, PATCH, DELETE)
func NewAPIFromSpec ¶
func NewAPIFromSpec(path string, pathitem *PathItem, rd *Swagger, m *martini.ClassicMartini)
NewAPIFromSpec creates a new API from stored swagger-doc specifications.
func RegisterType ¶
func ServeDocSet ¶
func ServeDocSet(m *martini.ClassicMartini, db DbBackend, cnf Conf)
ServeDocSet sets up the paths which serve the api documentation
func TranslatePath ¶
translatePath transforms a path from swagger-doc format (/path/{id}) to Martini format (/path/:id).
Types ¶
type Authorization ¶
type Authorization struct{}
Describes an authorization option for a resource (not implemented yet)
type Conf ¶
type Conf struct {
ContainerModels []*Schema `json:"containerModels"`
CommonSingleResponses map[string]*Response `json:"commonSingleResponses"`
CommonCollectionResponses map[string]*Response `json:"commonCollectionResponses"`
CommonGetParams []*Parameter `json:"commonGetParams"`
SwaggerTemplate *Swagger `json:"swaggerTemplate"`
Port string `json:"port"`
Host string `json:"host"`
DbServer string `json:"dbserver"`
DbPort string `json:"dbport"`
StaticDirs []string `json:"staticDirs"`
}
A configuration set for the service
type ContactLicences ¶
type ContactLicences struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
A swagger contact or license reference
type Container ¶
type Container struct {
Meta ContainerMeta `json:"meta,omitempty"`
ContainerType string `json:"containerType"`
Results []interface{} `json:"results"`
}
A Container is a wrapper for a list of results, plus some meta information about the result set.
type ContainerMeta ¶
type ContainerMeta struct {
ResponseCode int `json:"responseCode,omitempty"`
ResponseMessage string `json:"responseMessage,omitempty"`
Offset int `json:"offset"`
Limit int `json:"limit,omitempty"`
Total int `json:"total"`
Count int `json:"count"`
}
ContainerMeta is a list of metadata about a result set.
type DbBackend ¶
type DbBackend interface {
//// internal API
// connect to a backend server
Connect(string) error
LoadDefinition(Conf) (*Swagger, error)
SaveDefinition(*Swagger) error
// external API
// Query the datastore with a QueryParams struct
Query(QueryParams) (Container, error)
// Update a document using a QueryParams struct
Update(QueryParams, int) (interface{}, error)
// Insert a new document using a QueryParams struct
Insert(QueryParams) (interface{}, error)
// Delete a document with a QueryParams struct
Remove(QueryParams) error
// Prep prepares a database to serve a new API. For example, create
// tables or collections, create views, etc.
Prep(string, *Swagger) error
}
The DbBackend interface describes the methods which must be implemented for any backends used to store data.
type ExternalDoc ¶
type ExternalDoc struct {
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
}
An external documentation reference
type Items ¶
type Items struct {
Type string `json:"type"`
Format string `json:"format,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Default interface{} `json:"default,omitempty"`
Maximum float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxitems,omitempty"`
MinItems int `json:"minitems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
MaxProperties int `json:"maxProperties,omitempty"`
MinProperties int `json:"minProperties,omitempty"`
Required bool `json:"required,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
}
Describes an array item in a parameter
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
OperationID string `json:"operationId,omitempty"`
Produces []string `json:"produces,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
Responses map[string]*Response `json:"responses"`
Schemes []string `json:"schemes,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Security map[string][]string `json:"authorizations,omitempty"`
}
Describes an operation (e.g. a GET, PUT or POST operation)
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description,omitempty"`
Required bool `json:"required"`
Schema *Schema `json:"schema,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
AllowEmptyValue bool `json:"allowElmptyValue,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Default interface{} `json:"default,omitempty"`
Maximum float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxitems,omitempty"`
MinItems int `json:"minitems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
MaxProperties int `json:"maxProperties,omitempty"`
MinProperties int `json:"minProperties,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
}
Describes a parameter
type PathItem ¶
type PathItem struct {
Ref *PathItem `json:"$ref,omitempty"`
Get *Operation `json:"get,omitempty"`
Put *Operation `json:"put,omitempty"`
Post *Operation `json:"post,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Options *Operation `json:"options,omitempty"`
Head *Operation `json:"head,omitempty"`
Patch *Operation `json:"patch,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
}
Describes an API
type QueryParams ¶
type QueryParams struct {
Path string
PathParams map[string]interface{}
QueryParams qparam
Body []byte
}
QueryParams are a container for http path, query and body information that's used by the back-ends.
type Response ¶
type Response struct {
Description string `json:"description"`
Schema *Schema `json:"schema,omitempty"`
// headers and items are functionally equivalent
Headers map[string]*Items `json:"headers,omitempty"`
Examples map[string]interface{} `json:"example,omitempty"`
}
Describes a response message from an API
type Schema ¶
type Schema struct {
Ref string `json:"$ref,omitempty"`
Format string `json:"format,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Default interface{} `json:"default,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
Maximum float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxitems,omitempty"`
MinItems int `json:"minitems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
MaxProperties int `json:"maxProperties,omitempty"`
MinProperties int `json:"minProperties,omitempty"`
Required []string `json:"required,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Type string `json:"type,omitempty"`
Items *Schema `json:"items,omitempty"`
AdditionalItems bool `json:"additionalItems,omitempty"`
AllOf []*Schema `json:"allOf,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
Discriminator string `json:"discriminator,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
// parameters fields -
// properties and params share a bunch of fields
XML *XMLRef `json:"xml,omitempty"`
ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
Example interface{} `json:"example,omitempty"`
}
Describes a property of a Model or a parameter for an Operation
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
In string `json:"in"`
Flow string `json:"flow"`
AuthorizationURL string `json:"authorizationUrl"`
TokenURL string `json:"tokenUrl"`
Scopes map[string]string `json:"scopes"`
}
Describes a Swagger security scheme
type Swagger ¶
type Swagger struct {
Swagger string `json:"swagger"`
Info struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact ContactLicences `json:"contact,omitempty"`
License ContactLicences `json:"license,omitempty"`
Version string `json:"version"`
} `json:"info"`
Host string `json:"host,omitempty"`
BasePath string `json:"basePath,omitempty"`
Schemes []string `json:"schemes,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Paths map[string]*PathItem `json:"paths"`
Definitions map[string]*Schema `json:"definitions,omitempty"`
Parameters map[string]*Parameter `json:"parameters,omitempty"`
Responses map[string]*Response `json:"responses,omitempty"`
SecurityDefinitions map[string]*SecurityScheme `json:"securityDefinitions,omitempty"`
Security map[string][]string `json:"security,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
}
Describes a Swagger-doc resource description
type Tag ¶
type Tag struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"`
}