Documentation ¶
Index ¶
- func ContainsInterface(slice []any, s any) bool
- func ContainsSchemaRef(slice openapi3.SchemaRefs, ref *openapi3.SchemaRef) bool
- func ContainsString(slice []string, value string) bool
- func CreateComponentFromDefinition(ctx *GeneratorContext, componentId *gentypes.ComponentReference, ...) (*gentypes.ComponentDefinition, error)
- func CreateComponentFromReference(ctx *GeneratorContext, componentId *gentypes.ComponentReference, ...) (*gentypes.ComponentDefinition, error)
- func CreateMappingTable(ctx *GeneratorContext, componentId *gentypes.ComponentReference, ...) map[string]gentypes.ComponentReference
- func ExtendSchema(ctx *GeneratorContext, target openapi3.Schema, extending *openapi3.Schema, ...) (*openapi3.Schema, error)
- func FSysFileToBytes(f fs.FS, fqPath string) ([]byte, error)
- func HandleArray(ctx *GeneratorContext, arrayId *gentypes.ComponentReference, ...) (*gentypes.ComponentDefinition, error)
- func HandleComposition(ctx *GeneratorContext, td *gentypes.TypeDefinition, ...) error
- func HandleDiscriminatorBasedPolymorphism(ctx *GeneratorContext, td *gentypes.TypeDefinition, ...) error
- func HandleProperties(ctx *GeneratorContext, td *gentypes.TypeDefinition, ...) error
- func IsDefinition(ref *openapi3.SchemaRef) bool
- func IsReference(ref *openapi3.SchemaRef) bool
- func IsSpecificationRooted(ctx *GeneratorContext, path string) bool
- func Is_A_SpecificationRef(ctx *GeneratorContext, ref *gentypes.ComponentReference) bool
- func MergeSchemaObjects(ctx *GeneratorContext, to *openapi3.Schema, from *openapi3.Schema) (*openapi3.Schema, error)
- func MergeStrings(to, from string) string
- func ProcessSpecification(ctx *GeneratorContext, schemas map[string]*openapi3.SchemaRef) error
- func RemoveSchemaRef(references openapi3.SchemaRefs, ref *openapi3.SchemaRef) openapi3.SchemaRefs
- func ResolveGoPackage(ctx *GeneratorContext, ref *gentypes.ComponentReference) string
- func ResolveReferenceAndSwitchIfNeeded(ctx *GeneratorContext, componentId *gentypes.ComponentReference, ...) *gentypes.ComponentReference
- func ScanDir(f fs.FS, directory string, globExpr string, cb ScanDirCallback) error
- type ExtendConfig
- type Generator
- type GeneratorContext
- type Include
- type OpenAPIModule
- type ScanDirCallback
- type Settings
- func (sett *Settings) Include(inclusion ...string) *Settings
- func (sett *Settings) ToGenerator() *Generator
- func (sett *Settings) UseLoader(loader *openapi3.Loader) *Settings
- func (sett *Settings) UseModelPath(models, model_package string) *Settings
- func (sett *Settings) UseOutputPath(output string) *Settings
- func (sett *Settings) UseSpec(spec, spec_package string) *Settings
- type Templates
- type WellKnownTemplates
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsInterface ¶
func ContainsSchemaRef ¶
func ContainsSchemaRef(slice openapi3.SchemaRefs, ref *openapi3.SchemaRef) bool
func ContainsString ¶
ContainsString will check if a string is in a slice of strings.
func CreateComponentFromDefinition ¶
func CreateComponentFromDefinition( ctx *GeneratorContext, componentId *gentypes.ComponentReference, def *openapi3.Schema) (*gentypes.ComponentDefinition, error)
func CreateComponentFromReference ¶
func CreateComponentFromReference( ctx *GeneratorContext, componentId *gentypes.ComponentReference, ref *openapi3.SchemaRef) (*gentypes.ComponentDefinition, error)
CreateComponentFromReference will create the `ComponentDefinition` and return it. If there are sub-components such as references or `allOf`, `oneOf` or `anyOf` they will be created as well.
The types and components will be registered in the resolver so no duplicates will be created.
func CreateMappingTable ¶
func CreateMappingTable( ctx *GeneratorContext, componentId *gentypes.ComponentReference, schema *openapi3.Schema) map[string]gentypes.ComponentReference
CreateMappingTable makes sure that a complete mapping table is returned, it will fill in the entries that have not been defined in the mapping table. It does so by using the type name of the component as key and the reference as value.
The _componentId_ is the component that the mapping table is created for (and the _schema_ represents).
NOTE: Some entries may have a namespace since referenced in same module (file).
Entries that have been added will be resolved so they too have a `ComponentReference` and not just a `SchemaRef`.
func ExtendSchema ¶
func ExtendSchema( ctx *GeneratorContext, target openapi3.Schema, extending *openapi3.Schema, config *ExtendConfig) (*openapi3.Schema, error)
ExtendSchema will extend the _target_ schema with the _extending_ and the _target_ schema is returned.
CAUTION: This will not take into account that the _extending_ schema type is not set. If set, it will make sure that it matches the _target_ schema type.
Extend Support:
* Description * ExternalDocs * Example * Enum * Extensions * Default * Pattern (note it will not affect the `openapi3.Schema.compiledPattern` !!!)
func FSysFileToBytes ¶
FSysFileToBytes reads a file from as _fqPath_ and return the contents of it.
If it fails, it will return an error.
func HandleArray ¶
func HandleArray(ctx *GeneratorContext, arrayId *gentypes.ComponentReference, items *openapi3.SchemaRef) (*gentypes.ComponentDefinition, error)
func HandleComposition ¶
func HandleComposition( ctx *GeneratorContext, td *gentypes.TypeDefinition, component *gentypes.ComponentDefinition, def *openapi3.Schema) error
func HandleDiscriminatorBasedPolymorphism ¶
func HandleDiscriminatorBasedPolymorphism( ctx *GeneratorContext, td *gentypes.TypeDefinition, componentId *gentypes.ComponentReference, def *openapi3.Schema) error
HandleDiscriminatorBasedPolymorphism will handle when a discriminator and mapping is provided to determine what type to use. The is the _oneOf_ schema element.
CAUTION: It will not support polymorphism with properties, allOf or anyOf. Also when inline type it will also fail - just externalize in same file and it will be ok.
func HandleProperties ¶
func HandleProperties( ctx *GeneratorContext, td *gentypes.TypeDefinition, component *gentypes.ComponentDefinition, def *openapi3.Schema) error
func IsDefinition ¶
IsDefinition checks if the _ref_ is a definition or a reference.
func IsReference ¶
IsReference check if the _ref_ is a reference or a definition.
func IsSpecificationRooted ¶
func IsSpecificationRooted(ctx *GeneratorContext, path string) bool
func Is_A_SpecificationRef ¶
func Is_A_SpecificationRef(ctx *GeneratorContext, ref *gentypes.ComponentReference) bool
func MergeSchemaObjects ¶
func MergeSchemaObjects(ctx *GeneratorContext, to *openapi3.Schema, from *openapi3.Schema) (*openapi3.Schema, error)
MergeSchemaObjects will merge two schema of type object into one schema.
CAUTION: It will not merge a object schema with a non-object schema.
func MergeStrings ¶
func ProcessSpecification ¶
func ProcessSpecification(ctx *GeneratorContext, schemas map[string]*openapi3.SchemaRef) error
func RemoveSchemaRef ¶
func RemoveSchemaRef(references openapi3.SchemaRefs, ref *openapi3.SchemaRef) openapi3.SchemaRefs
RemoveSchemaRef will remove a _ref_ from the _references_ slice if found.
func ResolveGoPackage ¶
func ResolveGoPackage(ctx *GeneratorContext, ref *gentypes.ComponentReference) string
func ResolveReferenceAndSwitchIfNeeded ¶
func ResolveReferenceAndSwitchIfNeeded( ctx *GeneratorContext, componentId *gentypes.ComponentReference, ref *openapi3.SchemaRef, ) *gentypes.ComponentReference
ResolveReferenceAndSwitchIfNeeded will create a `ComponentReference`. If the _ref_ is under the specification root path then it will be used. If it is under model root path it will use that instead to create the `ComponentReference` as root path. If specification and module is on the same root path, the the longest path will be used as root path.
Types ¶
type ExtendConfig ¶
type ExtendConfig struct { // MergeDocs is set to `true` it will add documentation onto each other (if _extending_ contains description). MergeDocs bool // MergeEnum indicates wether a enum should be replaced or merge with _target_. // // NOTE: It will use the equality Operator to determine if elements are equal or not. MergeEnum bool // MergeExtensions will stipulate if the extending schema will completely overwrite or merge its // extensions onto target schema. MergeExtensions bool }
AddSchemaToObject will add a schema to an object schema.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func NewGenerator ¶
func (*Generator) Generate ¶
func (gen *Generator) Generate(ctx *GeneratorContext) error
type GeneratorContext ¶
type GeneratorContext struct {
// contains filtered or unexported fields
}
GeneratorContext is used when generating the types.
func (*GeneratorContext) GetResolver ¶
func (ctx *GeneratorContext) GetResolver() *gentypes.ReferenceResolverImpl
func (*GeneratorContext) GetSpecification ¶
func (ctx *GeneratorContext) GetSpecification() *gentypes.OpenAPISpecificationDefinition
func (*GeneratorContext) ResolveTypeDefinition ¶
func (ctx *GeneratorContext) ResolveTypeDefinition(ref *gentypes.ComponentReference) *gentypes.TypeDefinition
type OpenAPIModule ¶
OpenAPIModule represents a file with one or more openapi objects.
func ScanForModules ¶
func ScanForModules(path string, inclusion []Include) ([]OpenAPIModule, error)
ScanForModules will scan all the modules from the path and use the inclusion list to filter the modules.
Open the file and parse it using the yaml parser. Include all top level object into a `Module` object.
func (OpenAPIModule) ToRef ¶
func (m OpenAPIModule) ToRef(object string) string
ToRef creates a reference to the object in or outside of the module.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
func NewSettings ¶
func (*Settings) Include ¶
Include adds a list of paths to include in the generation.
NOTE: Those must be relative to the module path.
It is possible to use glob expressions by adding : and the glob expression For example: 'mypkg:{a,b}-model.yaml' will add path 'mypkg' and all files matching the glob expression.
func (*Settings) ToGenerator ¶
ToGenerator creates a generator from the settings
func (*Settings) UseModelPath ¶
UseModelPath sets the base path where all models are resolved relative to.
CAUTION: It must be a fully qualified path, and not a relative path.
The _model_package_ is the full package name to the _models_ path. For example "models", "github.com/mariotoffia/go-openapi/models".
func (*Settings) UseOutputPath ¶
UseOutputPath sets the base path where all generated files will be written.
func (*Settings) UseSpec ¶
UseSpec sets the path where a open api spec file is located.
CAUTION: It must be a fully qualified path, and not a relative path.
If none is provided, a default one will be created.
NOTE: If model scanning is performed, those will be added to the spec _components.schema_ section.
The _spec_package_ is the full package name to the _spec_ path. For example "spec", "github.com/mariotoffia/go-openapi/spec".
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
func (*Templates) GetFileAsString ¶
GetFile will check if it exists in user provided templates folder or in the embedded templates folder.
func (*Templates) GetTemplate ¶
GetTemplate will return a template from the template folder.
NOTE: It will scan the user provided first if such exist before checking the embedded template folder.
type WellKnownTemplates ¶
type WellKnownTemplates string
const ( // TemplateIndex is the name of the main open api 3 spec file // to use when generating the open api 3 spec or models. // // This is when a spec do not exist and models are generated, // otherwise a user specified spec is needed. TemplateIndex WellKnownTemplates = "index.yaml" )