ir

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintGoValue added in v0.15.0

func PrintGoValue(val interface{}) string

PrintGoValue prints given value as Go value.

Types

type Content

type Content struct {
	ContentType ContentType
	Type        *Type
}

type ContentType

type ContentType string

ContentType of body.

const (
	// ContentTypeJSON is ContentType for json.
	ContentTypeJSON ContentType = "application/json"
	// ContentTypeOctetStream is ContentType for binary.
	ContentTypeOctetStream ContentType = "application/octet-stream"
)

func (ContentType) EncodedDataTypeGo

func (t ContentType) EncodedDataTypeGo() string

func (ContentType) JSON

func (t ContentType) JSON() bool

func (ContentType) Name

func (t ContentType) Name() string

func (ContentType) OctetStream

func (t ContentType) OctetStream() bool

func (ContentType) String added in v0.15.0

func (t ContentType) String() string

type Default added in v0.15.0

type Default struct {
	Value interface{}
	Set   bool
}

Default represents default value.

func (Default) IsNil added in v0.15.0

func (d Default) IsNil() bool

IsNil whether value is set, but null.

type EnumVariant

type EnumVariant struct {
	Name  string
	Value interface{}
}

func (*EnumVariant) ValueGo

func (v *EnumVariant) ValueGo() string

type Field

type Field struct {
	Name string
	Type *Type
	Tag  Tag
	Spec *jsonschema.Property
}

Field of structure.

func (Field) Default added in v0.15.0

func (f Field) Default() Default

Default returns default value of this field, if it is set.

func (Field) GoDoc added in v0.10.0

func (f Field) GoDoc() []string

GoDoc returns field godoc.

type GenericVariant

type GenericVariant struct {
	Nullable bool
	Optional bool
}

func (GenericVariant) Any

func (v GenericVariant) Any() bool

func (GenericVariant) Name

func (v GenericVariant) Name() string

func (GenericVariant) NullableOptional

func (v GenericVariant) NullableOptional() bool

func (GenericVariant) OnlyNullable

func (v GenericVariant) OnlyNullable() bool

func (GenericVariant) OnlyOptional

func (v GenericVariant) OnlyOptional() bool

type JSON

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

JSON specifies json encoding and decoding for Type.

func (JSON) Decode added in v0.15.0

func (j JSON) Decode() string

func (JSON) Fields

func (j JSON) Fields() (fields JSONFields)

Fields return all fields of Type that should be encoded via json.

func (JSON) Fn

func (j JSON) Fn() string

Fn returns jx.Encoder or jx.Decoder method name.

If blank, value cannot be encoded with single method call.

func (JSON) Format

func (j JSON) Format() string

Format returns format name for handling json encoding or decoding.

Mostly used for encoding or decoding of string formats, like `json.EncodeUUID`, where UUID is Format.

func (JSON) IsBase64 added in v0.15.0

func (j JSON) IsBase64() bool

IsBase64 whether field has base64 encoding.

func (JSON) Sum

func (j JSON) Sum() SumJSON

Sum returns specification for parsing value as sum type.

func (JSON) Type

func (j JSON) Type() string

Type returns json value type that can represent Type.

E.g. string primitive can be represented by StringValue which is commonly returned from `i.WhatIsNext()` method. Blank string is returned if there is no appropriate json type.

type JSONFields added in v0.7.0

type JSONFields []*Field

func (JSONFields) FirstRequiredIndex added in v0.7.0

func (j JSONFields) FirstRequiredIndex() int

FirstRequiredIndex returns first required field index.

Or -1 if there is no required fields.

func (JSONFields) HasRequired added in v0.8.0

func (j JSONFields) HasRequired() bool

HasRequired whether object has required fields

func (JSONFields) NotEmpty added in v0.9.0

func (j JSONFields) NotEmpty() bool

NotEmpty whether field slice is not empty.

func (JSONFields) RequiredMask added in v0.8.0

func (j JSONFields) RequiredMask() (r []uint8)

