swagger

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2016 License: Apache-2.0 Imports: 16 Imported by: 8

Documentation

Index

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 Capitalize

func Capitalize(input string) string

Capitalize the first character of a string.

func CodeToTypeMap

func CodeToTypeMap(s *spec.Swagger, op *spec.Operation, makePointers bool) map[int]string

CodeToTypeMap returns a map from return status code to its corresponding type

func DefaultAsString

func DefaultAsString(param spec.Parameter) string

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

func ImportStatements(imports []string) string

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 Interface

func Interface(s *spec.Swagger, op *spec.Operation) string

Interface returns the interface for an operation

func InterfaceComment

func InterfaceComment(method, path string, s *spec.Swagger, op *spec.Operation) (string, error)

InterfaceComment returns the comment for the interface for the operation

func OutputType

func OutputType(s *spec.Swagger, op *spec.Operation, statusCode int) (string, bool)

OutputType returns the output type for a given status code of an operation and whether it is a pointer in the interface.

func ParamToStringCode

func ParamToStringCode(param spec.Parameter, op *spec.Operation) string

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

func ParamToType(param spec.Parameter) (string, bool, error)

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

func ParamToValidationCode(param spec.Parameter, op *spec.Operation) ([]string, error)

ParamToValidationCode takes in a param and returns a list of parameter validation functions, each of which have a single return value, error

func PathItemOperations

func PathItemOperations(item spec.PathItem) map[string]*spec.Operation

PathItemOperations converts a spec.PathItem to a map from HTTP operation (e.g., "GET") to spec.Operation.

func SingleSchemaedBodyParameter

func SingleSchemaedBodyParameter(op *spec.Operation) (bool, string)

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

func SingleStringPathParameter(op *spec.Operation) (bool, string)

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

func SortedOperationsKeys(m map[string]*spec.Operation) []string

SortedOperationsKeys sorts the keys of a map[string]*spec.Operation.

func SortedPathItemKeys

func SortedPathItemKeys(m map[string]spec.PathItem) []string

SortedPathItemKeys sorts the keys of a map[string]spec.PathItem.

func SortedResponses added in v0.4.0

func SortedResponses(m map[string]spec.Response) []string

SortedResponses sorts the keys of a map[string[spec].Response

func SortedSchemaProperties added in v1.0.0

func SortedSchemaProperties(schema spec.Schema) []string

SortedSchemaProperties sorts the properties of a schema

func SortedStatusCodeKeys

func SortedStatusCodeKeys(m map[int]spec.Response) []int

SortedStatusCodeKeys sorts the keys of a map[int]spec.Response.

func StringToTypeCode

func StringToTypeCode(strField string, param spec.Parameter, op *spec.Operation) (string, error)

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

func StructParamName(param spec.Parameter) string

StructParamName returns the name of the struct as used in the model struct

func SuccessType added in v1.0.2

func SuccessType(s *spec.Swagger, op *spec.Operation) *string

SuccessType returns the success type for the operation. If there is no success-type then it returns nil

func TypeFromSchema

func TypeFromSchema(schema *spec.Schema, includeModels bool) (string, error)

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

func TypeToCodeMap(s *spec.Swagger, op *spec.Operation) (map[string]int, error)

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

func ValidateResponses(s spec.Swagger) error

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

func WriteToFile added in v0.4.0

func WriteToFile(s *spec.Swagger) (string, error)

WriteToFile writes the swagger spec to a temporary file. It returns the name of the created file.

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.

func (*Generator) Printf

func (g *Generator) Printf(format string, args ...interface{})

Printf writes a formatted string to the buffer.

func (*Generator) Write

func (g *Generator) Write(p []byte) (n int, err error)

Write bytes to the buffer.

func (*Generator) WriteFile

func (g *Generator) WriteFile(path string) error

WriteFile writes the buffer to a gofmt-ed file. The file will be located at $GOPATH/src/{PackageName}/{path}.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL