expr

package
v0.0.0-...-55524bd Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultEncoding is default encoding when empty
	DefaultEncoding = consts.DefaultEncoding
	// PolyEncoding is encoding by poly api
	PolyEncoding = consts.PolyEncoding
)

Variables

View Source
var (
	// EnumTypesEnum represents enum of enum types
	EnumTypesEnum = newEnumSet(nil)
	EnumNode      = EnumTypesEnum.MustReg(consts.EnumNode)
	EnumValue     = EnumTypesEnum.MustReg(consts.EnumValue)
	EnumOper      = EnumTypesEnum.MustReg(consts.EnumOper)
	EnumCond      = EnumTypesEnum.MustReg(consts.EnumCond)
	EnumCmp       = EnumTypesEnum.MustReg(consts.EnumCmp)
	EnumIn        = EnumTypesEnum.MustReg(consts.EnumIn)
	EnumAuth      = EnumTypesEnum.MustReg(consts.EnumAuth)
)

enum of enum types

View Source
var (
	// ValTypeEnum input value enum set, basic value accept in Input node
	ValTypeEnum = newEnumSet(nil)
	// ValTypeNumber represent value like 123
	ValTypeNumber = ValTypeEnum.MustReg("number")
	// ValTypeString represent value like "xyz"
	ValTypeString = ValTypeEnum.MustReg("string")

	// XValTypeAction represent value like action parameter
	ValTypeAction = ValTypeEnum.MustReg("action")
	// XValTypeTimestamp represent value like timestamp parameter
	ValTypeTimestamp = ValTypeEnum.MustReg("timestamp")

	// ValTypeBoolean represent value like true
	ValTypeBoolean = ValTypeEnum.MustReg("boolean")
	// ValTypeObject represent value like {...}
	ValTypeObject = ValTypeEnum.MustReg("object")
	// ValTypeArray represent value like [...]
	ValTypeArray = ValTypeEnum.MustReg("array")

	// XValTypeField represent value like req.data.userId
	ValTypeField = ValTypeEnum.MustReg("field")

	ValTypeArrayString = ValTypeEnum.MustReg("array_string")
)

basic types

View Source
var (
	// EncodingEnum represents encoding format
	EncodingEnum = newEnumSet(nil)
	// EncodingJSON represents encoding JSON
	EncodingJSON = EncodingEnum.MustReg(consts.EncodingJSON)
	// EncodingXML represents encoding XML
	EncodingXML = EncodingEnum.MustReg(consts.EncodingXML)
	// EncodingYAML represents encoding YAML
	EncodingYAML = EncodingEnum.MustReg(consts.EncodingYAML)
)
View Source
var (
	// SchemaEnum represents API scheme
	SchemaEnum = newEnumSet(nil)
	// SchemaHTTP represents API scheme http
	SchemaHTTP = SchemaEnum.MustReg(consts.SchemaHTTP)
	// SchemaHTTPS represents API scheme https
	SchemaHTTPS = SchemaEnum.MustReg(consts.SchemaHTTPS)
)
View Source
var (
	// MethodEnum represents http API methods
	MethodEnum    = newEnumSet(nil)
	MethodGet     = MethodEnum.MustReg(consts.MethodGet)
	MethodPost    = MethodEnum.MustReg(consts.MethodPost)
	MethodPut     = MethodEnum.MustReg(consts.MethodPut)
	MethodDelete  = MethodEnum.MustReg(consts.MethodDelete)
	MethodOPTIONS = MethodEnum.MustReg(consts.MethodOptions)
	MethodHEAD    = MethodEnum.MustReg(consts.MethodHead)
	MethodTRACE   = MethodEnum.MustReg(consts.MethodTrace)
	MethodCONNECT = MethodEnum.MustReg(consts.MethodConnect)
)

http API methods

