Documentation
¶
Index ¶
- Variables
- func FilesListedInMetadata(outputDir string) []string
- func GenerateFiles(templateId string, outputDir string, templateData DocumentModel, ...) (map[string]templateapi.RenderedFile, error)
- func HaveSameCodeTypeName(codeTypes []CodeType) bool
- func IsBinaryAvailable(binary string) bool
- func RemoveGeneratedFile(outputDir string, file string) error
- func WriteMetadata(outputDir string, files map[string]templateapi.RenderedFile) error
- type APIEachTemplate
- type APIOnceTemplate
- type Auth
- type AuthMethod
- type CodeGenerator
- type CodeType
- type CodeTypeSchemaType
- type CommonPackages
- type DocumentModel
- type Documentation
- type Endpoint
- type Endpoints
- type Enum
- type EnumEachTemplate
- type GenerateOpts
- type GlobalTemplate
- type Metadata
- type Model
- type ModelEachTemplate
- type ModelOpts
- type ModelsOnceTemplate
- type Operation
- type OperationEachTemplate
- type OperationOpts
- type OperationsOnceTemplate
- type Parameter
- type PathSegment
- type Property
- type SchemaDefinition
- type Service
- type SupportOnceTemplate
- type Tag
- type TemplateDataOpts
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultCodeGenerationPatches = []string{"fix-operation-tags", "generate-operation-id", "flatten-components", "simplify-polymorphic-schemas", "fix-missing-schema-title"}
View Source
var DefaultCodeType = CodeType{}
View Source
var (
ErrFailedToWriteMetadata = errors.New("failed to write metadata")
)
View Source
var VoidCodeType = CodeType{IsVoid: true}
Functions ¶
func FilesListedInMetadata ¶
func GenerateFiles ¶
func GenerateFiles(templateId string, outputDir string, templateData DocumentModel, renderOpts templateapi.RenderOpts, generatorOpts GenerateOpts) (map[string]templateapi.RenderedFile, error)
func HaveSameCodeTypeName ¶
func IsBinaryAvailable ¶
func RemoveGeneratedFile ¶
func WriteMetadata ¶
func WriteMetadata(outputDir string, files map[string]templateapi.RenderedFile) error
WriteMetadata generates metadata about the generated files for the output directory
Types ¶
type APIEachTemplate ¶
type APIEachTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
Package string
Service Service
}
type APIOnceTemplate ¶
type APIOnceTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
Package string
}
type Auth ¶
type Auth struct {
Methods []AuthMethod
}
func BuildAuth ¶
func BuildAuth(doc *libopenapi.DocumentModel[v3.Document]) (auth Auth)
func (Auth) HasAuthMethod ¶
func (Auth) HasAuthScheme ¶
func (Auth) HasAuthType ¶
func (Auth) HasAuthVariant ¶
type AuthMethod ¶
type AuthMethod struct {
Name string
Description string
Type string // Type of the auth method, e.g. "apiKey", "http", "oauth2"
Variant string // Variant of the auth method, e.g. "apiKey-header", "apiKey-query", "oauth-client-credentials", "oauth-password-credentials"
Scheme string
HeaderParam string // HeaderParam is the name of the header parameter, if applicable
QueryParam string // QueryParam is the name of the query parameter, if applicable
TokenUrl string // TokenUrl is the URL to the token endpoint, if applicable
}
type CodeGenerator ¶
type CodeGenerator interface {
// Id returns a unique id for this generator
Id() string
// Description returns a human-readable description of the generator
Description() string
// Generate generates code
Generate(opts GenerateOpts) error
// TemplateData processes a openapi document and returns a data model to be used in the templates
TemplateData(opts TemplateDataOpts) (DocumentModel, error)
// ToClassName converts a name to a language-specific class name
ToClassName(name string) string
// ToFunctionName converts a name to a language-specific function name
ToFunctionName(name string) string
// ToPropertyName converts a name to a language-specific property name
ToPropertyName(name string) string
// ToParameterName converts a name to a language-specific parameter name
ToParameterName(name string) string
// ToConstantName converts a name to a language-specific constant name
ToConstantName(name string) string
// ToCodeType converts a schema to a language-specific type
ToCodeType(schema *base.Schema, schemaType CodeTypeSchemaType, required bool) (CodeType, error)
// PostProcessType is used for post-processing a type (e.g. void type if the type is empty)
PostProcessType(codeType CodeType) CodeType
// IsPrimitiveType checks if a type is a primitive type
IsPrimitiveType(input string) bool
// TypeToImport returns the import path for a given type
TypeToImport(typeName CodeType) string
}
CodeGenerator is the interface that all code generators must implement
func GeneratorById ¶
func GeneratorById(id string, allGenerators []CodeGenerator) (CodeGenerator, error)
type CodeType ¶
type CodeType struct {
Name string // Name of the type
Declaration string // Declaration of the type
QualifiedDeclaration string // Qualified declaration of the type (with package name, pointer, optional, etc.)
Type string // Type of the type
QualifiedType string // Qualified type of the type (with package name)
TypeArgs []CodeType
IsArray bool
IsList bool
IsMap bool
IsNullable bool
IsPointer bool
IsVoid bool
IsPostProcessed bool
ImportPath string
}
func NewMapCodeType ¶
type CodeTypeSchemaType ¶
type CodeTypeSchemaType string
const ( CodeTypeSchemaParameter CodeTypeSchemaType = "parameter" CodeTypeSchemaProperty CodeTypeSchemaType = "property" CodeTypeSchemaArray CodeTypeSchemaType = "array" CodeTypeSchemaResponse CodeTypeSchemaType = "response" CodeTypeSchemaParent CodeTypeSchemaType = "parent" )
type CommonPackages ¶
type DocumentModel ¶
type DocumentModel struct {
Name string
DisplayName string
Description string
Tags map[string]Tag
Endpoints Endpoints
Auth Auth
Services map[string]Service
Operations []Operation
OperationsByTag map[string][]Operation
Models []Model
Enums []Enum
Packages CommonPackages // Packages holds the import paths for output packages
}
func BuildTemplateData ¶
func BuildTemplateData(doc *libopenapi.DocumentModel[v3.Document], generator CodeGenerator, packageConfig CommonPackages) (DocumentModel, error)
func PruneTypeAliases ¶
func PruneTypeAliases(documentModel DocumentModel, primitiveTypes []string) DocumentModel
PruneTypeAliases removes type aliases and replaces it with the actual type A type alias is identified by not having properties and the parent being a primitive type
type Documentation ¶
type Endpoints ¶
type Endpoints []Endpoint
func BuildEndpoints ¶
func BuildEndpoints(doc *libopenapi.DocumentModel[v3.Document]) Endpoints
func (Endpoints) DefaultEndpoint ¶
func (Endpoints) HasEndpointWithType ¶
type Enum ¶
type Enum struct {
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
Parent CodeType `yaml:"parent,omitempty"`
ValueType CodeType `yaml:"valueType,omitempty"`
AllowedValues map[string]openapidocument.AllowedValue `yaml:"allowedValues,omitempty"`
Imports []string `yaml:"imports,omitempty"`
Deprecated bool `yaml:"deprecated,omitempty"`
DeprecatedReason string `yaml:"deprecatedReason,omitempty"`
}
func BuildEnums ¶
type EnumEachTemplate ¶
type EnumEachTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
Package string
Name string
Enum Enum
}
type GenerateOpts ¶
type GenerateOpts struct {
DryRun bool
Doc *libopenapi.DocumentModel[v3.Document]
OutputDir string
TemplateId string
PackageConfig CommonPackages
ArtifactGroupId string
ArtifactId string
RepositoryUrl string
LicenseName string
LicenseUrl string
Provider appconf.ProviderConf
GeneratorNames []string
GeneratorOutputs []string
}
type GlobalTemplate ¶
type GlobalTemplate struct {
GeneratorProperties map[string]string
Endpoints Endpoints
Auth Auth
Packages CommonPackages
Services map[string]Service
Operations []Operation
Models []Model
Enums []Enum
}
func (GlobalTemplate) HasParametersWithType ¶
func (g GlobalTemplate) HasParametersWithType(paramType string) bool
type Metadata ¶
type Metadata struct {
ArtifactGroupId string
ArtifactId string
Name string
DisplayName string
Description string
RepositoryUrl string // RepositoryUrl is the URL to the repository (without protocol or .git suffix)
LicenseName string // LicenseName is the name of the license (MIT, Apache-2.0, etc.)
LicenseUrl string // LicenseUrl is the URL to the license
GeneratorNames []string // GeneratorNames is a list of all active generators
GeneratorOutputs []string // GeneratorOutputs is a list of all output directories for the active generators
}
func (Metadata) IsPublicLibrary ¶
IsPublicLibrary returns true if the repository URL indicates a public version control hosting service
type Model ¶
type Model struct {
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
Parent CodeType `yaml:"parent,omitempty"`
Properties []Property `yaml:"properties,omitempty"`
AnyOf []Model `yaml:"anyOf,omitempty"`
AllOf []Model `yaml:"allOf,omitempty"`
OneOf []Model `yaml:"oneOf,omitempty"`
Imports []string `yaml:"imports,omitempty"`
Deprecated bool `yaml:"deprecated,omitempty"`
DeprecatedReason string `yaml:"deprecatedReason,omitempty"`
IsTypeAlias bool `yaml:"isTypeAlias,omitempty"`
}
func BuildComponentModels ¶
type ModelEachTemplate ¶
type ModelEachTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
Package string
Name string
Model Model
}
type ModelOpts ¶
type ModelOpts struct {
Generator CodeGenerator
Doc *libopenapi.DocumentModel[v3.Document]
PackageConfig CommonPackages
}
type ModelsOnceTemplate ¶
type ModelsOnceTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
Models []Model
}
type Operation ¶
type Operation struct {
Name string `yaml:"name,omitempty"`
Path string `yaml:"path"`
PathSegments []PathSegment `yaml:"pathSegments,omitempty"`
Method string `yaml:"method"`
Summary string `yaml:"summary,omitempty"` // Short description
Description string `yaml:"description,omitempty"` // Long description
Tag string `yaml:"tag,omitempty"`
Tags []string `yaml:"tags,omitempty"`
ReturnType CodeType `yaml:"returnType,omitempty"`
Deprecated bool `yaml:"deprecated,omitempty"`
DeprecatedReason string `yaml:"deprecatedReason,omitempty"`
Parameters []Parameter `yaml:"parameters,omitempty"` // Parameters holds all parameters, including static ones that can not be overridden
MutableParameters []Parameter `yaml:"mutableParameters,omitempty"` // MutableParameters can be supplied by the user
ImmutableParameters []Parameter `yaml:"immutableParameters,omitempty"` // ImmutableParameters can not be overridden by the user
PathParameters []Parameter `yaml:"pathParameters,omitempty"`
MutablePathParameters []Parameter `yaml:"mutablePathParameters,omitempty"`
ImmutablePathParameters []Parameter `yaml:"immutablePathParameters,omitempty"`
QueryParameters []Parameter `yaml:"queryParameters,omitempty"`
MutableQueryParameters []Parameter `yaml:"mutableQueryParameters,omitempty"`
ImmutableQueryParameters []Parameter `yaml:"immutableQueryParameters,omitempty"`
HeaderParameters []Parameter `yaml:"headerParameters,omitempty"`
MutableHeaderParameter []Parameter `yaml:"mutableHeaderParameter,omitempty"`
ImmutableHeaderParameter []Parameter `yaml:"immutableHeaderParameter,omitempty"`
CookieParameters []Parameter `yaml:"cookieParameters,omitempty"`
MutableCookieParameter []Parameter `yaml:"mutableCookieParameter,omitempty"`
ImmutableCookieParameter []Parameter `yaml:"immutableCookieParameter,omitempty"`
BodyParameter *Parameter `yaml:"bodyParameter,omitempty"`
Imports []string `yaml:"imports,omitempty"`
Documentation []Documentation `yaml:"documentation,omitempty"`
Stability string `yaml:"stability,omitempty"`
Extensions *orderedmap.Map[string, *yaml.Node] `yaml:"extensions,omitempty"` // Extensions are custom extensions to the operation
}
func BuildOperations ¶
func BuildOperations(opts OperationOpts) ([]Operation, error)
func (*Operation) AddParameter ¶
func (*Operation) HasParametersWithType ¶
type OperationEachTemplate ¶
type OperationEachTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
Package string
Name string
Operation Operation
}
type OperationOpts ¶
type OperationOpts struct {
Generator CodeGenerator
Doc *libopenapi.DocumentModel[v3.Document]
PackageConfig CommonPackages
}
type OperationsOnceTemplate ¶
type OperationsOnceTemplate struct {
Metadata Metadata // Metadata for the template, like artifact group and ID
Common GlobalTemplate
}
type Parameter ¶
type Parameter struct {
Name string `yaml:"name,omitempty"`
FieldName string `yaml:"fieldName,omitempty"` // FieldName is the original name of the parameter
In string `yaml:"in,omitempty"`
Description string `yaml:"description,omitempty"`
Type CodeType `yaml:"type,omitempty"`
IsPrimitiveType bool `yaml:"isPrimitiveType,omitempty"`
IsImmutable bool `yaml:"isImmutable,omitempty"`
Required bool `yaml:"required,omitempty"`
AllowedValues map[string]openapidocument.AllowedValue `yaml:"allowedValues,omitempty"`
StaticValue string `yaml:"staticValue,omitempty"`
Deprecated bool `yaml:"deprecated,omitempty"`
DeprecatedReason string `yaml:"deprecatedReason,omitempty"`
Stability string `yaml:"stability,omitempty"`
}
type PathSegment ¶
func BuildPathSegments ¶
func BuildPathSegments(path string, pathParameters []Parameter) []PathSegment
type Property ¶
type Property struct {
Name string `yaml:"name" required:"true"` // Name is the parameter name
FieldName string `yaml:"fieldName,omitempty"` // FieldName is the original name of the parameter
Title string `yaml:"title,omitempty"` // Title is the human-readable name of the parameter
Description string `yaml:"description,omitempty"` // Description is the human-readable description of the parameter
Type CodeType `yaml:"type,omitempty"`
IsPrimitiveType bool `yaml:"isPrimitiveType,omitempty"`
Nullable bool `yaml:"nullable,omitempty"`
AllowedValues map[string]openapidocument.AllowedValue `yaml:"allowedValues,omitempty"`
Items []Property `yaml:"items,omitempty"`
}
type SchemaDefinition ¶
type Service ¶
type Service struct {
Name string `yaml:"name"`
Type string `yaml:"type,omitempty"` // Type returns the CodeType used for the service
Description string `yaml:"description,omitempty"`
Operations []Operation
Documentation []Documentation `yaml:"documentation,omitempty"`
}
Service represents a named collection of operations
type SupportOnceTemplate ¶
type SupportOnceTemplate struct {
Metadata Metadata // Metadata for the template, e.g. artifact group, ID, etc.
Provider appconf.ProviderConf // Provider contains information about the product or company providing the API
Common GlobalTemplate // Common template data, e.g. API name, project name, etc.
}
type TemplateDataOpts ¶
type TemplateDataOpts struct {
Doc *libopenapi.DocumentModel[v3.Document]
PackageConfig CommonPackages
}
Click to show internal directories.
Click to hide internal directories.