Documentation ¶
Index ¶
- Constants
- Variables
- func AddPattern(pattern string) (key string)
- func GinReturnType(httpContent string) string
- func HasTag(src []string, tag string) bool
- func IsBytes(p code.Type) bool
- func IsSupportNegotiate(ress []string) bool
- func ModelMapToTypeInfo(model map[string]*ModelMap) (map[string]*code.TypeInfo, error)
- func NewTemplate(name string) *helper.Template
- func OasUriToGinUri(uri string) string
- func PrepareEnv(c *Config) (undo func() error, err error)
- type Config
- type GenerateFunc
- type Generator
- type Graph
- type GraphTemplate
- type Hook
- type ModelMap
- type NodeTemplate
- type Operation
- func (op *Operation) AddParameter(params ...*Parameter)
- func (op *Operation) GenRequest()
- func (op *Operation) GenResponse(codeStr string, spec *openapi3.ResponseRef) *Response
- func (op *Operation) GenResponses()
- func (op *Operation) GenSecurity(ssSpec openapi3.SecuritySchemes)
- func (op *Operation) HasRequest() bool
- func (op *Operation) HasResponse() bool
- func (op *Operation) RequestName() string
- func (op *Operation) SimpleBody() *Parameter
- type Parameter
- type Request
- type Response
- type Schema
- func (sch *Schema) AppendContentTypeStructTag(c *Config, tagName string, contentTypes []string)
- func (sch *Schema) CheckRequired()
- func (sch *Schema) CollectTags()
- func (sch *Schema) CopyTo(tg *Schema)
- func (sch *Schema) GenSchemaType(c *Config, name string, spec *openapi3.SchemaRef)
- func (sch *Schema) IsObjectArray() bool
- func (sch Schema) StructTagsString() string
- type Tag
Constants ¶
const (
TagRegular = "regex"
)
Variables ¶
var ( Templates = []NodeTemplate{ { Name: "tag", Format: pkgf("%s_tag.go"), }, } GraphTemplates = []GraphTemplate{ { Name: "interface", Format: "interface.go", }, { Name: "schema", Format: "model.go", }, { Name: "server", Format: "server/server.go", }, { Name: "validator", Format: "server/validator.go", }, } )
Functions ¶
func AddPattern ¶
func GinReturnType ¶
GinReturnType returns the which gin call for the incoming content type
func IsSupportNegotiate ¶
IsSupportNegotiate check if the response content type is support negotiate. if the response content type is not support negotiate, the response content type will be set to the first content type in the response use bytes.
func ModelMapToTypeInfo ¶
func NewTemplate ¶
NewTemplate creates an empty template with the standard codegen functions.
func OasUriToGinUri ¶
OasUriToGinUri converts a swagger style path URI with parameters to a Gin compatible path URI. We need to replace all Swagger parameters with ":param". Valid input parameters are:
{param} {param*} {.param} {.param*} {;param} {;param*} {?param} {?param*}
func PrepareEnv ¶
PrepareEnv makes sure the generated directory (environment) is suitable for loading the `ent` package (avoid cyclic imports).
Types ¶
type Config ¶
type Config struct { OpenAPISchema string `json:"spec,omitempty"` Package string `json:"package"` Target string `json:"target,omitempty"` Header string `json:"header,omitempty"` // Templates specifies a list of alternative templates to execute or // to override the default. If nil, the default template is used. // // Note that, additional templates are executed on the Graph object and // the execution output is stored in a file derived by the template name. Templates []*helper.Template // Hooks holds an optional list of Hooks to apply on the graph before/after the code-generation. Hooks []Hook Models map[string]*ModelMap `json:"models,omitempty"` TypeMap map[string]*code.TypeInfo // Schemas is the list of all schemas reference in the spec. Schemas []*Schema // contains filtered or unexported fields }
The Config holds the global codegen configuration to be shared between all generated nodes.
type GenerateFunc ¶
The GenerateFunc type is an adapter to allow the use of ordinary function as Generator. If f is a function with the appropriate signature, GenerateFunc(f) is a Generator that calls f.
func (GenerateFunc) Generate ¶
func (f GenerateFunc) Generate(g *Graph) error
type Graph ¶
type Graph struct { *Config Nodes []*Tag Spec *openapi3.T // contains filtered or unexported fields }
type GraphTemplate ¶
type Hook ¶
Hook defines the "generate middleware". A function that gets a Generator and returns a Generator. For example:
hook := func(next gen.Generator) gen.Generator { return gen.GenerateFunc(func(g *Graph) error { fmt.Println("Graph:", g) return next.Generate(g) }) }
type NodeTemplate ¶
type Operation ¶
type Operation struct { *Config Name string Group string // first tag name Method string // GET, POST, DELETE, etc. Path string Spec *openapi3.Operation SpecPathItem *openapi3.PathItem // navigation to pathItem Request *Request Responses []*Response ResponseOK *Response ResponseNotFound *Response IgnoreInterface bool }
Operation is for operation of openapi3
func (*Operation) AddParameter ¶
func (*Operation) GenRequest ¶
func (op *Operation) GenRequest()
func (*Operation) GenResponse ¶
func (op *Operation) GenResponse(codeStr string, spec *openapi3.ResponseRef) *Response
func (*Operation) GenResponses ¶
func (op *Operation) GenResponses()
func (*Operation) GenSecurity ¶
func (op *Operation) GenSecurity(ssSpec openapi3.SecuritySchemes)
func (*Operation) HasRequest ¶
func (*Operation) HasResponse ¶
func (*Operation) RequestName ¶
RequestName returns the name of the request struct.
func (*Operation) SimpleBody ¶
SimpleBody if request body is only one, use the parameter to body field
type Response ¶
type Response struct { Name string // return content type when response is not empty ContentTypes []string // http status Status int Schema *Schema Spec *openapi3.Response Description *string }
Response is for response of openapi3
type Schema ¶
type Schema struct { Spec *openapi3.SchemaRef // The original OpenAPIv3 Schema. Name string // The name of the schema. Type *code.TypeInfo // The type of the schema. IsRef bool HasRegular bool // if schema has a pattern setting Required bool StructTags []string Properties map[string]*Schema IsInline bool // if schema is inline , schema is embedded in another schema IsReplace bool // if schema is replaced by model defined in config IsAlias bool // if schema is alias of not go native type IsArray bool // contains filtered or unexported fields }
Schema is for schema of openapi3 a struct , the struct 's field all is Schema Properties are sort by name, because openapi3 use map to store properties,map is not ordered.
func (*Schema) AppendContentTypeStructTag ¶
AppendContentTypeStructTag parse content type and append to struct tags.if depends on Request or Response content type.
func (*Schema) CheckRequired ¶
func (sch *Schema) CheckRequired()
CheckRequired checks if the schema is required and updates the schema type if needed
func (*Schema) CollectTags ¶
func (sch *Schema) CollectTags()
CollectTags collects all struct tags from the schema and its children.
func (*Schema) GenSchemaType ¶
GenSchemaType generates the type of the parameter by SPEC. schema type from : the schema's sepc , additionalProperties, array items
func (*Schema) IsObjectArray ¶
IsObjectArray returns true if the schema is an array of objects
func (Schema) StructTagsString ¶
type Tag ¶
Tag is for tag of openapi3
func (*Tag) AddOperation ¶
AddOperation adds an operation to the Tag.