importer

package
v0.758.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenAPI_EMPTY   = ""
	OpenAPI_STRING  = "string"
	OpenAPI_OBJECT  = "object"
	OpenAPI_ARRAY   = "array"
	OpenAPI_BOOLEAN = "boolean"
	OpenAPI_INTEGER = "integer"
	OpenAPI_NUMBER  = "number"
)

OpenAPI Data Types: https://swagger.io/docs/specification/data-models/data-types/ nolint:revive,stylecheck

View Source
const (
	MinOnly maxType = iota
	MaxSpecified
	OpenEnded
)
View Source
const BlankLine = "&& !!"
View Source
const CommentLineLength = 80
View Source
const PopIndent = "&& <<"
View Source
const PushIndent = "&& >>"

Variables

View Source
var (
	XSD_BOOLEAN  = strings.ToLower(xsd.Boolean.String())
	XSD_BYTE     = strings.ToLower(xsd.Byte.String())
	XSD_DATE     = strings.ToLower(xsd.Date.String())
	XSD_DATETIME = strings.ToLower(xsd.DateTime.String())
	XSD_DECIMAL  = strings.ToLower(xsd.Decimal.String())
	XSD_INT      = strings.ToLower(xsd.Int.String())
	XSD_INTEGER  = strings.ToLower(xsd.Integer.String())
	XSD_STRING   = strings.ToLower(xsd.String.String())
	XSD_TIME     = strings.ToLower(xsd.Time.String())
	XSD_NMTOKEN  = strings.ToLower(xsd.NMTOKEN.String())
)

nolint:revive,stylecheck

View Source
var Avro = Format{
	Name:      "avro",
	Signature: nil,
	FileExt:   []string{".avsc"},
}
View Source
var BigQuery = Format{
	Name:      "bigquery",
	Signature: nil,
	FileExt:   []string{".sql"},
}

Formats lists all supported import formats TODO: Add all transform imports dynamically

View Source
var Grammar = Format{
	Name:      "grammar",
	Signature: nil,
	FileExt:   []string{".g"},
}
View Source
var JSONSchema = Format{
	Name:      "jsonschema",
	Signature: regexp.MustCompile(`\$schema`),
	FileExt:   []string{".json"},
}
View Source
var MySQL = Format{
	Name:      "mysql",
	Signature: nil,
	FileExt:   []string{".sql"},
}
View Source
var MySQLDir = Format{
	Name:      "mysqlDir",
	Signature: nil,
	FileExt:   []string{".up.sql"},
}
View Source
var OpenAPI2 = Format{
	Name:      "swagger",
	Signature: regexp.MustCompile(`["']?swagger["']?\s*:`),
	FileExt:   []string{".yaml", ".json", ".yml"},
}

OpenAPI2 only has swagger 2.0.0 as the single valid format - The value MUST be "2.0". For more details refer to https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#swaggerObject

View Source
var OpenAPI3 = Format{
	Name:      "openapi3",
	Signature: regexp.MustCompile(`["']?openapi["']?\s*:`),
	FileExt:   []string{".yaml", ".json", ".yml"},
}

OpenAPI3 is identified by the openapi header. - The value MUST be "3.x.x". For more details refer to https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#oasDocument

OpenAPI string formats: https://swagger.io/docs/specification/data-models/data-types/ -> String Formats nolint:gochecknoglobals,revive,stylecheck

View Source
var Postgres = Format{
	Name:      "postgres",
	Signature: nil,
	FileExt:   []string{".sql"},
}
View Source
var PostgresDir = Format{
	Name:      "postgresDir",
	Signature: nil,
	FileExt:   []string{".up.sql"},
}
View Source
var Protobuf = Format{
	Name:      "protobuf",
	Signature: nil,
	FileExt:   []string{".proto"},
}
View Source
var ProtobufDir = Format{
	Name:      "protobufDir",
	Signature: nil,
	FileExt:   []string{".up.proto"},
}
View Source
var SYSL = Format{
	Name:      "sysl",
	Signature: nil,
	FileExt:   []string{".sysl"},
}
View Source
var SpannerSQL = Format{
	Name:      "spannerSQL",
	Signature: nil,
	FileExt:   []string{".sql"},
}
View Source
var SpannerSQLDir = Format{
	Name:      "spannerSQLdir",
	Signature: nil,
	FileExt:   []string{".up.sql"},
}
View Source
var StringAlias = &SyslBuiltIn{name: syslutil.Type_STRING}
View Source
var SyslPB = Format{
	Name:      "sysl.pb",
	Signature: nil,
	FileExt:   []string{".pb", ".textpb"},
}
View Source
var XSD = Format{
	Name:      "xsd",
	Signature: nil,
	FileExt:   []string{".xsd", ".xml"},
}

