Documentation
¶
Index ¶
- func GenerateProto(api *APIDefinition, annotate bool) ([]byte, error)
- func OperationIDToName(operationID string) string
- func PathMethodToName(path, method, operationID string) string
- func ProtoEnum(name string, enums []string, depth int) string
- type APIDefinition
- type Endpoint
- type Extension
- type ExtensionField
- type GRPCOptions
- type HTTPAnnotation
- type Items
- type Model
- type Parameters
- type Path
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateProto ¶
func GenerateProto(api *APIDefinition, annotate bool) ([]byte, error)
GenerateProto will attempt to generate an protobuf version 3 schema from the given OpenAPI definition.
func OperationIDToName ¶
func PathMethodToName ¶
Types ¶
type APIDefinition ¶
type APIDefinition struct { FileName string // internal use to pass file path Swagger string `yaml:"swagger" json:"swagger"` Info struct { Title string `yaml:"title" json:"title"` Description string `yaml:"description" json:"description"` Version string `yaml:"version" json:"version"` } `yaml:"info" json:"info"` Host string `yaml:"host" json:"host"` Schemes []string `yaml:"schemes" json:"schemes"` BasePath string `yaml:"basePath" json:"basePath"` Produces []string `yaml:"produces" json:"produces"` Paths map[string]*Path `yaml:"paths" json:"paths"` Definitions map[string]*Items `yaml:"definitions" json:"definitions"` Parameters map[string]*Items `yaml:"parameters" json:"parameters"` GlobalOptions GRPCOptions `yaml:"x-global-options" json:"x-global-options"` Extensions []*Extension `yaml:"x-extensions" json:"x-extensions"` }
APIDefinition is the base struct for containing OpenAPI spec declarations.
func LoadDefinition ¶
func LoadDefinition(pth string) (*APIDefinition, error)
type Endpoint ¶
type Endpoint struct { Summary string `yaml:"summary" json:"summary"` Description string `yaml:"description" json:"description"` Parameters Parameters `yaml:"parameters" json:"parameters"` Tags []string `yaml:"tags" json:"tags"` Responses map[string]*Response `yaml:"responses" json:"responses"` OperationID string `yaml:"operationId" json:"operationId"` Options GRPCOptions `yaml:"x-options" json:"x-options"` // contains filtered or unexported fields }
Endpoint represents an endpoint for a path in an OpenAPI spec.
type Extension ¶
type Extension struct { Base string `json:"base" yaml:"base"` Fields []*ExtensionField `json:"fields" yaml:"fields"` }
type ExtensionField ¶
type GRPCOptions ¶
type GRPCOptions map[string]interface{}
type HTTPAnnotation ¶
type HTTPAnnotation struct {
// contains filtered or unexported fields
}
func NewHTTPAnnotation ¶
func NewHTTPAnnotation(method, path, body string) *HTTPAnnotation
func (HTTPAnnotation) Protobuf ¶
func (a HTTPAnnotation) Protobuf(indent string) string
type Items ¶
type Items struct { Description string `yaml:"description,omitempty" json:"description,omitempty"` // scalar Type interface{} `yaml:"type" json:"type"` Format interface{} `yaml:"format,omitempty" json:"format,omitempty"` Enum []string `yaml:"enum,omitempty" json:"enum,omitempty"` ProtoTag int `yaml:"x-proto-tag" json:"x-proto-tag"` // Map type AdditionalProperties interface{} `yaml:"additionalProperties" json:"additionalProperties"` // ref another Model Ref string `yaml:"$ref" json:"$ref"` // is an array Items *Items `yaml:"items" json:"items"` // for request parameters In string `yaml:"in" json:"in"` Schema *Items `yaml:"schema" json:"schema"` // is an other Model Model `yaml:",inline"` // required items Required interface{} `yaml:"required,omitempty" json:"required,omitempty"` // validation (regex pattern, max/min length) Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` MaxLength int `yaml:"maxLength,omitempty" json:"max_length,omitempty"` MinLength int `yaml:"minLength,omitempty" json:"min_length,omitempty"` }
Items represent Model properties in an OpenAPI spec.
func (Items) HasComment ¶
type Model ¶
type Model struct { Properties map[string]*Items `yaml:"properties" json:"properties"` Name string Depth int }
Model represents a model definition from an OpenAPI spec.
type Parameters ¶
type Parameters []*Items
Parameters is a slice of request parameters for a single endpoint.
func (Parameters) ProtoMessage ¶
func (p Parameters) ProtoMessage(dst io.Writer, parent Parameters, endpointName string, defs map[string]*Items)
ProtoMessage will return a protobuf v3 message that represents the request Parameters.
type Path ¶
type Path struct { Get *Endpoint `yaml:"get" json:"get"` Put *Endpoint `yaml:"put" json:"put"` Post *Endpoint `yaml:"post" json:"post"` Delete *Endpoint `yaml:"delete" json:"delete"` Parameters Parameters `yaml:"parameters" json:"parameters"` }
Path represents all of the endpoints and parameters available for a single path.
func (*Path) ProtoEndpoints ¶
ProtoEndpoints will return any protobuf v3 endpoints for gRPC service declarations.
func (*Path) ProtoMessages ¶
ProtoMessages will return protobuf v3 messages that represents the request Parameters of the endpoints within this path declaration and any custom response messages not listed in the definitions.
type Response ¶
type Response struct { Description string `yaml:"description" json:"description"` Schema *Items `yaml:"schema" json:"schema"` }
Response represents the response object in an OpenAPI spec.
func (*Response) ProtoMessage ¶
ProtoMessage will return a protobuf message declaration based on the response schema. If the response is an array type, it will get wrapped in a generic message with a single 'items' field to contain the array.