View Source
var (
	// ParaTypeEnum represents parameter type
	ParaTypeEnum     = newEnumSet(nil)
	ParaTypeHeader   = ParaTypeEnum.MustReg(consts.ParaInHeader)
	ParaTypePath     = ParaTypeEnum.MustReg(consts.ParaInPath)
	ParaTypeBody     = ParaTypeEnum.MustReg(consts.ParaInBody)
	ParaTypeQuery    = ParaTypeEnum.MustReg(consts.ParaInQuery)
	ParaTypeFormData = ParaTypeEnum.MustReg(consts.ParaInFormData)
	// ParaTypeHide represents hide parameter like skey
	ParaTypeHide = ParaTypeEnum.MustReg("hide")
)

parameter type

Functions

func FullVarName

func FullVarName(name string) string

FullVarName get the full variable of poly API

func GetFactory

func GetFactory() *factory.FlexObjFactory

GetFactory return the factory object

func GetFieldName

func GetFieldName(f string) string

GetFieldName return the file name from field ref. eg: req1.data.x => x

Types

type APISampleInput

type APISampleInput struct {
	Header http.Header     `json:"header,omitempty"`
	Body   json.RawMessage `json:"body,omitempty"`
}

APISampleInput is the sample input of an API

type APISampleOutput

type APISampleOutput struct {
	Header http.Header     `json:"header,omitempty"`
	Resp   json.RawMessage `json:"resp,omitempty"`
}

APISampleOutput is the sample output of an API

type CreateSampleDataor

type CreateSampleDataor interface {
	CreateSampleData(val interface{}, titleFirst bool) value.JSONValue
}

CreateSampleDataor represents value that can generate sample JSON value

type DelayedJSONDecoder

type DelayedJSONDecoder interface {
	DelayedJSONDecode() error //  delay unmarshal flex json object
}

DelayedJSONDecoder define an object that need delay decode JSON

type Enum

type Enum enumset.Enum

Enum exports

func (Enum) EncodingToMIME

func (e Enum) EncodingToMIME() (string, error)

EncodingToMIME change encoding like JSON to MIME like "application/json"

func (Enum) IsAction

func (e Enum) IsAction() bool

IsAction judge if a value type is action

func (Enum) IsBody

func (e Enum) IsBody() bool

IsBody judege if is a body parameter

func (Enum) IsField

func (e Enum) IsField() bool

IsField judge if a value type is field refer

func (Enum) IsHeader

func (e Enum) IsHeader() bool

IsHeader judege if is a header parameter

func (Enum) IsHeaderAcceptable

func (e Enum) IsHeaderAcceptable() bool

IsHeaderAcceptable judege if is a header-acceptable parameter

func (Enum) IsHide

func (e Enum) IsHide() bool

IsHide judege if is a hide parameter

func (Enum) IsNullable

func (e Enum) IsNullable() bool

IsNullable judge if the data field is nullable

func (Enum) IsPath

func (e Enum) IsPath() bool

IsPath judege if is a path parameter

func (Enum) IsPredefineable

func (e Enum) IsPredefineable() bool

IsPredefineable judge if a value is predefineable

func (Enum) IsQuery

func (e Enum) IsQuery() bool

IsQuery judege if is a query parameter

func (Enum) IsStringer

func (e Enum) IsStringer() bool

IsStringer judge if a value is able to convert to string

func (Enum) IsTimestamp

func (e Enum) IsTimestamp() bool

IsTimestamp judge if a value type is timestamp

func (Enum) SameIn

func (e Enum) SameIn(o Enum) bool

SameIn compare if the parameter from the same input way

func (Enum) String

func (e Enum) String() string

String show enum as string

type FieldRef

type FieldRef string

FieldRef is field reference

func (FieldRef) Empty

func (v FieldRef) Empty() bool

Empty check if field refer is empty

func (FieldRef) GetName

func (v FieldRef) GetName(titleFirst bool) string

GetName returns Name of the elem

func (*FieldRef) SetString

func (v *FieldRef) SetString(s string)

SetString set a string to Value

func (FieldRef) String

func (v FieldRef) String() string

String convert v to string

type FlexJSONObject

