swagger

package
v0.0.0-...-4bbce29 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootAddr = PropertyAddr{}

Functions

func CatesianProduct

func CatesianProduct[T any](params ...[]T) [][]T

func CatesianProductMap

func CatesianProductMap[T any](params map[string][]T) []map[string]T

func FlattenJSONValueObjectByAddr

func FlattenJSONValueObjectByAddr(obj JSONObject) map[string]JSONValue

func JSONValueValueMap

func JSONValueValueMap(l ...JSONValue) (map[string]*JSONValuePos, error)

JSONValueValueMap merges one or more JSONValue into a map whose key is the un-ambiguous leaf value of the input JSONValue(s). For the ambiguous leaf value (i.e. multiple properties among the JSONValue(s) have the same value), they are not included in the returning map.

func SchemaIsArray

func SchemaIsArray(schema *spec.Schema) bool

func SchemaIsEmptyObject

func SchemaIsEmptyObject(schema *spec.Schema) bool

func SchemaIsMap

func SchemaIsMap(schema *spec.Schema) bool

func SchemaIsObject

func SchemaIsObject(schema *spec.Schema) bool

Types

type Expander

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

func NewExpander

func NewExpander(ref spec.Ref, opt *ExpanderOption) (*Expander, error)

NewExpander create a expander for the schema referenced by the input json reference. The reference must be a normalized reference.

func NewExpanderFromOpRef

func NewExpanderFromOpRef(ref spec.Ref, opt *ExpanderOption) (*Expander, error)

NewExpanderFromOpRef create a expander for the successful response schema of an operation referenced by the input json reference. The reference must be a normalized reference to the operation.

func (*Expander) Expand

func (e *Expander) Expand() error

func (*Expander) Root

func (e *Expander) Root() *Property

type ExpanderCache

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

func NewExpanderCache

func NewExpanderCache() *ExpanderCache

type ExpanderOption

type ExpanderOption struct {
	EmptyObjAsStr bool
	Cache         *ExpanderCache
}

type JSONArray

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

func (JSONArray) JSONValue

func (arr JSONArray) JSONValue() interface{}

func (JSONArray) JSONValuePos

func (arr JSONArray) JSONValuePos() *JSONValuePos

type JSONObject

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

func (JSONObject) JSONValue

func (obj JSONObject) JSONValue() interface{}

func (JSONObject) JSONValuePos

func (obj JSONObject) JSONValuePos() *JSONValuePos

type JSONPrimitive

type JSONPrimitive[T primitiveType] struct {
	// contains filtered or unexported fields
}

func (JSONPrimitive[T]) JSONValue

func (p JSONPrimitive[T]) JSONValue() interface{}

func (JSONPrimitive[T]) JSONValuePos

func (p JSONPrimitive[T]) JSONValuePos() *JSONValuePos

type JSONValue

type JSONValue interface {
	JSONValue() interface{}

	// Only JSONPrimitive returns non-nil
	JSONValuePos() *JSONValuePos
}

func UnmarshalJSONToJSONValue

func UnmarshalJSONToJSONValue(b []byte, root *Property) (JSONValue, error)

type JSONValuePos

type JSONValuePos struct {
	RootModel  RootModelInfo     `json:"root_model"`
	Ref        jsonreference.Ref `json:"ref"`
	Addr       PropertyAddr      `json:"addr"`
	LinkLocal  string            `json:"link_local,omitempty"`
	LinkGithub string            `json:"link_github,omitempty"`
}

func (JSONValuePos) MarshalJSON

func (pos JSONValuePos) MarshalJSON() ([]byte, error)

func (JSONValuePos) String

func (pos JSONValuePos) String() string

func (*JSONValuePos) UnmarshalJSON

func (pos *JSONValuePos) UnmarshalJSON(b []byte) error

type PropWalkFunc

type PropWalkFunc func(p *Property) bool

PropWalkFunc is invoked during the property tree walking. If it returns false, it will stop walking at that property.

type Property