Functions

func NewOpenAPI3Loader added in v0.344.0

func NewOpenAPI3Loader(logger *logrus.Logger, fs afero.Fs) *openapi3.Loader

Types

type Alias

type Alias struct {
	Target Type
	// contains filtered or unexported fields
}

!alias type without the EXTERNAL_ prefix

func (*Alias) AddAttributes added in v0.397.0

func (s *Alias) AddAttributes(attrs []string) []string

func (*Alias) Attributes added in v0.397.0

func (s *Alias) Attributes() []string

func (*Alias) Name

func (s *Alias) Name() string

func (*Alias) SetName added in v0.702.0

func (s *Alias) SetName(name string)

type ArraiImporter added in v0.291.0

type ArraiImporter struct {
	// contains filtered or unexported fields
}

ArraiImporter encapsulates glue code for calling arr.ai scripts to import specs.

func MakeArraiImporterImporter added in v0.291.0

func MakeArraiImporterImporter(asset []byte, logger *logrus.Logger) *ArraiImporter

MakeArraiImporterImporter returns a new ArraiImporter.

func MakeSQLImporter added in v0.360.0

func MakeSQLImporter(logger *logrus.Logger) *ArraiImporter

MakeSQLImporter is a factory method for creating new SQL importer.

func (*ArraiImporter) Configure added in v0.551.0

func (i *ArraiImporter) Configure(arg *ImporterArg) (Importer, error)

Configure allows the imported Sysl application name, package and import directories to be specified.

func (*ArraiImporter) Load added in v0.291.0

func (i *ArraiImporter) Load(content string) (string, error)

Load generates a Sysl spec given the content of an input file.

func (*ArraiImporter) LoadFile added in v0.291.0

func (i *ArraiImporter) LoadFile(path string) (string, error)

LoadFile generates a Sysl spec be invoking the arr.ai script.

type Array

type Array struct {
	Items Type
	// contains filtered or unexported fields
}

func (*Array) AddAttributes added in v0.397.0

func (s *Array) AddAttributes(attrs []string) []string

func (*Array) Attributes added in v0.397.0

func (s *Array) Attributes() []string

func (*Array) Name

func (s *Array) Name() string

func (*Array) SetName added in v0.702.0

func (s *Array) SetName(name string)

type Endpoint

type Endpoint struct {
	Path        string
	Description string

	Params Parameters

	Responses []Response
}

type Enum

type Enum struct {
	// contains filtered or unexported fields
}

func (*Enum) AddAttributes added in v0.397.0

func (s *Enum) AddAttributes(attrs []string) []string

func (*Enum) Attributes added in v0.397.0

func (s *Enum) Attributes() []string

func (*Enum) Name

func (s *Enum) Name() string

func (*Enum) SetName added in v0.702.0

func (s *Enum) SetName(name string)

type ExternalAlias

type ExternalAlias struct {
	Target Type
	// contains filtered or unexported fields
}

func (*ExternalAlias) AddAttributes added in v0.397.0

func (s *ExternalAlias) AddAttributes(attrs []string) []string

func (*ExternalAlias) Attributes added in v0.397.0

func (s *ExternalAlias) Attributes() []string

func (*ExternalAlias) Name

func (s *ExternalAlias) Name() string

func (*ExternalAlias) SetName added in v0.702.0

func (s *ExternalAlias) SetName(name string)

type Field

type Field struct {
	Name     string
	Type     Type
	Optional bool
	Attrs    []string
	SizeSpec *sizeSpec
}

type FieldList

type FieldList []Field

func (FieldList) SortWithoutDupl added in v0.453.0