type FlexJSONObject = jsonx.FlexJSONObject

FlexJSONObject exports

type FmtAPIInOut

type FmtAPIInOut struct {
	Method    string             `json:"method"`
	URL       string             `json:"url"`
	Input     InputNodeDetail    `json:"input"`
	Output    OutputNodeDetail   `json:"output"`
	SampleIn  [2]APISampleInput  `json:"sampleInput"`  // [0]normal [1]tilteFirst
	SampleOut [2]APISampleOutput `json:"sampleOutput"` // [0]normal [1]tilteFirst
}

FmtAPIInOut is the formated API input and output

func (*FmtAPIInOut) DelayedJSONDecode

func (d *FmtAPIInOut) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (*FmtAPIInOut) SetAccessURL

func (d *FmtAPIInOut) SetAccessURL(apiPath string)

SetAccessURL update the api access path

type GenSampler

type GenSampler interface {
	GenSample(val interface{}, titleFirst bool) value.JSONValue
}

GenSampler represents value that can generate sample JSON value

type InputNodeDetail

type InputNodeDetail struct {
	Inputs []ValueDefine `json:"inputs,omitempty"` // input from header, path, body or uri(GET)
	Consts ValueSet      `json:"consts,omitempty"` // const values provide by arrange
}

InputNodeDetail represents the detail of an input node.

func (*InputNodeDetail) DelayedJSONDecode

func (d *InputNodeDetail) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

type InputValue

type InputValue struct {
	//Value
	// type of this value:
	// number|string|boolean|object|array|arrayelem|null|undefined|field|
	// mergeobj|filter|expr|exprcmp|exprsel|exprgroup
	Type  Enum   `json:"type"`
	Name  string `json:"name,omitempty"` // new name of this value
	Title string `json:"title,omitempty"`
	Desc  string `json:"desc,omitempty"` // description of this value

	Appendix bool `json:"$appendix$,omitempty"` // NOTE: Appendix value, platform only
	Required bool `json:"required,omitempty"`   // required

	Field FieldRef       `json:"field,omitempty"` // field refer for this value, eg: "req1.data.x"
	Data  FlexJSONObject `json:"data,omitempty"`  // specific value for non-field content

	In Enum `json:"in"` // header|path|body
}

InputValue represent a const value input

func (InputValue) CreateSampleData

func (v InputValue) CreateSampleData(val interface{}, titleFirst bool) value.JSONValue

CreateSampleData generate a sample JSON value

func (*InputValue) DelayedJSONDecode

func (v *InputValue) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (InputValue) DenyFieldRefer

func (v InputValue) DenyFieldRefer() error

DenyFieldRefer assert this value don't refer a field value

func (*InputValue) Empty

func (v *InputValue) Empty() bool

Empty check if the value is empty

func (InputValue) GetAsString

func (v InputValue) GetAsString() string

GetAsString return Value as string if it contains that.

func (InputValue) GetName

func (v InputValue) GetName(titleFirst bool) string

GetName return name of input value

type NamedType

type NamedType = factory.NamedType

NamedType exports

type NamedValue

type NamedValue interface {
	GetName(titleFirst bool) string // get name of this element
}

NamedValue define a value with name

type OutputNodeDetail

type OutputNodeDetail struct {
	Header ValueSet      `json:"header,omitempty"` // output from header
	Body   Value         `json:"body,omitempty"`   // output from body
	Doc    []ValueDefine `json:"doc,omitempty"`    // output from body, for doc only
}

OutputNodeDetail represents detail of an output node

func (*OutputNodeDetail) DelayedJSONDecode

func (d *OutputNodeDetail) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

type RequestArgs

type RequestArgs struct {
	Name         string      // Name of the request node
	URL          string      // URL of a request
	EncodingPoly string      // Content-Type, of poly call
	EncodingIn   string      // Content-Type of request api, json/xml/yaml
	Body         []byte      // request body
	Header       http.Header // request header
	Action       string      // action of this request
	// contains filtered or unexported fields
}

