Documentation ¶
Index ¶
Constants ¶
View Source
const DefaultPackageName = "openapi"
DefaultPackageName used in the models source code
View Source
const ExtensionPatternError = "x-pattern-error"
ExtensionPatternError is an extension property that, if set, allows the API author to control the error message for pattern validation failures.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConvertSpec ¶
type ConvertSpec struct { // TargetGoType is the target type of the conversion TargetGoType string }
ConvertSpec holds all info to build one As{Type}() function
type Discriminator ¶
type Generator ¶
type Generator interface { // Generate generates and writes model files that can be generated out of the given spec. Generate(ctx context.Context) error }
Generator defines generator operations needed for generating Go code for the spec
type Model ¶
type Model struct { // Name is a name of the generated type that follows the `type` keyword in the definition // For example, `type Name GoType`. Name string // Description is a description that will become a comment on the generated type Description string // Imports is a list of imports that will be present in the Go file Imports []string // Kind is a kind of generated model (e.g. `struct` or `enum`) Kind ModelKind // Properties is a list of type's property descriptors Properties []PropSpec // ConvertSpecs contains a list of convert functions for this model ConvertSpecs []ConvertSpec // Discriminator contains the optional oneOf discriminator Discriminator Discriminator // GoType is a string that represents the Go type that follows the model type name. // For example, `type Name GoType`. GoType string // SpecTitle is the spec title used in the auto-generated header SpecTitle string // SpecVersion is the spec version used in the auto-generated header SpecVersion string // PackageName is the name of the package used in the Go code PackageName string }
Model is a template model for rendering Go code for a given API schema
func NewModelFromParameters ¶
func NewModelFromParameters(params openapi3.Parameters) (model *Model, err error)
NewModelFromParameters returns a model built from operation parameters
func NewModelFromRef ¶
NewModelFromRef creates a model out of a schema
type Options ¶
type Options struct { // PackageName of the generated models source code (`DefaultPackageName` by default) PackageName string // Destination is a path to a folder where create all the Go files Destination string // Logger instance to use for messaging Logger zerolog.Logger }
Options represent all the possible options of the generator
type PropSpec ¶
type PropSpec struct { // Name is a property name in structs, variable name in enums, etc Name string // Description used in the comment of the property Description string // GoType used for this property (e.g. `string`, `int`, etc) GoType string // JSONTags is a string of JSON tags used for marshaling (e.g. `json:omitempty`) JSONTags string // Value is a value used for a enum item Value string // IsRequired is true when the property is a required value and should not be omitted on marshaling IsRequired bool // IsEnum is true when the property is a enum item IsEnum bool // Validation stuff Pattern string PatternErrorMsg string IsNullable bool NeedsValidation bool IsRequiredInValidation bool HasMin, HasMax bool Min, Max float64 HasMinLength, HasMaxLength bool MinLength, MaxLength uint64 HasFormat bool IsDate bool IsDateTime bool IsBase64 bool IsEmail bool IsUUID bool IsURL bool IsURI bool IsRequestURI bool IsHostname bool IsIP bool IsIPv4 bool IsIPv6 bool }
PropSpec is a Go property descriptor
Click to show internal directories.
Click to hide internal directories.