Documentation ¶
Overview ¶
Package apidocs implements the ability to generate API documentation.
Package apidocs provides functionality for handling API documentation. This package contains structures and methods related to generating API documentation in the apidocs JSON format. It includes models, definitions, and various utility functions.
Index ¶
- Variables
- func OrderedMarshalJSON(element interface{}, rank map[string]int) ([]byte, error)
- func OrderedUnmarshalJSON(b []byte, element interface{}, rank interface{}) error
- func WriteJSON(file string, data interface{}) error
- type BodyContentStruct
- type ComponentStruct
- type Definitions
- type InfoStruct
- type MediaStruct
- type MethodStruct
- type MethodStructX
- type Methods
- type MethodsX
- type ModelStruct
- type NewPropertyFunc
- type OpenAPIJSON
- type ParameterStructX
- type ParametersStruct
- type Paths
- type PathsX
- type Properties
- type PropertyStruct
- type SchemaStruct
- type SwaggerJSON
Constants ¶
This section is empty.
Variables ¶
var GetNameByRef = func(ref string) string { return strings.TrimPrefix(ref, refPrefix) }
GetNameByRef gets the name from a reference.
var RefName = func(name string) string { return fmt.Sprintf("%s%s", refPrefix, name) }
RefName returns a reference with the specified name.
Functions ¶
func OrderedMarshalJSON ¶
OrderedMarshalJSON serializes data to JSON while preserving the order of keys.
func OrderedUnmarshalJSON ¶
OrderedUnmarshalJSON deserializes JSON data while preserving the order of keys.
Types ¶
type BodyContentStruct ¶
type BodyContentStruct struct { Description string `json:"description"` // The description returned by method. Content map[string]MediaStruct `json:"content,omitempty"` }
BodyContentStruct defines the structure of the response in OpenAPI JSON for a given method.
type ComponentStruct ¶
type ComponentStruct struct {
Schemas map[string]ModelStruct `json:"schemas"`
}
ComponentStruct component struct
type Definitions ¶
type Definitions struct {
// contains filtered or unexported fields
}
Definitions models
func NewDefinitions ¶
func NewDefinitions(option *params.Option, fds ...descriptor.Desc) *Definitions
NewDefinitions returns a Definition instance.
type InfoStruct ¶
type InfoStruct struct { Title string `json:"title"` // Title of the doc. Description string `json:"description,omitempty"` // Description of the doc. Version string `json:"version,omitempty"` // Version of the doc. }
InfoStruct defines the structure of the documentation description information contained in the apidocs header.
func NewInfo ¶
func NewInfo(fd *descriptor.FileDescriptor) (InfoStruct, error)
NewInfo inits Info instance.
type MediaStruct ¶
type MediaStruct struct { Description string `json:"description,omitempty"` // The description returned by method. // The reference to the data model for the method reference, must have. Schema SchemaStruct `json:"schema,omitempty"` }
MediaStruct defines the structure of the response in api docs json for a given method.
type MethodStruct ¶
type MethodStruct struct { Summary string `json:"summary"` // Comments of method. OperationID string `json:"operationId"` // Name of method. Responses map[string]MediaStruct `json:"responses"` // Response. Parameters []*ParametersStruct `json:"parameters"` // Parameters. Tags []string `json:"tags"` // The service to which the method belongs. Description string `json:"description,omitempty"` // Description of the method. }
MethodStruct defines the detailed information of a method in apidocs.
func (MethodStruct) GetMethodX ¶
func (m MethodStruct) GetMethodX() *MethodStructX
GetMethodX converts MethodStruct to OpenAPI v3 interface.
type MethodStructX ¶
type MethodStructX struct { Summary string `json:"summary,omitempty"` // Comment of method. OperationID string `json:"operationId,omitempty"` // Name of method. Responses map[string]BodyContentStruct `json:"responses,omitempty"` // Response definition of method. // Structure of method's input parameters except body. Parameters []*ParameterStructX `json:"parameters,omitempty"` RequestBody *BodyContentStruct `json:"requestBody,omitempty"` // Struct definition of method input parameters. Tags []string `json:"tags,omitempty"` // The service to which the method belongs. Description string `json:"description,omitempty"` // Description of the method. }
MethodStructX defines the detailed information of a method in OpenAPI JSON.
type Methods ¶
type Methods struct { Elements map[string]*MethodStruct Rank map[string]int }
Methods is the set of methods.
func (Methods) GetMethodsX ¶
GetMethodsX converts MethodStruct to OpenAPI v3 interface.
func (Methods) MarshalJSON ¶
MarshalJSON serializes the method to JSON.
func (*Methods) Put ¶
func (methods *Methods) Put(key string, value *MethodStruct)
Put inserts an element into the ordered map, and records the element's rank in "Rank".
func (*Methods) UnmarshalJSON ¶
UnmarshalJSON deserializes JSON data.
type MethodsX ¶
type MethodsX struct { Elements map[string]*MethodStructX Rank map[string]int }
MethodsX for v3
func (MethodsX) MarshalJSON ¶
MarshalJSON serializes to JSON.
func (*MethodsX) UnmarshalJSON ¶
UnmarshalJSON deserializes JSON data.
type ModelStruct ¶
type ModelStruct struct { Type string `json:"type"` // Data model type Properties *Properties `json:"properties,omitempty"` // Data model parameters Title string `json:"title,omitempty"` // Data model title Description string `json:"description,omitempty"` // Data model description AdditionalProperties *PropertyStruct `json:"additionalProperties,omitempty"` // Usage of map value Ref string `json:"ref,omitempty"` Items *PropertyStruct `json:"items,omitempty"` }
ModelStruct defines the structure of the whole data model in the apidocs JSON.
type NewPropertyFunc ¶
type NewPropertyFunc func(field *desc.FieldDescriptor, defs *Definitions) PropertyStruct
NewPropertyFunc factory
type OpenAPIJSON ¶
type OpenAPIJSON struct { OpenAPI string `json:"openapi"` // Version of OpenAPI. Info InfoStruct `json:"info"` // Description of the API documentation. Paths PathsX `json:"paths"` // Set of specific information for request methods. // Definitions of various model data models, // including method input and output parameter's structure definitions. Components ComponentStruct `json:"components"` }
OpenAPIJSON defines the structure of the JSON file that OpenAPI API documentation needs to load.
func NewOpenAPIJSON ¶
func NewOpenAPIJSON(fd *descriptor.FileDescriptor, option *params.Option) (*OpenAPIJSON, error)
NewOpenAPIJSON returns a new OpenAPIJSON instance.
type ParameterStructX ¶
type ParameterStructX struct { Name string `json:"name"` // Name of the parameter. // Parameter's passing method: in, query, path, header, form. In string `json:"in"` Required bool `json:"required"` // Whether the parameter is required or not. Description string `json:"description,omitempty"` // Parameter description. Schema *ModelStruct `json:"schema,omitempty"` // Parameter reference. }
ParameterStructX for v3.
type ParametersStruct ¶
type ParametersStruct struct { Name string `json:"name"` // Name of the parameter. // Parameter's passing method: in, query, path, header, form. In string `json:"in"` Required bool `json:"required"` // Whether the parameter is required or not. Type string `json:"type,omitempty"` // Type of parameter. Schema *SchemaStruct `json:"schema,omitempty"` // Parameter reference, optional. Format string `json:"format,omitempty"` // Parameter format, optional. Description string `json:"description,omitempty"` // Parameter description, optional. Enum []int32 `json:"enum,omitempty"` // Possible values for the enum. // When type = array, it is necessary to indicate the member type, that is, the description of a single field value. Items *PropertyStruct `json:"items,omitempty"` Default interface{} `json:"default,omitempty"` // Default value of the parameter. }
ParametersStruct defines the structure of input parameters information for methods in Swagger JSON format.
func (ParametersStruct) GetParametersStructX ¶
func (param ParametersStruct) GetParametersStructX() *ParameterStructX
GetParametersStructX converts the structure.
func (ParametersStruct) GetProperty ¶
func (param ParametersStruct) GetProperty() *PropertyStruct
GetProperty converts the structure.
func (ParametersStruct) GetRequestBody ¶
func (param ParametersStruct) GetRequestBody() *BodyContentStruct
GetRequestBody converts the structure.
type Paths ¶
Paths is the set of Path.
func NewPaths ¶
func NewPaths(fd *descriptor.FileDescriptor, option *params.Option, defs *Definitions) (Paths, error)
NewPaths inits Path.
func (Paths) MarshalJSON ¶
MarshalJSON serializes to JSON
func (*Paths) Put ¶
Put puts the element into the ordered map and records the element's ranking order in "Rank".
func (*Paths) UnmarshalJSON ¶
UnmarshalJSON deserializes JSON data
type PathsX ¶
PathsX for v3
func (PathsX) MarshalJSON ¶
MarshalJSON serializes to JSON.
func (*PathsX) UnmarshalJSON ¶
UnmarshalJSON deserializes JSON data.
type Properties ¶
type Properties struct { Elements map[string]PropertyStruct Rank map[string]int }
Properties Properties
func NewProperties ¶
func NewProperties(option *params.Option, msg *desc.MessageDescriptor, defs *Definitions) *Properties
NewProperties new
func (Properties) MarshalJSON ¶
func (props Properties) MarshalJSON() ([]byte, error)
MarshalJSON serializes to JSON.
func (*Properties) Put ¶
func (props *Properties) Put(key string, value PropertyStruct)
Put puts an element into an ordered map and records the order of the elements in Rank.
func (*Properties) UnmarshalJSON ¶
func (props *Properties) UnmarshalJSON(b []byte) error
UnmarshalJSON deserializes JSON data.
type PropertyStruct ¶
type PropertyStruct struct { Title string `json:"title,omitempty"` // Name of parameter. Type string `json:"type,omitempty"` // Type of parameter. Format string `json:"format,omitempty"` // Format of parameter. Ref string `json:"$ref,omitempty"` // References in parameter. Description string `json:"description,omitempty"` // Description of paramaeter. Enum []int32 `json:"enum,omitempty"` // Possible values of the enum type. // When type is array, specify the member type, i.e., the description of a single field value. Items *PropertyStruct `json:"items,omitempty"` }
PropertyStruct defines the structure of a single field of a data model in the api docs json.
func NewProperty ¶
func NewProperty(field *desc.FieldDescriptor, defs *Definitions) PropertyStruct
NewProperty new
func (PropertyStruct) GetQueryParameter ¶
func (p PropertyStruct) GetQueryParameter(name string) *ParametersStruct
GetQueryParameter converts the given parameters into a query parameter string.
func (PropertyStruct) GetQueryParameters ¶
func (p PropertyStruct) GetQueryParameters(name string, defs *Definitions, searched map[string]bool) []*ParametersStruct
GetQueryParameters converts the given parameters into a query parameter string.
type SchemaStruct ¶
type SchemaStruct struct { Ref string `json:"$ref,omitempty"` Type string `json:"type,omitempty"` Properties []*PropertyStruct `json:"properties,omitempty"` }
SchemaStruct defines the structure of schema used by data model in api docs json.
type SwaggerJSON ¶
type SwaggerJSON struct { Swagger string `json:"swagger"` // Version of Swagger. Info InfoStruct `json:"info"` // Description information of the API document. Consumes []string `json:"consumes"` Produces []string `json:"produces"` // A collection of detailed information for the request method. Paths Paths `json:"paths"` // Various model definitions, including the structure definitions of method input and output parameters. Definitions map[string]ModelStruct `json:"definitions"` }
SwaggerJSON defines the structure of the JSON that contains the swagger API documentation.
func NewSwagger ¶
func NewSwagger(fd *descriptor.FileDescriptor, option *params.Option) (*SwaggerJSON, error)
NewSwagger generates swagger documents.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package openapi provides the ability to manipulate OpenAPI documents.
|
Package openapi provides the ability to manipulate OpenAPI documents. |
Package swagger provides the ability to manipulate swagger documentation.
|
Package swagger provides the ability to manipulate swagger documentation. |
Package x provides common utilities for documentation operations.
|
Package x provides common utilities for documentation operations. |