type Property struct {
	Schema *spec.Schema

	// The root model information that holds this property.
	RootModel RootModelInfo

	// Discriminator indicates the property name of the parent base schema's discriminator.
	// This only applies to property that is a variant schema.
	Discriminator string

	// DiscriminatorValue indicates the discriminator value.
	// This only applies to property that is a variant schema.
	DiscriminatorValue string

	// Children represents the child properties of an object
	// At most one of Children, Element and Variant is non nil
	Children map[string]*Property

	// Element represents the element property of an array or a map (additionalProperties of an object)
	// At most one of Children, Element and Variant is non nil
	Element *Property

	// Variant represents the current property is a polymorphic schema, which is then expanded to multiple variant schemas
	// At most one of Children, Element and Variant is non nil
	Variant map[string]*Property
	// contains filtered or unexported fields
}

func Monomorphization

func Monomorphization(prop *Property) []Property

func (*Property) IsMono

func (prop *Property) IsMono() bool

IsMono tests whether the Property is monomorphisized

func (Property) Name

func (prop Property) Name() string

func (Property) SchemaName

func (prop Property) SchemaName() string

func (Property) String

func (prop Property) String() string

func (*Property) Walk

func (prop *Property) Walk(fn PropWalkFunc)

Walk walks the property tree in depth first order

type PropertyAddr

type PropertyAddr []PropertyAddrStep

func MustParseAddr

func MustParseAddr(input string) PropertyAddr

func ParseAddr

func ParseAddr(input string) (*PropertyAddr, error)

func (PropertyAddr) Copy

func (addr PropertyAddr) Copy() PropertyAddr

func (PropertyAddr) Equal

func (addr PropertyAddr) Equal(oaddr PropertyAddr) bool

func (PropertyAddr) String

func (addr PropertyAddr) String() string

func (PropertyAddr) ToPointer

func (addr PropertyAddr) ToPointer() (jsonpointer.Pointer, error)

type PropertyAddrStep

type PropertyAddrStep struct {
	Type    PropertyAddrStepType
	Value   string
	Variant string
}

func (PropertyAddrStep) String

func (step PropertyAddrStep) String() string

type PropertyAddrStepType

type PropertyAddrStepType int
const (
	PropertyAddrStepTypeProp PropertyAddrStepType = iota
	PropertyAddrStepTypeIndex
)

type PropertyName

type PropertyName struct {
	Name    string
	Variant string
}

type RequestDescriptor

type RequestDescriptor struct {
	Method  string
	Path    string
	Version string
}

type Rnd

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

func NewRnd

func NewRnd(opt *RndOption) Rnd

func (*Rnd) NextInteger

func (rnd *Rnd) NextInteger(format string) int64

func (*Rnd) NextNumber

func (rnd *Rnd) NextNumber(format string) float64

func (*Rnd) NextString

func (rnd *Rnd) NextString(format string) string

type RndOption

type RndOption struct {
	InitString  string
	InitInteger int64
	InitNumber  float64

	InitTime time.Time
}

type RootModelInfo

type RootModelInfo struct {
	PathRef   jsonreference.Ref `json:"path_ref"`
	Operation string            `json:"operation"`
	Version   string            `json:"version"`
}

func (RootModelInfo) MarshalJSON

func (model RootModelInfo) MarshalJSON() ([]byte, error)

func (RootModelInfo) String

func (info RootModelInfo) String() string

func (*RootModelInfo) UnmarshalJSON

func (model *RootModelInfo) UnmarshalJSON(b []byte) error

type SynthDuplicateElement

type SynthDuplicateElement struct {
	Cnt  int
	Addr PropertyAddr
}

type Synthesizer

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

func NewSynthesizer

func NewSynthesizer(root *Property, rnd *Rnd, opt *SynthesizerOption) (*Synthesizer, error)

func (*Synthesizer) Synthesize

func (syn *Synthesizer) Synthesize() (interface{}, bool)

type SynthesizerOption

type SynthesizerOption struct {
	UseEnumValues     bool
	DuplicateElements []SynthDuplicateElement
}

type VariantInfo

type VariantInfo struct {
	Discriminator       string
	VariantValueToModel map[string]string
}

type VariantMap

type VariantMap map[string]VariantInfo

VariantMap maps the x-ms-discriminator-value to the model name in "/definitions". Note that the variant map is the plain translation of the swagger inheritance strucutre, it doesn't take cascaded variants into consideration. So always ensure use `Get()` to get the complete variant set of a model.

func NewVariantMap

func NewVariantMap(path string) (VariantMap, error)

func (VariantMap) Get

func (m VariantMap) Get(modelName string) (*VariantInfo, bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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