RequiredMask returns array of 64-bit bitmasks for required fields.

type Kind

type Kind string
const (
	KindPrimitive Kind = "primitive"
	KindArray     Kind = "array"
	KindMap       Kind = "map"
	KindAlias     Kind = "alias"
	KindEnum      Kind = "enum"
	KindStruct    Kind = "struct"
	KindPointer   Kind = "pointer"
	KindInterface Kind = "interface"
	KindGeneric   Kind = "generic"
	KindSum       Kind = "sum"
	KindAny       Kind = "any"
	KindStream    Kind = "stream"
)

type NilSemantic

type NilSemantic string

NilSemantic specifies nil value semantics.

const (
	NilInvalid  NilSemantic = "invalid"  // nil is invalid
	NilOptional NilSemantic = "optional" // nil is "no value"
	NilNull     NilSemantic = "null"     // nil is null
)

Possible nil value semantics.

func (NilSemantic) Invalid

func (n NilSemantic) Invalid() bool

func (NilSemantic) Null

func (n NilSemantic) Null() bool

func (NilSemantic) Optional

func (n NilSemantic) Optional() bool

type Operation

type Operation struct {
	Name        string
	Description string
	PathParts   []*PathPart
	Params      []*Parameter
	Request     *Request
	Response    *Response
	Spec        *oas.Operation
}

func (*Operation) CookieParams

func (op *Operation) CookieParams() []*Parameter

func (Operation) GoDoc added in v0.10.0

func (op Operation) GoDoc() []string

func (Operation) HasQueryParams added in v0.7.0

func (op Operation) HasQueryParams() bool

func (*Operation) HeaderParams

func (op *Operation) HeaderParams() []*Parameter

func (*Operation) ListResponseTypes

func (op *Operation) ListResponseTypes() []ResponseInfo

func (Operation) PathParamIndex added in v0.8.0

func (op Operation) PathParamIndex(name string) int

func (*Operation) PathParams

func (op *Operation) PathParams() []*Parameter

func (Operation) PathParamsCount added in v0.8.0

func (op Operation) PathParamsCount() (r int)

func (*Operation) QueryParams

func (op *Operation) QueryParams() []*Parameter

type Parameter

type Parameter struct {
	Name string
	Type *Type
	Spec *oas.Parameter
}

func (Parameter) Default added in v0.15.0

func (op Parameter) Default() Default

Default returns default value of this field, if it is set.

func (Parameter) GoDoc added in v0.10.0

func (op Parameter) GoDoc() []string

type PathPart

type PathPart struct {
	Raw   string
	Param *Parameter
}

func (PathPart) String

func (p PathPart) String() string

type PrimitiveType

type PrimitiveType int
const (
	String PrimitiveType = iota
	ByteSlice
	Int
	Int8
	Int16
	Int32
	Int64
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Float32
	Float64
	Time
	Duration
	UUID
	IP
	URL
	Bool
)

func (PrimitiveType) IsString added in v0.7.0

func (p PrimitiveType) IsString() bool

IsString whether this type is string.

func (PrimitiveType) String

func (p PrimitiveType) String() string

type Request

type Request struct {
	Type     *Type
	Contents map[ContentType]*Type
	Spec     *oas.RequestBody
}

type Response

type Response struct {
	Type       *Type
	StatusCode map[int]*StatusResponse
	Default    *StatusResponse
}

type ResponseInfo

type ResponseInfo struct {
	Type        *Type
	StatusCode  int
	Default     bool
	ContentType ContentType
	NoContent   bool
}

type StatusResponse

type StatusResponse struct {
	Wrapped   bool
	NoContent *Type
	Contents  map[ContentType]*Type
	Spec      *oas.Response
}

func (StatusResponse) ResponseInfo

func (s StatusResponse) ResponseInfo() []ResponseInfo

type SumJSON

type SumJSON struct {
	Type SumJSONType
}

SumJSON specifies rules for parsing sum types in json.

func (SumJSON) Discriminator

func (s SumJSON) Discriminator() bool