func (props FieldList) SortWithoutDupl() (FieldList, error)

type Format added in v0.124.0

type Format struct {
	Name      string         // Name of the format
	Signature *regexp.Regexp // This is a regex which can be used to uniquely identify the format
	FileExt   []string       // The file extension of the format
}

Format represents a format that can be imported into Sysl

func GuessFileType added in v0.124.0

func GuessFileType(path string, isDir bool, content []byte, validFormats []Format) (Format, error)

GuessFileType detects the file based on the filename extension and the file itself. It returns the detected format if successful, or an error if not. It first tries to match the file extensions before checking the files for signatures such as `swagger: "2.0"`.

type Func

type Func func(args OutputData, text string, logger *logrus.Logger) (out string, err error)

type ImportedBuiltInAlias

type ImportedBuiltInAlias struct {
	Target Type
	// contains filtered or unexported fields
}

func (*ImportedBuiltInAlias) AddAttributes added in v0.397.0

func (s *ImportedBuiltInAlias) AddAttributes(attrs []string) []string

func (*ImportedBuiltInAlias) Attributes added in v0.397.0

func (s *ImportedBuiltInAlias) Attributes() []string

func (*ImportedBuiltInAlias) Name

func (s *ImportedBuiltInAlias) Name() string

func (*ImportedBuiltInAlias) SetName added in v0.702.0

func (s *ImportedBuiltInAlias) SetName(name string)

type Importer added in v0.124.0

type Importer interface {
	// LoadFile reads in a file from path and returns the generated Sysl.
	LoadFile(path string) (string, error)
	// Load takes in a string in a format supported by an the importer
	// It returns the converted Sysl as a string.
	Load(content string) (string, error)
	// Configure allows the imported Sysl application name, package and import directories to be specified.
	Configure(arg *ImporterArg) (Importer, error)
}

Importer is an interface implemented by all sysl importers

func Factory added in v0.124.0

func Factory(path string, isDir bool, formatName string, content []byte, logger *logrus.Logger) (Importer, error)

Factory takes in an absolute path and its contents (if path is a file) and returns an importer for the detected file type.

func NewAvroImporter added in v0.217.0

func NewAvroImporter(logger *logrus.Logger) Importer

NewAvroImporter returns a new avroImporter.

func NewLegacyOpenAPIV3Importer added in v0.434.0

func NewLegacyOpenAPIV3Importer(logger *logrus.Logger, fs afero.Fs) Importer

func NewOpenAPIV3Importer added in v0.136.0

func NewOpenAPIV3Importer(logger *logrus.Logger) Importer

type ImporterArg added in v0.639.0

type ImporterArg struct {
	AppName, PackageName, Imports string
	Shallow                       bool
}

type IndentWriter

type IndentWriter struct {
	io.Writer
	// contains filtered or unexported fields
}

func NewIndentWriter

func NewIndentWriter(text string, out io.Writer) *IndentWriter

func (*IndentWriter) CurrentIndentLen

func (i *IndentWriter) CurrentIndentLen() int

func (*IndentWriter) Pop

func (i *IndentWriter) Pop()

func (*IndentWriter) Push

func (i *IndentWriter) Push()

func (*IndentWriter) Write

func (i *IndentWriter) Write() error

type MethodEndpoints

type MethodEndpoints struct {
	Method    string
	Endpoints []Endpoint
}

func (MethodEndpoints) Sort added in v0.397.0

func (me MethodEndpoints) Sort()

type OpenAPI2Importer added in v0.124.0

type OpenAPI2Importer struct {
	*OpenAPI3Importer
	// contains filtered or unexported fields
}

func MakeOpenAPI2Importer added in v0.124.0

func MakeOpenAPI2Importer(logger *logrus.Logger, basePath string, filePath string) *OpenAPI2Importer

func (*OpenAPI2Importer) Configure added in v0.551.0

func (l *OpenAPI2Importer) Configure(arg *ImporterArg) (Importer, error)

Configure allows the imported Sysl application name, package and import directories to be specified.

func (*OpenAPI2Importer) Load added in v0.124.0

func (l *OpenAPI2Importer) Load(oas2spec string) (string, error)

func (*OpenAPI2Importer) LoadFile added in v0.238.0

