spec

package
v2.1.1649 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 12 Imported by: 0

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 BadRequestError string = "BadRequestError"
View Source
const InternalServerError string = "InternalServerError"
View Source
const ParamMessage string = "ParamMessage"

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.1"
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 HttpStatusCode

func HttpStatusCode(statusName Name) string

func HttpStatusName added in v2.1.1222

func HttpStatusName(statusCode string) string

func ReadSpec

func ReadSpec(data []byte) (*Spec, *Messages, error)

func UrlParamStr

func UrlParamStr(param *NamedParam) string

func WriteSpec

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

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 BodyKind added in v2.1.1472

type BodyKind string
const (
	BodyEmpty  BodyKind = "empty"
	BodyString BodyKind = "string"
	BodyJson   BodyKind = "json"
)

type Definition

type Definition struct {
	Type        Type
	Description *string
	Location    *yaml.Node
}

func (Definition) MarshalYAML

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

func (*Definition) UnmarshalYAML

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

type DefinitionDefault

type DefinitionDefault struct {
	Type        Type
	Default     *string
	Description *string
	Location    *yaml.Node
}

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
	UrlParts  []UrlPart
}

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"`
}

type EnumItem

type EnumItem struct {
	Value       string
	Description *string
}

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 Level added in v2.1.1547

type Level string
const (
	LevelError   Level = "error"
	LevelWarning Level = "warning"
	LevelInfo    Level = "information"
)

type Location

type Location struct {
	Line   int
	Column int
}

type Message

type Message struct {
	Level    Level
	Message  string
	Location *Location
}

func Error added in v2.1.1547

func Error(messageFormat string, args ...interface{}) Message

func Info added in v2.1.1547

func Info(messageFormat string, args ...interface{}) Message

func Warning added in v2.1.1547

func Warning(messageFormat string, args ...interface{}) Message

func (Message) At added in v2.1.1547

func (message Message) At(location *Location) Message

func (Message) String

func (self Message) String() string

type Messages

type Messages struct {
	Items messages
}

func NewMessages added in v2.1.1547

func NewMessages() *Messages

func (*Messages) Add added in v2.1.1547

func (ms *Messages) Add(message Message)

func (*Messages) AddAll added in v2.1.1547

func (ms *Messages) AddAll(messages ...Message)

func (*Messages) Contains added in v2.1.1547

func (ms *Messages) Contains(f func(Message) bool) bool

func (*Messages) ContainsLevel added in v2.1.1547

func (ms *Messages) ContainsLevel(level Level) bool

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 (Meta) MarshalYAML

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

type Model

type Model struct {
	Object      *Object
	Enum        *Enum
	OneOf       *OneOf
	Description *string
	Location    *yaml.Node
}

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) FullName added in v2.1.1218

func (op *NamedOperation) FullName() string

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
}

func (*NamedResponse) BodyIs added in v2.1.1472

func (response *NamedResponse) BodyIs(kind BodyKind) bool

func (*NamedResponse) BodyKind added in v2.1.1472

func (response *NamedResponse) BodyKind() BodyKind

type Object

type Object struct {
	Fields NamedDefinitions `yaml:"object"`
}

type OneOf

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

type Operation

type Operation operation

func (*Operation) BodyIs added in v2.1.1472

func (operation *Operation) BodyIs(kind BodyKind) bool

func (*Operation) BodyKind added in v2.1.1472

func (operation *Operation) BodyKind() BodyKind

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) Get added in v2.1.1649

func (responses Responses) Get(httpStatus string) *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
	Messages Messages
}

type Type

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

func NewType added in v2.1.1238

func NewType(str string) *Type

func (Type) String added in v2.1.1238

func (typ Type) String() string

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 UrlPart added in v2.1.1033

type UrlPart struct {
	Part  string
	Param *NamedParam
}

type Version

type Version struct {
	Version Name
	VersionSpecification
	ResolvedModels []*NamedModel
}

type VersionSpecification added in v2.1.993

type VersionSpecification struct {
	Http   Apis   `yaml:"http"`
	Models Models `yaml:"models"`
}

func (VersionSpecification) MarshalYAML added in v2.1.993

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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