RequestArgs represents a request parament of a request

type Stringer

type Stringer interface {
	String() string
	SetString(s string)
}

Stringer define an interface with String()

func NewStringer

func NewStringer(v string, kind Enum) Stringer

NewStringer create a string-like value

type Stringifier

type Stringifier interface {
	String() string
}

Stringifier is an interface to convert to string only

type SwagConstValue

type SwagConstValue = InputValue

SwagConstValue is predef value

type SwagConstValueSet

type SwagConstValueSet = ValueSet

SwagConstValueSet is predef value set

type ValAction

type ValAction ValString

ValAction represents action string

func (*ValAction) DelayedJSONDecode

func (v *ValAction) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (*ValAction) SetString

func (v *ValAction) SetString(s string)

SetString set a string to Value

func (ValAction) String

func (v ValAction) String() string

String convert v to string

func (ValAction) TypeName

func (v ValAction) TypeName() string

TypeName returns name of the type

type ValArray

type ValArray []Value

ValArray represents an array value, [...]

func (*ValArray) DelayedJSONDecode

func (v *ValArray) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValArray) GenSample

func (v ValArray) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (ValArray) TypeName

func (v ValArray) TypeName() string

TypeName returns name of the type

type ValArrayString

type ValArrayString []string

ValArrayString enable parse a single string as string array

func (*ValArrayString) DelayedJSONDecode

func (v *ValArrayString) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValArrayString) GenSample

func (v ValArrayString) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (ValArrayString) MarshalJSON

func (v ValArrayString) MarshalJSON() ([]byte, error)

MarshalJSON encoding array as single string

func (*ValArrayString) SetString

func (v *ValArrayString) SetString(s string)

SetString decode string as ValArrayString

func (ValArrayString) String

func (v ValArrayString) String() string

String encode ValArrayString as string

func (ValArrayString) TypeName

func (v ValArrayString) TypeName() string

TypeName returns name of the type

func (*ValArrayString) UnmarshalJSON

func (v *ValArrayString) UnmarshalJSON(data []byte) error

UnmarshalJSON splist data as string array

type ValBoolean

type ValBoolean ValString

ValBoolean represents boolean value

func (*ValBoolean) DelayedJSONDecode

func (v *ValBoolean) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValBoolean) GenSample

func (v ValBoolean) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (*ValBoolean) SetString

func (v *ValBoolean) SetString(s string)

SetString set a string to Value

func (ValBoolean) String

func (v ValBoolean) String() string

String convert v to string

func (ValBoolean) TypeName

func (v ValBoolean) TypeName() string

TypeName returns name of the type

type ValNumber

type ValNumber ValString

ValNumber represents number value, deal as string

func (*ValNumber) DelayedJSONDecode

func (v *ValNumber) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValNumber) GenSample

func (v ValNumber) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (*ValNumber) SetString

func (v *ValNumber) SetString(s string)

SetString set a string to Value

func (ValNumber) String

func (v ValNumber) String() string

String convert v to string

func (ValNumber) TypeName

func (v ValNumber) TypeName() string

TypeName returns name of the type

type ValObject

type ValObject ValArray

ValObject represents an object value, {...}

func (*ValObject) DelayedJSONDecode

func (v *ValObject) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValObject) GenSample

func (v ValObject) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (ValObject) TypeName

func (v ValObject) TypeName() string

TypeName returns name of the type

type ValString

type ValString string

ValString represents string value

func (*ValString) DelayedJSONDecode

func (v *ValString) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValString) GenSample

func (v ValString) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (*ValString) SetString

func (v *ValString) SetString(s string)

SetString set a string to Value

func (ValString) String

func (v ValString) String() string

String convert v to string

func (ValString) TypeName

func (v ValString) TypeName() string

TypeName returns name of the type

type ValTimestamp

type ValTimestamp ValString

ValTimestamp represents timestamp value

func (*ValTimestamp) DelayedJSONDecode