func (l *OpenAPI2Importer) LoadFile(path string) (string, error)

type OpenAPI3Importer added in v0.124.0

type OpenAPI3Importer struct {
	// contains filtered or unexported fields
}

func (*OpenAPI3Importer) Configure added in v0.551.0

func (o *OpenAPI3Importer) Configure(arg *ImporterArg) (Importer, error)

Configure allows the imported Sysl application name, package and import directories to be specified.

func (*OpenAPI3Importer) Load added in v0.124.0

func (o *OpenAPI3Importer) Load(file string) (string, error)

func (*OpenAPI3Importer) LoadFile added in v0.344.0

func (o *OpenAPI3Importer) LoadFile(path string) (string, error)

type OpenAPIFormat added in v0.344.0

type OpenAPIFormat = string
const (
	OpenAPIFormat_INT32    OpenAPIFormat = "int32"
	OpenAPIFormat_INT64    OpenAPIFormat = "int64"
	OpenAPIFormat_FLOAT    OpenAPIFormat = "float"
	OpenAPIFormat_DOUBLE   OpenAPIFormat = "double"
	OpenAPIFormat_DATE     OpenAPIFormat = "date"
	OpenAPIFormat_DATETIME OpenAPIFormat = "date-time"
	OpenAPIFormat_BYTE     OpenAPIFormat = "byte"
	OpenAPIFormat_BINARY   OpenAPIFormat = "binary"
	OpenAPIFormat_UUID     OpenAPIFormat = "uuid"
	OpenAPIFormat_URI      OpenAPIFormat = "uri"
)

nolint:revive,stylecheck

type OutputData

type OutputData struct {
	AppName     string
	Package     string
	ImportPaths string
	SwaggerRoot string
	Mode        string
	Shallow     bool
}

type Param

type Param struct {
	Field
	In string
}

type Parameters

type Parameters struct {
	// contains filtered or unexported fields
}

func (*Parameters) Add

func (p *Parameters) Add(param Param)

func (Parameters) BodyParams

func (p Parameters) BodyParams() []Param

func (Parameters) CookieParams added in v0.314.0

func (p Parameters) CookieParams() []Param

func (*Parameters) Extend added in v0.5.0

func (p *Parameters) Extend(others Parameters) Parameters

func (Parameters) HeaderParams

func (p Parameters) HeaderParams() []Param

func (Parameters) PathParams

func (p Parameters) PathParams() []Param

func (Parameters) QueryParams

func (p Parameters) QueryParams() []Param

type ProtobufImporter added in v0.457.0

type ProtobufImporter struct {
	// contains filtered or unexported fields
}

func MakeProtobufImporter added in v0.457.0

func MakeProtobufImporter(logger *logrus.Logger) *ProtobufImporter

MakeProtobufImporter is a factory method for creating new Protobuf importer.

func (*ProtobufImporter) Configure added in v0.551.0

func (p *ProtobufImporter) Configure(arg *ImporterArg) (Importer, error)

Configure allows the imported Sysl application name, package and import directories to be specified.

func (*ProtobufImporter) Load added in v0.457.0

func (p *ProtobufImporter) Load(protoSpec string) (string, error)

Load returns a Sysl spec equivalent to protoSpec.

func (*ProtobufImporter) LoadFile added in v0.457.0

func (p *ProtobufImporter) LoadFile(path string) (string, error)

type Response

type Response struct {
	Text string
	Type Type
}

Response is going to be either freetext or a type, or both

type StandardType

type StandardType struct {
	Properties FieldList
	// contains filtered or unexported fields
}

func (*StandardType) AddAttributes added in v0.397.0

func (s *StandardType) AddAttributes(attrs []string) []string

func (*StandardType) Attributes

func (s *StandardType) Attributes() []string

func (*StandardType) Name

func (s *StandardType) Name() string

func (*StandardType) SetName added in v0.702.0

func (s *StandardType) SetName(name string)

func (*StandardType) SortProperties added in v0.453.0

func (s *StandardType) SortProperties() error

type SyslBuiltIn

type SyslBuiltIn struct {
	// contains filtered or unexported fields
}

func (*SyslBuiltIn) AddAttributes added in v0.397.0