func (SumJSON) Fields

func (s SumJSON) Fields() bool

func (SumJSON) Primitive

func (s SumJSON) Primitive() bool

func (SumJSON) String

func (s SumJSON) String() string

func (SumJSON) TypeDiscriminator

func (s SumJSON) TypeDiscriminator() bool

type SumJSONType

type SumJSONType byte
const (
	SumJSONPrimitive SumJSONType = iota
	SumJSONFields
	SumJSONDiscriminator
	SumJSONTypeDiscriminator
)

type SumSpec

type SumSpec struct {
	Unique []*Field
	// DefaultMapping is name of default mapping.
	//
	// Used for variant which has no unique fields.
	DefaultMapping string

	// Discriminator is field name of sum type discriminator.
	Discriminator string
	// Mapping is discriminator value -> variant mapping.
	Mapping []SumSpecMap

	// TypeDiscriminator denotes to distinguish variants by type.
	TypeDiscriminator bool
}

SumSpec for KindSum.

type SumSpecMap

type SumSpecMap struct {
	Key  string
	Type string
}

type Tag

type Tag struct {
	JSON string // json tag, empty for none
}

Tag of Field.

func (Tag) EscapedJSON added in v0.7.0

func (t Tag) EscapedJSON() string

EscapedJSON returns quoted and escaped JSON tag.

type Type

type Type struct {
	Doc              string              // ogen documentation
	Kind             Kind                // kind
	Name             string              // only for struct, alias, interface, enum
	Primitive        PrimitiveType       // only for primitive, enum
	AliasTo          *Type               // only for alias
	PointerTo        *Type               // only for pointer
	SumOf            []*Type             // only for sum
	SumSpec          SumSpec             // only for sum
	Item             *Type               // only for array, map
	EnumVariants     []*EnumVariant      // only for enum
	Fields           []*Field            // only for struct
	Implements       map[*Type]struct{}  // only for struct, alias, enum
	Implementations  map[*Type]struct{}  // only for interface
	InterfaceMethods map[string]struct{} // only for interface
	Schema           *jsonschema.Schema  // for all kinds except pointer, interface. Can be nil.
	NilSemantic      NilSemantic         // only for pointer
	GenericOf        *Type               // only for generic
	GenericVariant   GenericVariant      // only for generic
	Validators       Validators

	// Features contains a set of features the type must implement.
	// Available features: 'json', 'uri'.
	//
	// If some of these features are set, generator
	// generates additional encoding methods if needed.
	Features []string
}

func Alias

func Alias(name string, to *Type) *Type

func Any added in v0.11.0

func Any() *Type

func Array

func Array(item *Type, sem NilSemantic, schema *jsonschema.Schema) *Type

func Generic

func Generic(name string, of *Type, v GenericVariant) *Type

func Interface

func Interface(name string) *Type

func Pointer

func Pointer(to *Type, sem NilSemantic) *Type

func Primitive

func Primitive(typ PrimitiveType, schema *jsonschema.Schema) *Type

func Stream

func Stream(name string) *Type

func (*Type) AddFeature added in v0.10.0

func (t *Type) AddFeature(feature string)

func (*Type) AddMethod

func (t *Type) AddMethod(name string)

func (*Type) AdditionalPropsField added in v0.9.0

func (t *Type) AdditionalPropsField() string

AdditionalPropsField returns name of additional properties field.

func (Type) CanGeneric

func (t Type) CanGeneric() bool

CanGeneric reports whether Type can be boxed to KindGeneric.

func (*Type) CanHaveMethods added in v0.15.0

func (t *Type) CanHaveMethods() bool

func (*Type) CloneFeatures added in v0.10.0

func (t *Type) CloneFeatures() []string

func (Type) Default added in v0.15.0

func (t Type) Default() Default

Default returns default value of this type, if it is set.

func (Type) DefaultFields added in v0.15.0

func (t Type) DefaultFields() (r []*Field)

DefaultFields returns fields with default values.

func (*Type) EncodeFn

