Documentation ¶
Index ¶
- Constants
- func DescriptorForData(path string, data []byte, contentType string) definition.Descriptor
- func GenSwaggerPageData(root string, versions []string) ([]byte, error)
- func NewPathDefinitions(tc *TypeContainer, definitions map[string][]definition.Definition, ...) (map[string][]Definition, error)
- func PathForVersion(root, version string) string
- func RPCDescriptorForData(path string, data []byte, contentType string) definition.RPCDescriptor
- func WriteFiles(output string, apis map[string][]byte) error
- type Analyzer
- type Buffer
- type Comments
- func (c *Comments) AddOption(name, value string)
- func (c *Comments) BlockComments() string
- func (c *Comments) CleanOptions()
- func (c *Comments) LineComments() string
- func (c *Comments) Option(name string) []string
- func (c *Comments) Options() map[string][]string
- func (c *Comments) Rename(origin, target string) bool
- func (c *Comments) String() string
- type Container
- type Definition
- type Definitions
- type Example
- type FuncField
- type Parameter
- type Result
- type StructField
- type Type
- type TypeContainer
- type TypeName
Constants ¶
const ( // CommentsOptionDescriptors is the option name of descriptors. CommentsOptionDescriptors = "descriptors" // CommentsOptionModifiers is the option name of modifiers. CommentsOptionModifiers = "modifiers" // CommentsOptionAlias is the option name of alias. CommentsOptionAlias = "alias" // CommentsOptionOrigin is the option name of original name. CommentsOptionOrigin = "origin" )
const TypeNameInvalid = ""
TypeNameInvalid indicates an invalid type name.
Variables ¶
This section is empty.
Functions ¶
func DescriptorForData ¶ added in v0.3.0
func DescriptorForData(path string, data []byte, contentType string) definition.Descriptor
DescriptorForData generates a Descriptor for API docs page.
func GenSwaggerPageData ¶ added in v0.3.0
GenSwaggerPageData generates a Swagger UI page based on the given API files.
func NewPathDefinitions ¶
func NewPathDefinitions(tc *TypeContainer, definitions map[string][]definition.Definition, apiStyle service.APIStyle) (map[string][]Definition, error)
NewPathDefinitions creates a list of definitions with path.
func PathForVersion ¶ added in v0.3.0
PathForVersion returns the path of API file.
func RPCDescriptorForData ¶ added in v0.3.0
func RPCDescriptorForData(path string, data []byte, contentType string) definition.RPCDescriptor
RPCDescriptorForData generates a RPCDescriptor for API docs page.
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
Analyzer analyzes go packages.
func NewAnalyzer ¶
NewAnalyzer creates a code analyzer.
func (*Analyzer) Comments ¶
Comments returns immediate comments above pos. Import package before calling this method.
func (*Analyzer) PackageComments ¶
func (a *Analyzer) PackageComments(path string) []*ast.CommentGroup
PackageComments returns comments above package keyword. Import package before calling this method.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer provides a buffer to write data. The buffer will panic if an error occurs.
func (*Buffer) Bytes ¶
Bytes returns a slice of length b.Len() holding the unread portion of the buffer.
func (*Buffer) String ¶
String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".
type Comments ¶
type Comments struct {
// contains filtered or unexported fields
}
Comments is parsed from go comments.
func ParseComments ¶
ParseComments parses comments and extracts nirvana options.
func (*Comments) BlockComments ¶
BlockComments returns block style comments.
func (*Comments) LineComments ¶
LineComments returns line style comments.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container contains informations to generate APIs.
func NewContainer ¶
NewContainer creates API container.
func (*Container) AddDescriptor ¶
func (ac *Container) AddDescriptor(descriptors ...interface{})
AddDescriptor add descriptors to container.
func (*Container) AddModifier ¶
func (ac *Container) AddModifier(modifiers ...service.DefinitionModifier)
AddModifier add definition modifiers to container.
type Definition ¶
type Definition struct { // Method is definition method. Method definition.Method // HTTPMethod is http method. HTTPMethod string // HTTPCode is http success code. HTTPCode int // Summary is a brief of this definition. Summary string // Description describes the API handler. Description string // Tags indicates tags of the API handler. // It will override parent descriptor's tags. Tags []string // Consumes indicates how many content types the handler can consume. // It will override parent descriptor's consumes. Consumes []string // Produces indicates how many content types the handler can produce. // It will override parent descriptor's produces. Produces []string // ErrorProduces is used to generate data for error. If this field is empty, // it means that this field equals to Produces. // In some cases, successful data and error data should be generated in // different ways. ErrorProduces []string // Function is a function handler. It must be func type. Function TypeName // Parameters describes function parameters. Parameters []Parameter // Results describes function retrun values. Results []Result // Examples contains many examples for the API handler. Examples []Example }
Definition is complete version of def.Definition.
func NewDefinition ¶
func NewDefinition(tc *TypeContainer, d *definition.Definition, apiStyle service.APIStyle) (*Definition, error)
NewDefinition creates openapi.Definition from definition.Definition.
func NewDefinitions ¶
func NewDefinitions(tc *TypeContainer, definitions []definition.Definition, apiStyle service.APIStyle) ([]Definition, error)
NewDefinitions creates a list of definitions.
type Definitions ¶
type Definitions struct { // Definitions holds mappings between path and API descriptions. Definitions map[string][]Definition // Types contains all types used by definitions. Types map[TypeName]*Type }
Definitions describes all APIs and its related object types.
func (*Definitions) Subset ¶
func (d *Definitions) Subset(require func(path string, def *Definition) bool) *Definitions
Subset returns a subset required by a definition filter.
type Example ¶
type Example struct { // Description describes the example. Description string // Type is result object type. Type TypeName // Instance is encoded instance data. Instance []byte }
Example is just an example.
type FuncField ¶
type FuncField struct { // Name is the field name. Name string // Type is field type name. Type TypeName }
FuncField describes a field of function.
type Parameter ¶
type Parameter struct { // Source is the parameter value generated from. Source definition.Source // Name is the name to get value from a request. Name string // Description describes the parameter. Description string // Type is parameter object type. Type TypeName // Default is encoded default value. Default []byte // Optional used to set whether this parameter is optional or not. Optional bool }
Parameter describes a function parameter.
type Result ¶
type Result struct { // Destination is the target for the result. Destination definition.Destination // Description describes the result. Description string // Type is result object type. Type TypeName }
Result describes a function result.
type StructField ¶
type StructField struct { // Name is the field name. Name string // Comments of the type. Comments string // PkgPath is the package path that qualifies a lower case (unexported) // field name. It is empty for upper case (exported) field names. PkgPath string // Type is field type name. Type TypeName // Tag is field tag. Tag reflect.StructTag // Offset within struct, in bytes. Offset uintptr // Index sequence for Type.FieldByIndex. Index []int // Anonymous shows whether the field is an embedded field. Anonymous bool }
StructField describes a field of a struct.
type Type ¶
type Type struct { // Name is short type name. Name string // Comments of the type. Comments string // PkgPath is the package for this type. PkgPath string // Kind is type kind. Kind reflect.Kind // Key is map key type. Only used in map. Key TypeName // Elem is the element type of map, slice, array, pointer. Elem TypeName // Fields contains all struct fields of a struct. Fields []StructField // In presents fields of function input parameters. In []FuncField // Out presents fields of function output results. Out []FuncField // Conflict identifies the index of current type in a list of // types which have same type names. In most cases, this field is 0. Conflict int }
Type describes an go type.
func (*Type) RawTypeName ¶
RawTypeName returns raw type name without confliction.
type TypeContainer ¶
type TypeContainer struct {
// contains filtered or unexported fields
}
TypeContainer contains types.
func NewTypeContainer ¶
func NewTypeContainer() *TypeContainer
NewTypeContainer creates a type container.
func (*TypeContainer) Complete ¶
func (tc *TypeContainer) Complete(analyzer *Analyzer) error
Complete fills comments for all types.
func (*TypeContainer) NameOf ¶
func (tc *TypeContainer) NameOf(typ reflect.Type) TypeName
NameOf gets an unique name of a type.
func (*TypeContainer) NameOfInstance ¶
func (tc *TypeContainer) NameOfInstance(ins interface{}) TypeName
NameOfInstance gets type name of an instance.
func (*TypeContainer) Type ¶
func (tc *TypeContainer) Type(name TypeName) *Type
Type gets type via type name.
func (*TypeContainer) Types ¶
func (tc *TypeContainer) Types() map[TypeName]*Type
Types returns all types