spec

package
v2.1.1966-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 11 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 ErrorLocation string = "ErrorLocation"
View Source
const InternalServerError string = "InternalServerError"
View Source
const NotFoundError string = "NotFound"
View Source
const ValidationError string = "ValidationError"

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 SpecOptionsDefault = SpecOptions{true}
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

func HttpStatusName(statusCode string) string

func MergeHttpStatusCodes

func MergeHttpStatusCodes(left, right []string) []string

func ReadSpec

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

func ReadSpecWithOptions

func ReadSpecWithOptions(options SpecOptions, 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
	Http       *Http
}

type BodyKind

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 Http

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

func (*Http) GetUrl

func (apis *Http) GetUrl() string

func (Http) MarshalYAML

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

func (*Http) UnmarshalYAML

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

type HttpErrors

type HttpErrors struct {
	Responses      Responses
	Models         Models
	ResolvedModels []*NamedModel
}

type Level

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

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

func Info

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

func Warning

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

func (Message) At

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

func (Message) String

func (self Message) String() string

type Messages

type Messages struct {
	Items messages
}

func NewMessages

func NewMessages() *Messages

func (*Messages) Add

func (ms *Messages) Add(message Message)

func (*Messages) AddAll

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

func (*Messages) Contains

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

func (*Messages) ContainsLevel

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

func (op *NamedOperation) FullName() string

func (*NamedOperation) FullUrl

func (op *NamedOperation) FullUrl() string

type NamedParam

type NamedParam struct {
	Name Name
	DefinitionDefault
}

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

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

func (*Operation) BodyKind

func (operation *Operation) BodyKind() BodyKind

func (*Operation) GetResponse

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

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 OperationResponse

type OperationResponse struct {
	Response
	Operation *NamedOperation
}

type OperationResponses

type OperationResponses []OperationResponse

func (OperationResponses) Get

func (responses OperationResponses) Get(httpStatus string) *OperationResponse

func (OperationResponses) GetByStatusCode

func (responses OperationResponses) GetByStatusCode(statusCode string) *OperationResponse

func (OperationResponses) HttpStatusCodes

func (responses OperationResponses) HttpStatusCodes() []string

func (OperationResponses) MarshalYAML

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

func (*OperationResponses) UnmarshalYAML

func (value *OperationResponses) 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 Response

type Response struct {
	Name Name
	Definition
}

func (*Response) BodyIs

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

func (*Response) BodyKind

func (response *Response) BodyKind() BodyKind

type Responses

type Responses []Response

func (Responses) GetByStatusCode

func (responses Responses) GetByStatusCode(statusCode string) *Response

func (Responses) GetByStatusName

func (responses Responses) GetByStatusName(httpStatus string) *Response

func (Responses) HttpStatusCodes

func (responses Responses) HttpStatusCodes() []string

func (Responses) MarshalYAML

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

func (*Responses) UnmarshalYAML

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

type Security

type Security []SecurityRef

type SecurityRef

type SecurityRef securityRef

func (SecurityRef) MarshalYAML

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

func (*SecurityRef) UnmarshalYAML

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

type Spec

type Spec struct {
	Meta
	Versions   []Version
	HttpErrors HttpErrors
}

func (Spec) MarshalYAML

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

func (*Spec) UnmarshalYAML

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

type SpecOptions

type SpecOptions struct {
	AddErrors bool
}

type SpecParseResult

type SpecParseResult struct {
	Spec     *Spec
	Messages Messages
}

type Type

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

func NewType

func NewType(str string) *Type

func (Type) String

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

type UrlPart struct {
	Part  string
	Param *NamedParam
}

type Version

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

type VersionSpecification

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

func (VersionSpecification) MarshalYAML

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

Jump to

Keyboard shortcuts

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