func (t *Type) EncodeFn() string

func (*Type) Equal

func (t *Type) Equal(target *Type) bool

Equal reports whether two types are equal.

func (*Type) Examples added in v0.10.1

func (t *Type) Examples() (r []string)

func (*Type) Format

func (t *Type) Format() bool

Format denotes whether custom formatting for Type is required while encoding or decoding.

TODO(ernado): can we use t.JSON here?

func (Type) FromString

func (t Type) FromString() string

func (*Type) Go

func (t *Type) Go() string

Go returns valid Go type for this Type.

func (Type) GoDoc added in v0.10.0

func (t Type) GoDoc() []string

GoDoc returns type godoc.

func (Type) HasDefaultFields added in v0.15.0

func (t Type) HasDefaultFields() bool

HasDefaultFields whether type has fields with default values.

func (*Type) HasFeature added in v0.10.0

func (t *Type) HasFeature(feature string) bool

func (*Type) Implement

func (t *Type) Implement(i *Type)

func (*Type) Is

func (t *Type) Is(vs ...Kind) bool

func (*Type) IsAlias

func (t *Type) IsAlias() bool

func (*Type) IsAny added in v0.11.0

func (t *Type) IsAny() bool

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) IsEnum

func (t *Type) IsEnum() bool

func (*Type) IsFloat

func (t *Type) IsFloat() bool

func (*Type) IsGeneric

func (t *Type) IsGeneric() bool

func (*Type) IsInteger

func (t *Type) IsInteger() bool

func (*Type) IsInterface

func (t *Type) IsInterface() bool

func (*Type) IsMap added in v0.9.0

func (t *Type) IsMap() bool

func (*Type) IsNumeric

func (t *Type) IsNumeric() bool

func (*Type) IsPointer

func (t *Type) IsPointer() bool

func (*Type) IsPrimitive

func (t *Type) IsPrimitive() bool

func (*Type) IsStream

func (t *Type) IsStream() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsSum

func (t *Type) IsSum() bool

func (*Type) JSON

func (t *Type) JSON() JSON

JSON returns json encoding/decoding rules for t.

func (*Type) ListImplementations

func (t *Type) ListImplementations() []*Type

func (*Type) Methods

func (t *Type) Methods() []string

func (*Type) MustField

func (t *Type) MustField(name string) *Field

func (*Type) NamePostfix added in v0.15.0

func (t *Type) NamePostfix() string

NamePostfix returns name postfix for optional wrapper.

func (*Type) NeedValidation

func (t *Type) NeedValidation() bool

func (*Type) Pointer

func (t *Type) Pointer(sem NilSemantic) *Type

func (*Type) ReceiverType added in v0.7.0

func (t *Type) ReceiverType() string

func (*Type) RecursiveTo

func (t *Type) RecursiveTo(target *Type) bool

func (*Type) SetFieldType added in v0.15.0

func (t *Type) SetFieldType(name string, newT *Type)

func (Type) String

func (t Type) String() string

func (Type) ToString

func (t Type) ToString() string

func (*Type) Unimplement

func (t *Type) Unimplement(i *Type)

type TypeDiscriminator

type TypeDiscriminator struct {
	Kind      Kind
	Primitive PrimitiveType
}

func (TypeDiscriminator) Less

func (*TypeDiscriminator) Set

func (t *TypeDiscriminator) Set(s *Type)

type Validators

type Validators struct {
	String validate.String
	Int    validate.Int
	Array  validate.Array
	Object validate.Object
}

func (*Validators) SetArray added in v0.12.0

func (v *Validators) SetArray(schema *jsonschema.Schema)

func (*Validators) SetInt added in v0.12.0

func (v *Validators) SetInt(schema *jsonschema.Schema)

func (*Validators) SetObject added in v0.12.0

func (v *Validators) SetObject(schema *jsonschema.Schema)

func (*Validators) SetString added in v0.12.0

func (v *Validators) SetString(schema *jsonschema.Schema) (err error)

Jump to

Keyboard shortcuts

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