func (v *ValTimestamp) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValTimestamp) GenSample

func (v ValTimestamp) GenSample(val interface{}, titleFirst bool) value.JSONValue

GenSample generate a sample JSON value

func (*ValTimestamp) SetString

func (v *ValTimestamp) SetString(s string)

SetString set a string to Value

func (ValTimestamp) String

func (v ValTimestamp) String() string

String convert v to string

func (ValTimestamp) TypeName

func (v ValTimestamp) TypeName() string

TypeName returns name of the type

type Value

type Value struct {
	// type of this value:
	// number|string|boolean|object|array|array_elem|array_string_elem|array_string|
	// undefined|null|mergeobj|filter|path|header|skey|action|signature|timestamp|
	// field|expr|exprcmp|exprsel|exprfunc|exprgroup|direct_expr
	Type  Enum   `json:"type"`
	Name  string `json:"name"` // new name of this value
	Title string `json:"title,omitempty"`
	Desc  string `json:"desc,omitempty"` // description of this value

	Appendix bool `json:"$appendix$,omitempty"` // NOTE: Appendix value, platform only
	Required bool `json:"required,omitempty"`   // required

	Field FieldRef       `json:"field,omitempty"` // field refer for this value, eg: "req1.data.x"
	Data  FlexJSONObject `json:"data,omitempty"`  // specific value for non-field content
}

Value represents a value with given type It use Field value firstly.

func (Value) CreateSampleData

func (v Value) CreateSampleData(val interface{}, titleFirst bool) value.JSONValue

CreateSampleData generate a sample JSON value

func (*Value) DelayedJSONDecode

func (v *Value) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (Value) DenyFieldRefer

func (v Value) DenyFieldRefer() error

DenyFieldRefer assert this value don't refer a field value

func (Value) Empty

func (v Value) Empty() bool

Empty check if the value is empty

func (Value) GetAsString

func (v Value) GetAsString() string

GetAsString return Value as string if it contains that.

func (Value) GetName

func (v Value) GetName(titleFirst bool) string

GetName returns Name of the value. It returns field name if it is a filed value and Nanme not set.

type ValueDefine

type ValueDefine struct {
	InputValue          //value
	Key        bool     `json:"key,omitempty"`     // key field, for name check of referenced
	Default    string   `json:"default,omitempty"` // default value
	Mock       string   `json:"mock,omitempty"`    // mock value
	Enums      []string `json:"enums,omitempty"`   // valid value enum of this input
	Ranges     []string `json:"ranges,omitempty"`  // valid value ranges [min,max)[min,max)... of this input
}

ValueDefine represents the value of an input.

type ValueSet

type ValueSet []InputValue

ValueSet represents a set of value for input

func (*ValueSet) AddExKV

func (v *ValueSet) AddExKV(key, value string, kind, in Enum) error

AddExKV add or update a named string value in this object without type check

func (*ValueSet) AddKV

func (v *ValueSet) AddKV(key, value string, kind, in Enum) error

AddKV add or update a named string value in this object

func (*ValueSet) DelayedJSONDecode

func (v *ValueSet) DelayedJSONDecode() error

DelayedJSONDecode delay unmarshal flex json object

func (ValueSet) GetAction

func (v ValueSet) GetAction() *SwagConstValue

GetAction return the action predef value

func (ValueSet) PrepareRequest

func (v ValueSet) PrepareRequest(args *RequestArgs) error

PrepareRequest solve the input parameters from predefined values

func (*ValueSet) ReplacePathArgs

func (s *ValueSet) ReplacePathArgs(srcURL string, name string) (string, error)

ReplacePathArgs replace args in path from the input values

func (*ValueSet) ResolvePathArgs

func (s *ValueSet) ResolvePathArgs(srcURL string, nodeName string) (string, []string, error)

ResolvePathArgs repalce the path with fmt string and return it's fmt args. eg: "/api/:x" => ("/api/%v", ["$x"])

Jump to

Keyboard shortcuts

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