spec

package module
v0.0.0-...-b004e20 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 12 Imported by: 14

README

spec

Spec is API specification format. It currently can define models and HTTP endpoints. Read documentation at docs.specgen.io.

Documentation

Index

Constants

View Source
const (
	HttpStatusInternalServerError string = "internal_server_error"
	HttpStatusNotFound            string = "not_found"
	HttpStatusBadRequest          string = "bad_request"
)
View Source
const (
	TypeInt32    string = "int32"
	TypeInt64    string = "int64"
	TypeFloat    string = "float"
	TypeDouble   string = "double"
	TypeDecimal  string = "decimal"
	TypeBoolean  string = "boolean"
	TypeString   string = "string"
	TypeUuid     string = "uuid"
	TypeDate     string = "date"
	TypeDateTime string = "datetime"
	TypeJson     string = "json"
	TypeEmpty    string = "empty"
)
View Source
const (
	TypeAliasInt  string = "int"
	TypeAliasLong string = "long"
	TypeAliasBool string = "bool"
	TypeAliasStr  string = "str"
)
View Source
const (
	LevelError   string = "error"
	LevelWarning string = "warning"
)

Variables

View Source
var Boolean = Format{Name: "boolean", Regex: "^true$|^false$", Example: "true or false"}
View Source
var Date = Format{Name: "date", Regex: "^\\d{4}-\\d{2}-\\d{2}$", Example: "2019-12-31"}
View Source
var DateTime = Format{Name: "datetime", Regex: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$", Example: "2019-12-31T15:53:45"}
View Source
var Float = Format{Name: "float", Regex: "^[-+]?\\d+\\.?\\d*$", Example: "123.4"}
View Source
var HttpMethod = Format{Name: "HTTP method", Regex: "^GET|POST|PUT|DELETE$", Example: "GET, POST, PUT, DELETE"}
View Source
var HttpParams = Format{Name: "symbols a-z, A-Z, 0-9, -, _ starting from letter", Regex: "^[a-zA-Z]([a-zA-Z0-9_-])*$", Example: "some123, Some-123, some_123"}
View Source
var Integer = Format{Name: "integer", Regex: "^[-+]?\\d+$", Example: "123"}
View Source
var JsonField = Format{Name: "symbols a-z, A-Z, 0-9, _ starting from letter or _", Regex: "^[a-zA-Z_]([a-zA-Z_0-9])*$", Example: "some123, Some123, some_123, _some123"}
View Source
var LowerCase = Format{Name: "lower case", Regex: "^[a-z][a-z]*[0-9]*$", Example: "thisislowercase"}
View Source
var PascalCase = Format{Name: "pascal case", Regex: "^[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$", Example: "ThisIsPascalCase"}
View Source
var SnakeCase = Format{Name: "snake case", Regex: "^[a-z][a-z0-9]*(_[a-z][a-z0-9]*)*$", Example: "this_is_snake_case"}
View Source
var SpecVersion = "2"
View Source
var UUID = Format{Name: "uuid", Regex: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$", Example: "fbd3036f-0f1c-4e98-b71c-d4cd61213f90"}
View Source
var VersionFormat = Format{Name: "version", Regex: "^v\\d+$", Example: "v1"}

Functions

func GetSpecVersion

func GetSpecVersion(data []byte) (*string, error)

func HttpStatusCode

func HttpStatusCode(statusName Name) string

func UrlParamStr

func UrlParamStr(paramName string) string

func WriteSpec

func WriteSpec(spec *Spec) ([]byte, error)

func WriteSpecFile

func WriteSpecFile(spec *Spec, filepath string) error

func YamlString

func YamlString(value string) yaml.Node

Types

type Api

type Api struct {
	Name       Name
	Operations Operations
	Apis       *Apis
}

type Apis

type Apis struct {
	Url     *string
	Apis    []Api
	Version *Version
}

func (*Apis) GetUrl

func (apis *Apis) GetUrl() string

func (Apis) MarshalYAML

func (value Apis) MarshalYAML() (interface{}, error)

func (*Apis) UnmarshalYAML

func (value *Apis) UnmarshalYAML(node *yaml.Node) error

type Definition

type Definition definition

func (Definition) MarshalYAML

func (value Definition) MarshalYAML() (interface{}, error)

func (*Definition) UnmarshalYAML

func (value *Definition) UnmarshalYAML(node *yaml.Node) error

type DefinitionDefault

type DefinitionDefault definitionDefault

func (DefinitionDefault) MarshalYAML

func (value DefinitionDefault) MarshalYAML() (interface{}, error)

func (*DefinitionDefault) UnmarshalYAML

func (value *DefinitionDefault) UnmarshalYAML(node *yaml.Node) error

type Endpoint

type Endpoint struct {
	Method    string
	Url       string
	UrlParams UrlParams
}

func ParseEndpoint

func ParseEndpoint(endpointStr string) *Endpoint

func (Endpoint) MarshalYAML

func (value Endpoint) MarshalYAML() (interface{}, error)

func (*Endpoint) UnmarshalYAML

func (value *Endpoint) UnmarshalYAML(node *yaml.Node) error

type Enum

type Enum struct {
	Items       EnumItems `yaml:"enum"`
	Description *string   `yaml:"description"`
}

func (Enum) MarshalYAML

func (value Enum) MarshalYAML() (interface{}, error)

type EnumItem

type EnumItem struct {
	Value       string  `yaml:"value"`
	Description *string `yaml:"description"`
}

type EnumItems

type EnumItems []NamedEnumItem

func (EnumItems) MarshalYAML

func (value EnumItems) MarshalYAML() (interface{}, error)

func (*EnumItems) UnmarshalYAML

func (value *EnumItems) UnmarshalYAML(node *yaml.Node) error

type Format

type Format struct {
	Name    string
	Regex   string
	Example string
}

func FormatOr

func FormatOr(f1 Format, f2 Format) Format

func (*Format) Check

func (format *Format) Check(value string) error

type FormatError

type FormatError struct {
	Value  string
	Format Format
}

func (*FormatError) Error

func (err *FormatError) Error() string

type HeaderParams

type HeaderParams Params

func (HeaderParams) MarshalYAML

func (params HeaderParams) MarshalYAML() (interface{}, error)

func (*HeaderParams) UnmarshalYAML

func (value *HeaderParams) UnmarshalYAML(node *yaml.Node) error

type Location

type Location struct {
	Line int
}

func GetLocation

func GetLocation(node yaml.Node) Location

type Message

type Message struct {
	Level    string
	Message  string
	Location *yaml.Node
}

func (Message) String

func (self Message) String() string

type Messages

type Messages []Message

type Meta

type Meta struct {
	SpecVersion string  `yaml:"spec"`
	Name        Name    `yaml:"name"`
	Title       *string `yaml:"title,omitempty"`
	Description *string `yaml:"description,omitempty"`
	Version     string  `yaml:"version"`
}

func ReadMeta

func ReadMeta(data []byte) (*Meta, error)

func ReadMetaFile

func ReadMetaFile(filepath string) (*Meta, error)

func (Meta) MarshalYAML

func (value Meta) MarshalYAML() (interface{}, error)

type Model

type Model struct {
	Object *Object
	Enum   *Enum
	OneOf  *OneOf
}

func (*Model) Description

func (model *Model) Description() *string

func (*Model) IsEnum

func (self *Model) IsEnum() bool

func (*Model) IsObject

func (self *Model) IsObject() bool

func (*Model) IsOneOf

func (self *Model) IsOneOf() bool

func (Model) MarshalYAML

func (value Model) MarshalYAML() (interface{}, error)

func (*Model) UnmarshalYAML

func (value *Model) UnmarshalYAML(node *yaml.Node) error

type Models

type Models []NamedModel

func (Models) MarshalYAML

func (value Models) MarshalYAML() (interface{}, error)

func (*Models) UnmarshalYAML

func (value *Models) UnmarshalYAML(node *yaml.Node) error

type ModelsMap

type ModelsMap map[string]*NamedModel

type Name

type Name struct {
	Source   string
	Location *yaml.Node
}

func (Name) CamelCase

func (self Name) CamelCase() string

func (Name) Check

func (self Name) Check(format Format) error

func (Name) FlatCase

func (self Name) FlatCase() string

func (Name) MarshalYAML

func (value Name) MarshalYAML() (interface{}, error)

func (Name) PascalCase

func (self Name) PascalCase() string

func (Name) SnakeCase

func (self Name) SnakeCase() string

func (*Name) UnmarshalYAML

func (value *Name) UnmarshalYAML(node *yaml.Node) error

func (Name) UpperCase

func (self Name) UpperCase() string

type NamedDefinition

type NamedDefinition struct {
	Name Name
	Definition
}

type NamedDefinitions

type NamedDefinitions []NamedDefinition

func (NamedDefinitions) MarshalYAML

func (value NamedDefinitions) MarshalYAML() (interface{}, error)

func (*NamedDefinitions) UnmarshalYAML

func (value *NamedDefinitions) UnmarshalYAML(node *yaml.Node) error

type NamedEnumItem

type NamedEnumItem struct {
	Name Name
	EnumItem
}

type NamedModel

type NamedModel struct {
	Name Name
	Model
	Version *Version
}

type NamedOperation

type NamedOperation struct {
	Name Name
	Operation
	Api *Api
}

func (*NamedOperation) FullUrl

func (op *NamedOperation) FullUrl() string

type NamedParam

type NamedParam struct {
	Name Name
	DefinitionDefault
}

type NamedResponse

type NamedResponse struct {
	Name Name
	Definition
	Operation *NamedOperation
}

type Object

type Object object

func (Object) MarshalYAML

func (value Object) MarshalYAML() (interface{}, error)

func (*Object) UnmarshalYAML

func (value *Object) UnmarshalYAML(node *yaml.Node) error

type OneOf

type OneOf struct {
	Items         NamedDefinitions `yaml:"oneOf"`
	Discriminator *string          `yaml:"discriminator"`
	Description   *string          `yaml:"description"`
}

func (OneOf) MarshalYAML

func (value OneOf) MarshalYAML() (interface{}, error)

type Operation

type Operation operation

func (*Operation) GetResponse

func (operation *Operation) GetResponse(status string) *NamedResponse

func (*Operation) HasParams

func (operation *Operation) HasParams() bool

func (Operation) MarshalYAML

func (value Operation) MarshalYAML() (interface{}, error)

func (*Operation) UnmarshalYAML

func (value *Operation) UnmarshalYAML(node *yaml.Node) error

type Operations

type Operations []NamedOperation

func (Operations) MarshalYAML

func (value Operations) MarshalYAML() (interface{}, error)

func (*Operations) UnmarshalYAML

func (value *Operations) UnmarshalYAML(node *yaml.Node) error

type Params

type Params []NamedParam

type QueryParams

type QueryParams Params

func (QueryParams) MarshalYAML

func (params QueryParams) MarshalYAML() (interface{}, error)

func (*QueryParams) UnmarshalYAML

func (value *QueryParams) UnmarshalYAML(node *yaml.Node) error

type Responses

type Responses []NamedResponse

func (Responses) MarshalYAML

func (value Responses) MarshalYAML() (interface{}, error)

func (*Responses) UnmarshalYAML

func (value *Responses) UnmarshalYAML(node *yaml.Node) error

type Spec

type Spec struct {
	Meta
	Versions []Version
}

func (Spec) MarshalYAML

func (value Spec) MarshalYAML() (interface{}, error)

func (*Spec) UnmarshalYAML

func (value *Spec) UnmarshalYAML(node *yaml.Node) error

type SpecParseResult

type SpecParseResult struct {
	Spec     *Spec
	Warnings Messages
	Errors   Messages
}

func ReadSpec

func ReadSpec(data []byte) (*SpecParseResult, error)

func ReadSpecFile

func ReadSpecFile(filepath string) (*SpecParseResult, error)

type Type

type Type struct {
	Definition TypeDef
	Location   *yaml.Node
}

func (*Type) UnmarshalYAML

func (value *Type) UnmarshalYAML(node *yaml.Node) error

type TypeDef

type TypeDef struct {
	Name  string
	Node  TypeNode
	Child *TypeDef
	Plain string
	Info  *TypeInfo
}

func Array

func Array(typ *TypeDef) *TypeDef

func Map

func Map(typ *TypeDef) *TypeDef

func Nullable

func Nullable(typ *TypeDef) *TypeDef

func ParseType

func ParseType(value string) TypeDef

func Plain

func Plain(typ string) *TypeDef

func (*TypeDef) BaseType

func (self *TypeDef) BaseType() *TypeDef

func (*TypeDef) IsEmpty

func (self *TypeDef) IsEmpty() bool

func (*TypeDef) IsNullable

func (self *TypeDef) IsNullable() bool

func (TypeDef) String

func (typ TypeDef) String() string

type TypeInfo

type TypeInfo struct {
	Structure   TypeStructure
	Defaultable bool
	Model       *NamedModel
}

func ArrayTypeInfo

func ArrayTypeInfo() *TypeInfo

func MapTypeInfo

func MapTypeInfo() *TypeInfo

func ModelTypeInfo

func ModelTypeInfo(model *NamedModel) *TypeInfo

func NullableTypeInfo

func NullableTypeInfo(childInfo *TypeInfo) *TypeInfo

type TypeNode

type TypeNode int
const (
	PlainType    TypeNode = 0
	NullableType TypeNode = 1
	ArrayType    TypeNode = 2
	MapType      TypeNode = 3
)

type TypeStructure

type TypeStructure int
const (
	StructureNone   TypeStructure = 0
	StructureScalar TypeStructure = 1
	StructureArray  TypeStructure = 2
	StructureObject TypeStructure = 3
)

type UrlParams

type UrlParams Params

type Version

type Version struct {
	Version Name

	ResolvedModels []*NamedModel
	// contains filtered or unexported fields
}

func (Version) MarshalYAML

func (value Version) MarshalYAML() (interface{}, error)

type YamlMap

type YamlMap struct {
	Node yaml.Node
}

func NewYamlMap

func NewYamlMap() *YamlMap

func (*YamlMap) Add

func (yamlMap *YamlMap) Add(key interface{}, value interface{}) error

func (*YamlMap) AddOmitNil

func (yamlMap *YamlMap) AddOmitNil(key interface{}, value interface{}) error

func (*YamlMap) AddWithComment

func (yamlMap *YamlMap) AddWithComment(key interface{}, value interface{}, comment *string) error

func (*YamlMap) Merge

func (yamlMap *YamlMap) Merge(value interface{}) error

Jump to

Keyboard shortcuts

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