Documentation ¶
Index ¶
- func BaseStringToTypeCode() string
- func Capitalize(input string) string
- func ClientInterface(s *spec.Swagger, op *spec.Operation) string
- func ClientIterInterface(s *spec.Swagger, op *spec.Operation) string
- func CodeToTypeMap(s *spec.Swagger, op *spec.Operation, makePointers bool) map[int]string
- func DefaultAsString(param spec.Parameter) string
- func ImportStatements(imports []string) string
- func InitCustomFormats()
- func Interface(s *spec.Swagger, op *spec.Operation) string
- func InterfaceComment(method, path string, client bool, s *spec.Swagger, op *spec.Operation) (string, error)
- func OperationInput(op *spec.Operation) string
- func OutputType(s *spec.Swagger, op *spec.Operation, statusCode int) (string, bool)
- func PagingParam(op *spec.Operation) (spec.Parameter, bool)
- func PagingResourcePath(op *spec.Operation) []string
- func PagingResourceType(s *spec.Swagger, op *spec.Operation) (string, bool, error)
- func ParamToStringCode(param spec.Parameter, op *spec.Operation) string
- func ParamToType(param spec.Parameter) (string, bool, error)
- func ParamToValidationCode(param spec.Parameter, op *spec.Operation) ([]string, error)
- func PathItemOperations(item spec.PathItem) map[string]*spec.Operation
- func SingleSchemaedBodyParameter(op *spec.Operation) (bool, string)
- func SingleStringPathParameter(op *spec.Operation) (bool, string)
- func SortedOperationsKeys(m map[string]*spec.Operation) []string
- func SortedPathItemKeys(m map[string]spec.PathItem) []string
- func SortedResponses(m map[string]spec.Response) []string
- func SortedSchemaProperties(schema spec.Schema) []string
- func SortedStatusCodeKeys(m map[int]spec.Response) []int
- func StringToTypeCode(strField string, param spec.Parameter, op *spec.Operation) (string, error)
- func StructParamName(param spec.Parameter) string
- func SuccessType(s *spec.Swagger, op *spec.Operation) *string
- func TypeFromSchema(schema *spec.Schema, includeModels bool) (string, error)
- func TypeToCodeMap(s *spec.Swagger, op *spec.Operation) (map[string]int, error)
- func ValidateResponses(s spec.Swagger) error
- func WriteToFile(s *spec.Swagger) (string, error)
- type Generator
- type ParamTemplate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseStringToTypeCode ¶
func BaseStringToTypeCode() string
BaseStringToTypeCode is the helper code from base string to type
func ClientInterface ¶ added in v1.3.0
ClientInterface returns the client-facing interface for an operation
func ClientIterInterface ¶ added in v1.3.0
ClientIterInterface returns the client-facing interface for the iterator builder of an operation
func CodeToTypeMap ¶
CodeToTypeMap returns a map from return status code to its corresponding type
func DefaultAsString ¶
DefaultAsString returns the default value as a string. We convert it into a string so it's easier to insert into the generated code and it doesn't make this logic really any different.
func ImportStatements ¶
ImportStatements takes a list of import strings and converts them to a formatted imports
func InitCustomFormats ¶
func InitCustomFormats()
InitCustomFormats adds wag's custom formats to the global go-openapi/strfmt Default registry.
func InterfaceComment ¶
func InterfaceComment(method, path string, client bool, s *spec.Swagger, op *spec.Operation) (string, error)
InterfaceComment returns the comment for the interface for the operation. If the client flag is set then it generates the client version. Otherwise it generates the server version.
func OperationInput ¶ added in v1.3.0
OperationInput returns the input to an operation
func OutputType ¶
OutputType returns the output type for a given status code of an operation and whether it is a pointer in the interface.
func PagingParam ¶ added in v1.3.0
PagingParam returns the parameter that specifies the page ID for this operation, if paging is configured. If paging is not configured, the second return value is `false`.
func PagingResourcePath ¶ added in v1.3.0
PagingResourcePath returns the path to the array to page over for a paging-enabled endpoint (specified by x-paging.resourcePath). Panics if paging is not enabled.
func PagingResourceType ¶ added in v1.3.0
PagingResourceType returns the type of the items of the array set to page over for this operation and whether the array should consist of pointers to that type. Panics if paging is not enabled.
func ParamToStringCode ¶
ParamToStringCode returns a function that converts a Parameter into the code to convert it into a string (for serialization). For example, a integer named 'Size' becomes `strconv.FormatInt(i.Size, 10)`
func ParamToType ¶
ParamToType converts a parameter into its Go type. It returns the type name and a bool indiciating whether it should be a pointer.
func ParamToValidationCode ¶
ParamToValidationCode takes in a param and returns a list of parameter validation functions, each of which have a single return value, error
func PathItemOperations ¶
PathItemOperations converts a spec.PathItem to a map from HTTP operation (e.g., "GET") to spec.Operation.
func SingleSchemaedBodyParameter ¶
SingleSchemaedBodyParameter returns true if the operation has a single, schema'd body input. It also returns the name of the model (without "models.").
func SingleStringPathParameter ¶ added in v0.5.0
SingleStringPathParameter returns true if the operation has a single, required string input in the URL path. It also returns the name of the parameter.
func SortedOperationsKeys ¶
SortedOperationsKeys sorts the keys of a map[string]*spec.Operation.
func SortedPathItemKeys ¶
SortedPathItemKeys sorts the keys of a map[string]spec.PathItem.
func SortedResponses ¶ added in v0.4.0
SortedResponses sorts the keys of a map[string[spec].Response
func SortedSchemaProperties ¶ added in v1.0.0
SortedSchemaProperties sorts the properties of a schema
func SortedStatusCodeKeys ¶
SortedStatusCodeKeys sorts the keys of a map[int]spec.Response.
func StringToTypeCode ¶
StringToTypeCode returns the code to convert a string into the type. For example, for an int64 it generates swag.ConvertFloat64(sizeStr). It returns an array because sometimes this takes multiple lines of code
func StructParamName ¶
StructParamName returns the name of the struct as used in the model struct
func SuccessType ¶ added in v1.0.2
SuccessType returns the success type for the operation. If there is no success-type then it returns nil
func TypeFromSchema ¶
TypeFromSchema returns the type of a Swagger schema as a string. If includeModels is true then it returns models.TYPE
func TypeToCodeMap ¶ added in v0.4.0
TypeToCodeMap returns a map from the type to its corresponding status code. It returns an error if mutiple status codes map to the same type
func ValidateResponses ¶ added in v0.6.0
ValidateResponses checks the responses from swagger operations, and in a few cases tweaks the swagger spec to make them valid. This means a few things: - Verifying that the spec only has one success type - Verifying the required global error types exist and that they have the required fields - Adding 400 / 500 responses to any operation that doesn't have them defined
Types ¶
type Generator ¶
type Generator struct { PackageName string // contains filtered or unexported fields }
Generator handles common code generation operations when generating a file in a Go package.
type ParamTemplate ¶ added in v1.3.0
type ParamTemplate struct { Name string ToStringCode string Type string AccessString string Pointer bool }
ParamTemplate includes information needed by template code to use a parameter.
func ParamToTemplate ¶ added in v1.3.0
func ParamToTemplate(param *spec.Parameter, op *spec.Operation) ParamTemplate
ParamToTemplate converts a spec.Parameter into the a struct with the information needed to template code that uses that parameter. For example, it figures out what the access string for the parameter should be (e.g. either "i.$FIELD" or just $FIELD) and whether the field should be used as a pointer or not.