Documentation ¶
Overview ¶
Package generator provides the code generation library for go-swagger.
Generating data types ¶
The general idea is that you should rarely see interface{} in the generated code. You get a complete representation of a swagger document in somewhat idiomatic go.
To do so, there is a set of mapping patterns that are applied, to map a Swagger specification to go types:
definition of primitive => type alias/name definition of array => type alias/name definition of map => type alias/name definition of object with properties => struct definition of $ref => type alias/name object with only additional properties => map[string]T object with additional properties and properties => custom serializer schema with schema array in items => tuple (struct with properties, custom serializer) schema with all of => struct * allOf schema with $ref => embedded value * allOf schema with properties => properties are included in struct * adding an allOf schema with just "x-isnullable": true or "x-nullable": true turns the schema into a pointer when there are only other extension properties provided
NOTE: anyOf and oneOf JSON-schema constructs are not supported by Swagger 2.0
A property on a definition is a pointer when any one of the following conditions is met:
it is an object schema (struct) it has x-nullable or x-isnullable as vendor extension it is a primitive where the zero value is valid but would fail validation otherwise strings minLength > 0 or required results in non-pointer numbers min > 0, max < 0 and min < max
JSONSchema and by extension Swagger allow for items that have a fixed size array, with the schema describing the items at each index. This can be combined with additional items to form some kind of tuple with varargs.
To map this to go it creates a struct that has fixed names and a custom json serializer.
NOTE: the additionalItems keyword is not supported by Swagger 2.0. However, the generator and validator parts in go-swagger do.
Documenting the generated code ¶
The code that is generated also gets the doc comments that are used by the scanner to generate a spec from go code. So that after generation you should be able to reverse generate a spec from the code that was generated by your spec.
It should be equivalent to the original spec but might miss some default values and examples.
Index ¶
- Constants
- Variables
- func AddFile(name, data string) error
- func Asset(name string) ([]byte, error)
- func AssetDigest(name string) ([sha256.Size]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func AssetString(name string) (string, error)
- func DefaultFuncMap(lang *LanguageOpts) template.FuncMap
- func DefaultSectionOpts(gen *GenOpts)
- func Digests() (map[string][sha256.Size]byte, error)
- func GenerateClient(name string, modelNames, operationIDs []string, opts *GenOpts) error
- func GenerateDefinition(modelNames []string, opts *GenOpts) error
- func GenerateMarkdown(output string, modelNames, operationIDs []string, opts *GenOpts) error
- func GenerateModels(modelNames []string, opts *GenOpts) error
- func GenerateServer(name string, modelNames, operationIDs []string, opts *GenOpts) error
- func GenerateServerOperation(operationNames []string, opts *GenOpts) error
- func GenerateSupport(name string, modelNames, operationIDs []string, opts *GenOpts) error
- func MarkdownSectionOpts(gen *GenOpts, output string)
- func MustAsset(name string) []byte
- func MustAssetString(name string) string
- func ReadConfig(fpath string) (*viper.Viper, error)
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func WithAutoXOrder(specPath string) string
- type GenApp
- type GenCommon
- type GenDefinition
- type GenDefinitions
- type GenHeader
- type GenHeaders
- type GenItems
- type GenOperation
- type GenOperationGroup
- type GenOperationGroups
- type GenOperations
- type GenOpts
- type GenParameter
- func (g *GenParameter) IsBodyParam() bool
- func (g *GenParameter) IsFileParam() bool
- func (g *GenParameter) IsFormParam() bool
- func (g *GenParameter) IsHeaderParam() bool
- func (g *GenParameter) IsPathParam() bool
- func (g *GenParameter) IsQueryParam() bool
- func (g *GenParameter) ItemsDepth() string
- func (g GenParameter) ToString() string
- func (g GenParameter) UnderlyingType() string
- func (rt GenParameter) Zero() string
- type GenParameters
- type GenResponse
- type GenResponseExample
- type GenResponseExamples
- type GenSchema
- type GenSchemaList
- type GenSecurityRequirement
- type GenSecurityRequirements
- type GenSecurityScheme
- type GenSecuritySchemes
- type GenSecurityScope
- type GenSerGroup
- type GenSerGroups
- type GenSerializer
- type GenSerializers
- type GenStatusCodeResponses
- type LanguageConfig
- type LanguageDefinition
- type LanguageOpts
- func (l *LanguageOpts) FormatContent(name string, content []byte) ([]byte, error)
- func (l *LanguageOpts) Init()
- func (l *LanguageOpts) MangleFileName(name string) string
- func (l *LanguageOpts) MangleName(name, suffix string) string
- func (l *LanguageOpts) ManglePackageName(name, suffix string) string
- func (l *LanguageOpts) ManglePackagePath(name string, suffix string) string
- func (l *LanguageOpts) MangleVarName(name string) string
- type Repository
- func (t *Repository) AddFile(name, data string) error
- func (t *Repository) DumpTemplates()
- func (t *Repository) Get(name string) (*template.Template, error)
- func (t *Repository) LoadContrib(name string) error
- func (t *Repository) LoadDefaults()
- func (t *Repository) LoadDir(templatePath string) error
- func (t *Repository) MustGet(name string) *template.Template
- func (t *Repository) SetAllowOverride(value bool)
- func (t *Repository) ShallowClone() *Repository
- type SectionOpts
- type TemplateOpts
Constants ¶
const AssetDebug = false
AssetDebug is true if the assets were built with the debug flag enabled.
Variables ¶
var ( // Debug when the env var DEBUG or SWAGGER_DEBUG is not empty // the generators will be very noisy about what they are doing Debug = os.Getenv("DEBUG") != "" || os.Getenv("SWAGGER_DEBUG") != "" )
var ( // DefaultLanguageFunc defines the default generation language DefaultLanguageFunc func() *LanguageOpts )
var ( // FuncMapFunc yields a map with all functions for templates FuncMapFunc func(*LanguageOpts) template.FuncMap )
Functions ¶
func AddFile ¶ added in v0.17.0
AddFile adds a file to the default repository. It will create a new template based on the filename. It trims the .gotmpl from the end and converts the name using swag.ToJSONName. This will strip directory separators and Camelcase the next letter. e.g validation/primitive.gotmpl will become validationPrimitive
If the file contains a definition for a template that is protected the whole file will not be added
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDigest ¶ added in v0.17.1
AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"}, AssetDir("data/img") would return []string{"a.png", "b.png"}, AssetDir("foo.txt") and AssetDir("notexist") would return an error, and AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetString ¶ added in v0.17.1
AssetString returns the asset contents as a string (instead of a []byte).
func DefaultFuncMap ¶ added in v0.26.0
func DefaultFuncMap(lang *LanguageOpts) template.FuncMap
DefaultFuncMap yields a map with default functions for use n the templates. These are available in every template
func DefaultSectionOpts ¶ added in v0.17.0
func DefaultSectionOpts(gen *GenOpts)
DefaultSectionOpts for a given opts, this is used when no config file is passed and uses the embedded templates when no local override can be found
func GenerateClient ¶
GenerateClient generates a client library for a swagger spec document.
func GenerateDefinition ¶
GenerateDefinition generates a single model file for some schema definitions
func GenerateMarkdown ¶ added in v0.26.0
GenerateMarkdown documentation for a swagger specification
func GenerateModels ¶ added in v0.26.0
GenerateModels generates all model files for some schema definitions
func GenerateServer ¶ added in v0.17.0
GenerateServer generates a server application
func GenerateServerOperation ¶
GenerateServerOperation generates a parameter model, parameter validator, http handler implementations for a given operation.
It also generates an operation handler interface that uses the parameter model for handling a valid request. Allows for specifying a list of tags to include only certain tags for the generation
func GenerateSupport ¶
GenerateSupport generates the supporting files for an API
func MarkdownSectionOpts ¶ added in v0.26.0
MarkdownSectionOpts for a given opts and output file.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func MustAssetString ¶ added in v0.17.1
MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables.
func ReadConfig ¶ added in v0.17.0
ReadConfig at the specified path, when no path is specified it will look into the current directory and load a .swagger.{yml,json,hcl,toml,properties} file Returns a viper config or an error
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory.
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively.
func WithAutoXOrder ¶ added in v0.26.0
WithAutoXOrder amends the spec to specify property order as they appear in the spec (supports yaml documents only).
Types ¶
type GenApp ¶
type GenApp struct { GenCommon APIPackage string ServerPackageAlias string APIPackageAlias string Package string ReceiverName string Name string Principal string PrincipalIsNullable bool DefaultConsumes string DefaultProduces string Host string BasePath string Info *spec.Info ExternalDocs *spec.ExternalDocumentation Tags []spec.Tag Imports map[string]string DefaultImports map[string]string Schemes []string ExtraSchemes []string Consumes GenSerGroups Produces GenSerGroups SecurityDefinitions GenSecuritySchemes SecurityRequirements []analysis.SecurityRequirement // original security requirements as per the spec (for doc) Models []GenDefinition Operations GenOperations OperationGroups GenOperationGroups SwaggerJSON string // Embedded specs: this is important for when the generated server adds routes. // NOTE: there is a distinct advantage to having this in runtime rather than generated code. // We are not ever going to generate the router. // If embedding spec is an issue (e.g. memory usage), this can be excluded with the --exclude-spec // generation option. Alternative methods to serve spec (e.g. from disk, ...) may be implemented by // adding a middleware to the generated API. FlatSwaggerJSON string ExcludeSpec bool GenOpts *GenOpts }
GenApp represents all the meta data needed to generate an application from a swagger spec
func (*GenApp) UseFlags ¶ added in v0.26.0
UseFlags returns true when the flag strategy is set to flag
func (*GenApp) UseGoStructFlags ¶ added in v0.17.0
UseGoStructFlags returns true when no strategy is specified or it is set to "go-flags"
func (*GenApp) UseIntermediateMode ¶ added in v0.17.0
UseIntermediateMode for https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28default.29
func (*GenApp) UseModernMode ¶ added in v0.17.0
UseModernMode for https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility
type GenCommon ¶ added in v0.17.0
GenCommon contains common properties needed across definitions, app and operations TargetImportPath may be used by templates to import other (possibly generated) packages in the generation path (e.g. relative to GOPATH). TargetImportPath is NOT used by standard templates.
type GenDefinition ¶
type GenDefinition struct { GenCommon GenSchema Package string Imports map[string]string DefaultImports map[string]string ExtraSchemas GenSchemaList DependsOn []string External bool }
GenDefinition contains all the properties to generate a definition from a swagger spec
type GenDefinitions ¶ added in v0.17.0
type GenDefinitions []GenDefinition
GenDefinitions represents a list of operations to generate this implements a sort by operation id
func (GenDefinitions) Len ¶ added in v0.17.0
func (g GenDefinitions) Len() int
func (GenDefinitions) Less ¶ added in v0.17.0
func (g GenDefinitions) Less(i, j int) bool
func (GenDefinitions) Swap ¶ added in v0.17.0
func (g GenDefinitions) Swap(i, j int)
type GenHeader ¶
type GenHeader struct { Package string ReceiverName string IndexVar string ID string Name string Path string ValueExpression string Title string Description string Default interface{} HasDefault bool CollectionFormat string Child *GenItems Parent *GenItems Converter string Formatter string ZeroValue string // contains filtered or unexported fields }
GenHeader represents a header on a response for code generation
func (*GenHeader) ItemsDepth ¶ added in v0.17.0
ItemsDepth returns a string "items.items..." with as many items as the level of nesting of the array. For a header objects it always returns "".
type GenHeaders ¶
type GenHeaders []GenHeader
GenHeaders is a sorted collection of headers for codegen
func (GenHeaders) HasSomeDefaults ¶ added in v0.17.0
func (g GenHeaders) HasSomeDefaults() bool
HasSomeDefaults returns true is at least one header has a default value set
func (GenHeaders) Len ¶
func (g GenHeaders) Len() int
func (GenHeaders) Less ¶
func (g GenHeaders) Less(i, j int) bool
func (GenHeaders) Swap ¶
func (g GenHeaders) Swap(i, j int)
type GenItems ¶
type GenItems struct { Name string Path string ValueExpression string CollectionFormat string Child *GenItems Parent *GenItems Converter string Formatter string Location string IndexVar string KeyVar string // instructs generator to skip the splitting and parsing from CollectionFormat SkipParse bool // instructs generator that some nested structure needs an higher level loop index NeedsIndex bool // contains filtered or unexported fields }
GenItems represents the collection items for a collection parameter
func (*GenItems) ItemsDepth ¶ added in v0.17.0
ItemsDepth returns a string "items.items..." with as many items as the level of nesting of the array.
func (GenItems) ToString ¶ added in v0.26.0
ToString returns a string conversion expression for the item
func (GenItems) UnderlyingType ¶ added in v0.26.0
UnderlyingType tells the go type or the aliased go type
type GenOperation ¶
type GenOperation struct { GenCommon Package string ReceiverName string Name string Summary string Description string Method string Path string BasePath string Tags []string UseTags bool RootPackage string Imports map[string]string DefaultImports map[string]string ExtraSchemas GenSchemaList PackageAlias string Authorized bool Security []GenSecurityRequirements // resolved security requirements for the operation SecurityDefinitions GenSecuritySchemes SecurityRequirements []analysis.SecurityRequirement // original security requirements as per the spec (for doc) Principal string PrincipalIsNullable bool SuccessResponse *GenResponse SuccessResponses []GenResponse Responses GenStatusCodeResponses DefaultResponse *GenResponse Params GenParameters QueryParams GenParameters PathParams GenParameters HeaderParams GenParameters FormParams GenParameters HasQueryParams bool HasPathParams bool HasHeaderParams bool HasFormParams bool HasFormValueParams bool HasFileParams bool HasBodyParams bool HasStreamingResponse bool Schemes []string ExtraSchemes []string SchemeOverrides []string // original scheme overrides for operation, as per spec (for doc) ExtraSchemeOverrides []string // original extra scheme overrides for operation, as per spec (for doc) ProducesMediaTypes []string ConsumesMediaTypes []string TimeoutName string Extensions map[string]interface{} StrictResponders bool ExternalDocs *spec.ExternalDocumentation Produces []string // original produces for operation (for doc) Consumes []string // original consumes for operation (for doc) }
GenOperation represents an operation for code generation
type GenOperationGroup ¶
type GenOperationGroup struct { GenCommon Name string Operations GenOperations Summary string Description string Imports map[string]string DefaultImports map[string]string RootPackage string GenOpts *GenOpts PackageAlias string }
GenOperationGroup represents a named (tagged) group of operations
type GenOperationGroups ¶
type GenOperationGroups []GenOperationGroup
GenOperationGroups is a sorted collection of operation groups
func (GenOperationGroups) Len ¶
func (g GenOperationGroups) Len() int
func (GenOperationGroups) Less ¶
func (g GenOperationGroups) Less(i, j int) bool
func (GenOperationGroups) Swap ¶
func (g GenOperationGroups) Swap(i, j int)
type GenOperations ¶
type GenOperations []GenOperation
GenOperations represents a list of operations to generate this implements a sort by operation id
func (GenOperations) Len ¶
func (g GenOperations) Len() int
func (GenOperations) Less ¶
func (g GenOperations) Less(i, j int) bool
func (GenOperations) Swap ¶
func (g GenOperations) Swap(i, j int)
type GenOpts ¶
type GenOpts struct { IncludeModel bool IncludeValidator bool IncludeHandler bool IncludeParameters bool IncludeResponses bool IncludeURLBuilder bool IncludeMain bool IncludeSupport bool ExcludeSpec bool DumpData bool ValidateSpec bool FlattenOpts *analysis.FlattenOpts IsClient bool PropertiesSpecOrder bool StrictAdditionalProperties bool AllowTemplateOverride bool Spec string APIPackage string ModelPackage string ServerPackage string ClientPackage string Principal string PrincipalCustomIface bool // user-provided interface for Principal (non-nullable) Target string Sections SectionOpts LanguageOpts *LanguageOpts TypeMapping map[string]string Imports map[string]string DefaultScheme string DefaultProduces string DefaultConsumes string WithXML bool TemplateDir string Template string RegenerateConfigureAPI bool Operations []string Models []string Tags []string StructTags []string Name string FlagStrategy string CompatibilityMode string ExistingModels string Copyright string SkipTagPackages bool MainPackage string IgnoreOperations bool AllowEnumCI bool StrictResponders bool AcceptDefinitionsOnly bool // contains filtered or unexported fields }
GenOpts the options for the generator
func (*GenOpts) CheckOpts ¶ added in v0.18.0
CheckOpts carries out some global consistency checks on options.
func (*GenOpts) EnsureDefaults ¶ added in v0.17.0
EnsureDefaults for these gen opts
func (*GenOpts) PrincipalAlias ¶ added in v0.26.0
PrincipalAlias returns an aliased type to the principal
func (*GenOpts) PrincipalIsNullable ¶ added in v0.26.0
PrincipalIsNullable indicates whether the principal type used for authentication may be used as a pointer
func (*GenOpts) SpecPath ¶ added in v0.17.0
SpecPath returns the path to the spec relative to the server package. If the spec is remote keep this absolute location.
If spec is not relative to server (e.g. lives on a different drive on windows), then the resolved path is absolute.
This method is used by templates, e.g. with {{ .SpecPath }}
Errors cases are prevented by calling CheckOpts beforehand.
func (*GenOpts) TargetPath ¶ added in v0.17.0
TargetPath returns the target generation path relative to the server package. This method is used by templates, e.g. with {{ .TargetPath }}
Errors cases are prevented by calling CheckOpts beforehand.
Example: Target: ${PWD}/tmp ServerPackage: abc/efg
Server is generated in ${PWD}/tmp/abc/efg relative TargetPath returned: ../../../tmp
type GenParameter ¶
type GenParameter struct { ID string Name string ModelsPackage string Path string ValueExpression string IndexVar string KeyVar string ReceiverName string Location string Title string Description string Converter string Formatter string Schema *GenSchema CollectionFormat string Child *GenItems Parent *GenItems Default interface{} HasDefault bool ZeroValue string AllowEmptyValue bool // validation strategy for Body params, which may mix model and simple constructs. // Distinguish the following cases: // - HasSimpleBodyParams: body is an inline simple type // - HasModelBodyParams: body is a model objectd // - HasSimpleBodyItems: body is an inline array of simple type // - HasModelBodyItems: body is an array of model objects // - HasSimpleBodyMap: body is a map of simple objects (possibly arrays) // - HasModelBodyMap: body is a map of model objects HasSimpleBodyParams bool HasModelBodyParams bool HasSimpleBodyItems bool HasModelBodyItems bool HasSimpleBodyMap bool HasModelBodyMap bool Extensions map[string]interface{} // contains filtered or unexported fields }
GenParameter is used to represent a parameter or a header for code generation.
func (*GenParameter) IsBodyParam ¶
func (g *GenParameter) IsBodyParam() bool
IsBodyParam returns true when this parameter is a body param
func (*GenParameter) IsFileParam ¶
func (g *GenParameter) IsFileParam() bool
IsFileParam returns true when this parameter is a file param
func (*GenParameter) IsFormParam ¶
func (g *GenParameter) IsFormParam() bool
IsFormParam returns true when this parameter is a form param
func (*GenParameter) IsHeaderParam ¶
func (g *GenParameter) IsHeaderParam() bool
IsHeaderParam returns true when this parameter is a header param
func (*GenParameter) IsPathParam ¶
func (g *GenParameter) IsPathParam() bool
IsPathParam returns true when this parameter is a path param
func (*GenParameter) IsQueryParam ¶
func (g *GenParameter) IsQueryParam() bool
IsQueryParam returns true when this parameter is a query param
func (*GenParameter) ItemsDepth ¶ added in v0.17.0
func (g *GenParameter) ItemsDepth() string
ItemsDepth returns a string "items.items..." with as many items as the level of nesting of the array. For a parameter object, it always returns "".
func (GenParameter) ToString ¶ added in v0.26.0
func (g GenParameter) ToString() string
ToString returns a string conversion expression for the parameter
func (GenParameter) UnderlyingType ¶ added in v0.26.0
func (g GenParameter) UnderlyingType() string
UnderlyingType tells the go type or the aliased go type
type GenParameters ¶
type GenParameters []GenParameter
GenParameters represents a sorted parameter collection
func (GenParameters) HasSomeDefaults ¶ added in v0.17.0
func (g GenParameters) HasSomeDefaults() bool
HasSomeDefaults returns true is at least one parameter has a default value set
func (GenParameters) Len ¶
func (g GenParameters) Len() int
func (GenParameters) Less ¶
func (g GenParameters) Less(i, j int) bool
func (GenParameters) Swap ¶
func (g GenParameters) Swap(i, j int)
type GenResponse ¶
type GenResponse struct { Package string ModelsPackage string ReceiverName string Name string Description string IsSuccess bool Code int Method string Path string Headers GenHeaders Schema *GenSchema AllowsForStreaming bool Imports map[string]string DefaultImports map[string]string Extensions map[string]interface{} StrictResponders bool OperationName string Examples GenResponseExamples }
GenResponse represents a response object for code generation
type GenResponseExample ¶ added in v0.26.0
type GenResponseExample struct { MediaType string Example interface{} }
GenResponseExample captures an example provided for a response for some mime type
type GenResponseExamples ¶ added in v0.26.0
type GenResponseExamples []GenResponseExample
GenResponseExamples is a sortable collection []GenResponseExample
func (GenResponseExamples) Len ¶ added in v0.26.0
func (g GenResponseExamples) Len() int
func (GenResponseExamples) Less ¶ added in v0.26.0
func (g GenResponseExamples) Less(i, j int) bool
func (GenResponseExamples) Swap ¶ added in v0.26.0
func (g GenResponseExamples) Swap(i, j int)
type GenSchema ¶
type GenSchema struct { Example string OriginalName string Name string Suffix string Path string ValueExpression string IndexVar string KeyVar string Title string Description string Location string ReceiverName string Items *GenSchema AllowsAdditionalItems bool HasAdditionalItems bool AdditionalItems *GenSchema Object *GenSchema XMLName string CustomTag string Properties GenSchemaList AllOf GenSchemaList HasAdditionalProperties bool IsAdditionalProperties bool AdditionalProperties *GenSchema StrictAdditionalProperties bool ReadOnly bool IsVirtual bool IsBaseType bool HasBaseType bool IsSubType bool IsExported bool DiscriminatorField string DiscriminatorValue string Discriminates map[string]string Parents []string IncludeValidator bool IncludeModel bool Default interface{} WantsMarshalBinary bool // do we generate MarshalBinary interface? StructTags []string ExtraImports map[string]string // non-standard imports detected when using external types ExternalDocs *spec.ExternalDocumentation // contains filtered or unexported fields }
GenSchema contains all the information needed to generate the code for a schema
func (GenSchema) PrintTags ¶ added in v0.26.0
PrintTags takes care of rendering tags for a struct field
func (GenSchema) ToString ¶ added in v0.26.0
ToString returns a string conversion expression for the schema
func (GenSchema) UnderlyingType ¶ added in v0.26.0
UnderlyingType tells the go type or the aliased go type
type GenSchemaList ¶
type GenSchemaList []GenSchema
GenSchemaList is a list of schemas for generation.
It can be sorted by name to get a stable struct layout for version control and such
func (GenSchemaList) Len ¶
func (g GenSchemaList) Len() int
func (GenSchemaList) Less ¶
func (g GenSchemaList) Less(i, j int) bool
func (GenSchemaList) Swap ¶
func (g GenSchemaList) Swap(i, j int)
type GenSecurityRequirement ¶ added in v0.17.0
GenSecurityRequirement represents a security requirement for an operation
type GenSecurityRequirements ¶ added in v0.17.0
type GenSecurityRequirements []GenSecurityRequirement
GenSecurityRequirements represents a compounded security requirement specification. In a []GenSecurityRequirements complete requirements specification, outer elements are interpreted as optional requirements (OR), and inner elements are interpreted as jointly required (AND).
func (GenSecurityRequirements) Len ¶ added in v0.17.0
func (g GenSecurityRequirements) Len() int
func (GenSecurityRequirements) Less ¶ added in v0.17.0
func (g GenSecurityRequirements) Less(i, j int) bool
func (GenSecurityRequirements) Swap ¶ added in v0.17.0
func (g GenSecurityRequirements) Swap(i, j int)
type GenSecurityScheme ¶
type GenSecurityScheme struct { AppName string ID string Name string ReceiverName string IsBasicAuth bool IsAPIKeyAuth bool IsOAuth2 bool Scopes []string Source string Principal string PrincipalIsNullable bool // from spec.SecurityScheme Description string Type string In string Flow string AuthorizationURL string TokenURL string Extensions map[string]interface{} ScopesDesc []GenSecurityScope }
GenSecurityScheme represents a security scheme for code generation
type GenSecuritySchemes ¶ added in v0.17.0
type GenSecuritySchemes []GenSecurityScheme
GenSecuritySchemes sorted representation of serializers
func (GenSecuritySchemes) Len ¶ added in v0.17.0
func (g GenSecuritySchemes) Len() int
func (GenSecuritySchemes) Less ¶ added in v0.17.0
func (g GenSecuritySchemes) Less(i, j int) bool
func (GenSecuritySchemes) Swap ¶ added in v0.17.0
func (g GenSecuritySchemes) Swap(i, j int)
type GenSecurityScope ¶ added in v0.26.0
GenSecurityScope represents a scope descriptor for an OAuth2 security scheme
type GenSerGroup ¶
type GenSerGroup struct { GenSerializer // All media types for this serializer. The redundant representation allows for easier use in templates AllSerializers GenSerializers }
GenSerGroup represents a group of serializers: this links a serializer to a list of prioritized media types (mime).
type GenSerGroups ¶ added in v0.17.0
type GenSerGroups []GenSerGroup
GenSerGroups sorted representation of serializer groups
func (GenSerGroups) Len ¶ added in v0.17.0
func (g GenSerGroups) Len() int
func (GenSerGroups) Less ¶ added in v0.17.0
func (g GenSerGroups) Less(i, j int) bool
func (GenSerGroups) Swap ¶ added in v0.17.0
func (g GenSerGroups) Swap(i, j int)
type GenSerializer ¶
type GenSerializer struct { AppName string // Application name ReceiverName string Name string // Name of the Producer/Consumer (e.g. json, yaml, txt, bin) MediaType string // mime Implementation string // func implementing the Producer/Consumer Parameters []string // parameters supported by this serializer }
GenSerializer represents a single serializer for a particular media type
type GenSerializers ¶ added in v0.17.0
type GenSerializers []GenSerializer
GenSerializers sorted representation of serializers
func (GenSerializers) Len ¶ added in v0.17.0
func (g GenSerializers) Len() int
func (GenSerializers) Less ¶ added in v0.17.0
func (g GenSerializers) Less(i, j int) bool
func (GenSerializers) Swap ¶ added in v0.17.0
func (g GenSerializers) Swap(i, j int)
type GenStatusCodeResponses ¶ added in v0.17.0
type GenStatusCodeResponses []GenResponse
GenStatusCodeResponses a container for status code responses
func (GenStatusCodeResponses) Len ¶ added in v0.17.0
func (g GenStatusCodeResponses) Len() int
func (GenStatusCodeResponses) Less ¶ added in v0.17.0
func (g GenStatusCodeResponses) Less(i, j int) bool
func (GenStatusCodeResponses) MarshalJSON ¶ added in v0.17.0
func (g GenStatusCodeResponses) MarshalJSON() ([]byte, error)
MarshalJSON marshals these responses to json
This is used by DumpData.
func (GenStatusCodeResponses) Swap ¶ added in v0.17.0
func (g GenStatusCodeResponses) Swap(i, j int)
func (*GenStatusCodeResponses) UnmarshalJSON ¶ added in v0.17.0
func (g *GenStatusCodeResponses) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals this GenStatusCodeResponses from json
type LanguageConfig ¶ added in v0.17.0
type LanguageConfig map[string]LanguageDefinition
LanguageConfig structure that is obtained from parsing a config file
type LanguageDefinition ¶ added in v0.17.0
type LanguageDefinition struct {
Layout SectionOpts `mapstructure:"layout"`
}
LanguageDefinition in the configuration file.
func (*LanguageDefinition) ConfigureOpts ¶ added in v0.17.0
func (d *LanguageDefinition) ConfigureOpts(opts *GenOpts) error
ConfigureOpts for generation
type LanguageOpts ¶ added in v0.17.0
type LanguageOpts struct { ReservedWords []string BaseImportFunc func(string) string `json:"-"` ImportsFunc func(map[string]string) string `json:"-"` ArrayInitializerFunc func(interface{}) (string, error) `json:"-"` // contains filtered or unexported fields }
LanguageOpts to describe a language to the code generator
func GoLangOpts ¶ added in v0.17.0
func GoLangOpts() *LanguageOpts
GoLangOpts for rendering items as golang code
func MarkdownOpts ¶ added in v0.26.0
func MarkdownOpts() *LanguageOpts
MarkdownOpts for rendering a spec as markdown
func (*LanguageOpts) FormatContent ¶ added in v0.17.0
func (l *LanguageOpts) FormatContent(name string, content []byte) ([]byte, error)
FormatContent formats a file with a language specific formatter
func (*LanguageOpts) MangleFileName ¶ added in v0.17.0
func (l *LanguageOpts) MangleFileName(name string) string
MangleFileName makes sure a file name gets a safe name
func (*LanguageOpts) MangleName ¶ added in v0.17.0
func (l *LanguageOpts) MangleName(name, suffix string) string
MangleName makes sure a reserved word gets a safe name
func (*LanguageOpts) ManglePackageName ¶ added in v0.18.0
func (l *LanguageOpts) ManglePackageName(name, suffix string) string
ManglePackageName makes sure a package gets a safe name. In case of a file system path (e.g. name contains "/" or "\" on Windows), this return only the last element.
func (*LanguageOpts) ManglePackagePath ¶ added in v0.18.0
func (l *LanguageOpts) ManglePackagePath(name string, suffix string) string
ManglePackagePath makes sure a full package path gets a safe name. Only the last part of the path is altered.
func (*LanguageOpts) MangleVarName ¶ added in v0.17.0
func (l *LanguageOpts) MangleVarName(name string) string
MangleVarName makes sure a reserved word gets a safe name
type Repository ¶ added in v0.17.0
type Repository struct {
// contains filtered or unexported fields
}
Repository is the repository for the generator templates
func NewRepository ¶ added in v0.17.0
func NewRepository(funcs template.FuncMap) *Repository
NewRepository creates a new template repository with the provided functions defined
func (*Repository) AddFile ¶ added in v0.17.0
func (t *Repository) AddFile(name, data string) error
AddFile adds a file to the repository. It will create a new template based on the filename. It trims the .gotmpl from the end and converts the name using swag.ToJSONName. This will strip directory separators and Camelcase the next letter. e.g validation/primitive.gotmpl will become validationPrimitive
If the file contains a definition for a template that is protected the whole file will not be added
func (*Repository) DumpTemplates ¶ added in v0.17.0
func (t *Repository) DumpTemplates()
DumpTemplates prints out a dump of all the defined templates, where they are defined and what their dependencies are.
func (*Repository) Get ¶ added in v0.17.0
func (t *Repository) Get(name string) (*template.Template, error)
Get will return the named template from the repository, ensuring that all dependent templates are loaded. It will return an error if a dependent template is not defined in the repository.
func (*Repository) LoadContrib ¶ added in v0.17.0
func (t *Repository) LoadContrib(name string) error
LoadContrib loads template from contrib directory
func (*Repository) LoadDefaults ¶ added in v0.17.0
func (t *Repository) LoadDefaults()
LoadDefaults will load the embedded templates
func (*Repository) LoadDir ¶ added in v0.17.0
func (t *Repository) LoadDir(templatePath string) error
LoadDir will walk the specified path and add each .gotmpl file it finds to the repository
func (*Repository) MustGet ¶ added in v0.17.0
func (t *Repository) MustGet(name string) *template.Template
MustGet a template by name, panics when fails
func (*Repository) SetAllowOverride ¶ added in v0.26.0
func (t *Repository) SetAllowOverride(value bool)
SetAllowOverride allows setting allowOverride after the Repository was initialized
func (*Repository) ShallowClone ¶ added in v0.26.0
func (t *Repository) ShallowClone() *Repository
ShallowClone a repository.
Clones the maps of files and templates, so as to be able to use the cloned repo concurrently.
type SectionOpts ¶ added in v0.17.0
type SectionOpts struct { Application []TemplateOpts `mapstructure:"application"` Operations []TemplateOpts `mapstructure:"operations"` OperationGroups []TemplateOpts `mapstructure:"operation_groups"` Models []TemplateOpts `mapstructure:"models"` }
SectionOpts allows for specifying options to customize the templates used for generation
type TemplateOpts ¶ added in v0.17.0
type TemplateOpts struct { Name string `mapstructure:"name"` Source string `mapstructure:"source"` Target string `mapstructure:"target"` FileName string `mapstructure:"file_name"` SkipExists bool `mapstructure:"skip_exists"` SkipFormat bool `mapstructure:"skip_format"` }
TemplateOpts allows for codegen customization