func (s *SyslBuiltIn) AddAttributes(attrs []string) []string

func (*SyslBuiltIn) Attributes added in v0.397.0

func (s *SyslBuiltIn) Attributes() []string

func (*SyslBuiltIn) Name

func (s *SyslBuiltIn) Name() string

func (*SyslBuiltIn) SetName added in v0.702.0

func (s *SyslBuiltIn) SetName(name string)

type SyslInfo

type SyslInfo struct {
	OutputData

	Title       string
	Description string
	OtherFields []string // Ordered key, val pair
}

type SyslPBImporter added in v0.672.0

type SyslPBImporter struct {
	// contains filtered or unexported fields
}

func MakeSyslPBImporter added in v0.672.0

func MakeSyslPBImporter(logger *logrus.Logger) *SyslPBImporter

MakeSyslPBImporter is a factory method for creating new SyslPB importer.

func (*SyslPBImporter) Configure added in v0.672.0

func (i *SyslPBImporter) Configure(arg *ImporterArg) (Importer, error)

Configure for Sysl PB files is a no-op; they are simply imported as-is.

func (*SyslPBImporter) Load added in v0.672.0

func (i *SyslPBImporter) Load(content string) (string, error)

Load returns a Sysl spec equivalent to protoSpec.

func (*SyslPBImporter) LoadFile added in v0.672.0

func (i *SyslPBImporter) LoadFile(path string) (string, error)

type TransformImporter added in v0.431.0

type TransformImporter struct {
	// contains filtered or unexported fields
}

TransformImporter enables importing from various formats by running embedded arr.ai transform scripts that convert data into Sysl.

func MakeTransformImporter added in v0.431.0

func MakeTransformImporter(logger *logrus.Logger, transformName string) *TransformImporter

func (*TransformImporter) Configure added in v0.551.0

func (i *TransformImporter) Configure(arg *ImporterArg) (Importer, error)

Configure allows the imported Sysl application name, package and import directories to be specified.

func (*TransformImporter) Load added in v0.431.0

func (i *TransformImporter) Load(content string) (string, error)

Load generates a Sysl spec given the content of an input file.

func (*TransformImporter) LoadFile added in v0.431.0

func (i *TransformImporter) LoadFile(path string) (string, error)

LoadFile generates a Sysl spec by invoking the arr.ai transform.

type Type

type Type interface {
	Name() string
	SetName(name string)
	Attributes() []string
	AddAttributes([]string) []string
}

func NewStringAlias

func NewStringAlias(name string, attrs ...string) Type

type TypeList

type TypeList struct {
	// contains filtered or unexported fields
}

func (*TypeList) Add

func (t *TypeList) Add(item ...Type)

func (*TypeList) AddAndRet added in v0.5.0

func (t *TypeList) AddAndRet(item Type) Type

func (TypeList) Find

func (t TypeList) Find(name string) (Type, bool)

func (TypeList) Items

func (t TypeList) Items() []Type

func (TypeList) Sort

func (t TypeList) Sort()

type Union

type Union struct {
	Options FieldList
	// contains filtered or unexported fields
}

Union represents a union type https://sysl.io/docs/lang-spec#union

func (*Union) AddAttributes added in v0.397.0

func (s *Union) AddAttributes(attrs []string) []string

func (*Union) Attributes added in v0.397.0

func (s *Union) Attributes() []string

func (*Union) Name

func (s *Union) Name() string

func (*Union) SetName added in v0.702.0

func (s *Union) SetName(name string)

type XSDImporter added in v0.124.0

type XSDImporter struct {
	// contains filtered or unexported fields
}

func MakeXSDImporter added in v0.124.0

func MakeXSDImporter(logger *logrus.Logger) *XSDImporter

func (*XSDImporter) Configure added in v0.551.0

func (i *XSDImporter) Configure(arg *ImporterArg) (Importer, error)

Configure allows the imported Sysl application name, package and import directories to be specified.

func (*XSDImporter) Load added in v0.124.0

func (i *XSDImporter) Load(input string) (string, error)

func (*XSDImporter) LoadFile added in v0.238.0

func (i *XSDImporter) LoadFile(path string) (string, error)

Jump to

Keyboard shortcuts

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