models

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayWithNoValidate

type ArrayWithNoValidate []httpext.Request

ArrayWithNoValidate A slice of NoValidateExternal external types.

If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method.

swagger:model ArrayWithNoValidate

func (ArrayWithNoValidate) ContextValidate

func (m ArrayWithNoValidate) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this array with no validate based on context it is used

func (ArrayWithNoValidate) Validate

func (m ArrayWithNoValidate) Validate(formats strfmt.Registry) error

Validate validates this array with no validate

type EmbeddedTime

type EmbeddedTime struct {
	timeext.Time
}

EmbeddedTime This type demonstrates how we can embed an external type and wraps the validation.

This is especially useful if you want to reuse some types from the standard library, such as `time.Time` or `json.RawMessage`.

swagger:model EmbeddedTime

func (EmbeddedTime) ContextValidate

func (m EmbeddedTime) ContextValidate(ctx context.Context, formats strfmt.Registry) error

func (EmbeddedTime) Validate

func (m EmbeddedTime) Validate(formats strfmt.Registry) error

type MapOfPrimitives

type MapOfPrimitives map[string]timeext.Duration

MapOfPrimitives A map of NoValidatePrimitive external types.

If the "noValidation" hint is omitted in the definition above, this code won't build because `time.Duration` has no `Validate` method.

swagger:model MapOfPrimitives

func (MapOfPrimitives) ContextValidate

func (m MapOfPrimitives) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this map of primitives based on context it is used

func (MapOfPrimitives) Validate

func (m MapOfPrimitives) Validate(formats strfmt.Registry) error

Validate validates this map of primitives

type MapWithNoValidate

type MapWithNoValidate map[string]httpext.Request

MapWithNoValidate A map of NoValidateExternal external types.

If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method.

swagger:model MapWithNoValidate

func (MapWithNoValidate) ContextValidate

func (m MapWithNoValidate) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this map with no validate based on context it is used

func (MapWithNoValidate) Validate

func (m MapWithNoValidate) Validate(formats strfmt.Registry) error

Validate validates this map with no validate

type MyCustomArray

type MyCustomArray []alternate.MyAlternateType

MyCustomArray This generate an array type in models, based on the external type.

[]alternate.MyAlternateType

The validation method of the external type is called by the generated array.

swagger:model MyCustomArray

func (MyCustomArray) ContextValidate

func (m MyCustomArray) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this my custom array based on context it is used

func (MyCustomArray) Validate

func (m MyCustomArray) Validate(formats strfmt.Registry) error

Validate validates this my custom array

type MyCustomArrayNullable

type MyCustomArrayNullable []*alternate.MyAlternateType

MyCustomArrayNullable This generate an array type in models, based on the external type. Notice the impact of the nullable hint (equivalent to x-nullable at the type level), to produce a slice of pointers.

[]*alternate.MyAlternateType

swagger:model MyCustomArrayNullable

func (MyCustomArrayNullable) ContextValidate

func (m MyCustomArrayNullable) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this my custom array nullable based on context it is used

func (MyCustomArrayNullable) Validate

func (m MyCustomArrayNullable) Validate(formats strfmt.Registry) error

Validate validates this my custom array nullable

type MyCustomMap

type MyCustomMap map[string]map[string]alternate.MyAlternateType

MyCustomMap This generate a map type in models, based on the external type.

MyCustomMap map[string]map[string]alternate.MyAlternateType

The validation method of the external type is called by the generated map.

swagger:model MyCustomMap

func (MyCustomMap) ContextValidate

func (m MyCustomMap) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this my custom map based on context it is used

func (MyCustomMap) Validate

func (m MyCustomMap) Validate(formats strfmt.Registry) error

Validate validates this my custom map

type MyCustomMapNullable

type MyCustomMapNullable map[string]map[string]*alternate.MyAlternateType

MyCustomMapNullable This generate a map type in models, based on the external type. Notice the impact of the x-nullable directive, to produce a map of pointers.

MapNullable map[string]map[string]*alternate.MyAlternateType

swagger:model MyCustomMapNullable

func (MyCustomMapNullable) ContextValidate

func (m MyCustomMapNullable) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this my custom map nullable based on context it is used

func (MyCustomMapNullable) Validate

func (m MyCustomMapNullable) Validate(formats strfmt.Registry) error

Validate validates this my custom map nullable

type MyExtCollection

type MyExtCollection []go_ext.MyExtType

MyExtCollection This type demonstrates the import generation with name mangling

swagger:model MyExtCollection

func (MyExtCollection) ContextValidate

func (m MyExtCollection) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validate this my ext collection based on the context it is used

func (MyExtCollection) Validate

func (m MyExtCollection) Validate(formats strfmt.Registry) error

Validate validates this my ext collection

type MyInteger

type MyInteger int

MyInteger ...

func (MyInteger) ContextValidate

func (MyInteger) ContextValidate(context.Context, strfmt.Registry) error

ContextValidate MyInteger

func (MyInteger) Validate

func (MyInteger) Validate(strfmt.Registry) error

Validate MyInteger

type MyInterfaceObject

type MyInterfaceObject struct {

	// iface1
	Iface1 fred.MyAlternateInterface `json:"iface1,omitempty"`

	// Demonstrates the impact of the "interface" hint: no validation is called on iface2,
	// and no pointer is generated in spite of the "required" directive.
	//
	// The generated object validation checks for the "required" directive.
	//
	// Without the hint, the generator assumes a Validatable object, with pointer, which may
	// not build, depending on how the external type is defined.
	//
	// Required: true
	Iface2 fred.MyAlternateInterface `json:"iface2"`

	// Demonstrates the impact of the "noValidation" hint.
	//
	// Notice how we avoid the generation of a pointer on the required json.RawMessage (which is a []byte)
	// with the "nullable" hint.
	//
	// Notice that the "json" package is automatically deconflicted from other standard imports with a distinct alias.
	//
	// Required: true
	Iface3 jsonext.RawMessage `json:"iface3"`
}

MyInterfaceObject This object demonstrates several ways to refer to an external interface.

The generated code behaves as it is an interface{}: no pointers are generated, and no valication is required.

swagger:model MyInterfaceObject

func (*MyInterfaceObject) ContextValidate

func (m *MyInterfaceObject) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this my interface object based on context it is used

func (*MyInterfaceObject) MarshalBinary

func (m *MyInterfaceObject) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (*MyInterfaceObject) UnmarshalBinary

func (m *MyInterfaceObject) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*MyInterfaceObject) Validate

func (m *MyInterfaceObject) Validate(formats strfmt.Registry) error

Validate validates this my interface object

type MyOtherType

type MyOtherType struct{}

MyOtherType ...

func (MyOtherType) ContextValidate

func (MyOtherType) ContextValidate(context.Context, strfmt.Registry) error

ContextValidate MyOtherType

func (MyOtherType) Validate

func (MyOtherType) Validate(strfmt.Registry) error

Validate MyOtherType

type MyReaderObject

type MyReaderObject struct {

	// reader1
	// Format: binary
	Reader1 MyStreamer `json:"reader1,omitempty"`

	// In line definition of the external type.
	//
	// Notice that we have provided some information in the spec, so the generator
	// can infer we want it to be understood as an io.Reader, with no validation.
	//
	// Format: binary
	Reader2 alternate.MyAlternateStreamer `json:"reader2,omitempty"`

	// In line definition of the external type.
	//
	// Notice that we have provided some information in the spec, as a hint in the extension
	// rather than in the type definition.
	//
	// So this will be documented as an object, but the generated code knows this is a stream.
	//
	Reader3 fred.MyAlternateStreamer `json:"reader3,omitempty"`
}

MyReaderObject This object demonstrates several ways to refer to an external interface (here assumed akin to io.Reader). MarshalBinary() methods are generated. No validation is expected on binary format.

swagger:model MyReaderObject

func (*MyReaderObject) ContextValidate

func (m *MyReaderObject) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this my reader object based on context it is used

func (*MyReaderObject) MarshalBinary

func (m *MyReaderObject) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (*MyReaderObject) UnmarshalBinary

func (m *MyReaderObject) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*MyReaderObject) Validate

func (m *MyReaderObject) Validate(formats strfmt.Registry) error

Validate validates this my reader object

type MyStreamer

type MyStreamer io.Reader

MyStreamer ...

type MyString

type MyString string

MyString ...

func (MyString) ContextValidate

func (MyString) ContextValidate(context.Context, strfmt.Registry) error

ContextValidate MyInteger

func (MyString) Validate

func (MyString) Validate(strfmt.Registry) error

Validate MyString

type MyTuple

type MyTuple struct {

	// p0
	// Required: true
	P0 *MyType `json:"-"` // custom serializer

	// Second element of the tuple, defined as follows.
	//
	// P1 *fred.MyAlternateType `json:"-"` // custom serializer
	//
	// Required: true
	P1 *fred.MyAlternateType `json:"-"` // custom serializer

	// Additional items to a tuple, from an external type.
	// This defines the following field in the tuple
	//
	// MyTupleItems []map[string]fred.MyAlternateType
	//
	MyTupleItems []map[string]fred.MyAlternateType `json:"-"`
}

MyTuple Demonstrates references to some external type in the context of a tuple.

Notice that "additionalItems" is not a construct that pass swagger validation, but is supported by go-swagger.

swagger:model MyTuple

func (*MyTuple) ContextValidate

func (m *MyTuple) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validate this my tuple based on the context it is used

func (*MyTuple) MarshalBinary

func (m *MyTuple) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (MyTuple) MarshalJSON

func (m MyTuple) MarshalJSON() ([]byte, error)

MarshalJSON marshals this tuple type into a JSON array

func (*MyTuple) UnmarshalBinary

func (m *MyTuple) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*MyTuple) UnmarshalJSON

func (m *MyTuple) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals this tuple type from a JSON array

func (*MyTuple) Validate

func (m *MyTuple) Validate(formats strfmt.Registry) error

Validate validates this my tuple

type MyType

type MyType string

MyType is a type manually added to the models package (NOT GENERATED)

func (MyType) ContextValidate

func (MyType) ContextValidate(context.Context, strfmt.Registry) error

ContextValidate MyType

func (MyType) Validate

func (MyType) Validate(strfmt.Registry) error

Validate MyType

type ObjectWithNoValidate

type ObjectWithNoValidate struct {

	// my mandatory request
	// Required: true
	MyMandatoryRequest *httpext.Request `json:"myMandatoryRequest"`

	// my request
	MyRequest httpext.Request `json:"myRequest,omitempty"`
}

ObjectWithNoValidate A reference to the NoValidateExternal external type.

If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method.

swagger:model ObjectWithNoValidate

func (*ObjectWithNoValidate) ContextValidate

func (m *ObjectWithNoValidate) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this object with no validate based on context it is used

func (*ObjectWithNoValidate) MarshalBinary

func (m *ObjectWithNoValidate) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (*ObjectWithNoValidate) UnmarshalBinary

func (m *ObjectWithNoValidate) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*ObjectWithNoValidate) Validate

func (m *ObjectWithNoValidate) Validate(formats strfmt.Registry) error

Validate validates this object with no validate

type TupleWithNoValidate

type TupleWithNoValidate struct {

	// p0
	// Required: true
	P0 *httpext.Request `json:"-"` // custom serializer

	// p1
	// Required: true
	P1 *httpext.Request `json:"-"` // custom serializer

	// tuple with no validate items
	TupleWithNoValidateItems []httpext.Request `json:"-"`
}

TupleWithNoValidate A tuple of NoValidateExternal external types.

If the "noValidation" hint is omitted in the definition above, this code won't build because `http.Request` has no `Validate` method.

Notice that "additionalItems" is not a construct that pass swagger validation, but is supported by go-swagger.

swagger:model TupleWithNoValidate

func (*TupleWithNoValidate) ContextValidate

func (m *TupleWithNoValidate) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validates this tuple with no validate based on context it is used

func (*TupleWithNoValidate) MarshalBinary

func (m *TupleWithNoValidate) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (TupleWithNoValidate) MarshalJSON

func (m TupleWithNoValidate) MarshalJSON() ([]byte, error)

MarshalJSON marshals this tuple type into a JSON array

func (*TupleWithNoValidate) UnmarshalBinary

func (m *TupleWithNoValidate) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*TupleWithNoValidate) UnmarshalJSON

func (m *TupleWithNoValidate) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals this tuple type from a JSON array

func (*TupleWithNoValidate) Validate

func (m *TupleWithNoValidate) Validate(formats strfmt.Registry) error

Validate validates this tuple with no validate

type Zzz

type Zzz struct {

	// This property defines an array of external types (in the same package).
	//
	// []MyOtherType
	//
	// The maxItems validation is generated and the external validation is called for every item.
	//
	// Max Items: 15
	Beta []MyOtherType `json:"beta"`

	// A type is provided (integer), and the implementation is an external type in the same package.
	//
	// The maximum validation remains documentary and is ignored by the generated code.
	//
	// Maximum: 15
	Delta MyInteger `json:"delta,omitempty"`

	// epsilon
	Epsilon []custom.MyAlternateType `json:"epsilon"`

	// Property defined as an external type from package "fred"
	//
	Gamma fred.MyAlternateInteger `json:"gamma,omitempty"`

	// meta
	Meta MyType `json:"meta,omitempty"`

	// This property defines an array of external types (in the same package).
	//
	// []MyOtherType
	//
	// The maxItems validation is generated and the external validation is called for every item.
	//
	// Max Items: 15
	NullableBeta []*MyOtherType `json:"nullableBeta"`

	// A type is provided (integer), and the implementation is an external type in the same package.
	//
	// The maximum validation remains documentary and is ignored by the generated code.
	//
	// NullableDelta *MyInteger
	//
	// Maximum: 15
	NullableDelta *MyInteger `json:"nullableDelta,omitempty"`

	// In this example, items are made nullable.
	//
	// NullableEpsilon []*custom.MyAlternateType `json:"nullableEpsilon"`
	//
	NullableEpsilon []*custom.MyAlternateType `json:"nullableEpsilon"`

	// Property defined as an external type from package "fred", with a nullable hint for the
	// external type.
	//
	// NullableGamma *fred.MyAlternateInteger `json:"nullableGamma,omitempty"`
	//
	NullableGamma *fred.MyAlternateInteger `json:"nullableGamma,omitempty"`

	// nullable meta
	NullableMeta MyType `json:"nullableMeta,omitempty"`

	// req beta
	// Required: true
	ReqBeta []MyOtherType `json:"reqBeta"`

	// req delta
	// Required: true
	ReqDelta *MyInteger `json:"reqDelta"`

	// req epsilon
	// Required: true
	ReqEpsilon []custom.MyAlternateType `json:"reqEpsilon"`

	// req gamma
	// Required: true
	ReqGamma *fred.MyAlternateInteger `json:"reqGamma"`

	// req meta
	// Required: true
	ReqMeta *MyType `json:"reqMeta"`
}

Zzz This demonstrates variations in generated code, depending on how properties are declared.

Some properties are directly based on some external type and some other define collections (slices, maps) of these external types.

Notice the use of pointers for required properties, but not for slices or maps.

In addition, it demonstrates how pointer generation may be controlled with the nullable hint or the x-nullable extension.

type Zzz struct {
	Beta []MyOtherType `json:"beta"`
	Delta MyInteger `json:"delta,omitempty"`
	Epsilon []custom.MyAlternateType `json:"epsilon"`
	Gamma fred.MyAlternateInteger `json:"gamma,omitempty"`
	Meta MyType `json:"meta,omitempty"`

	NullableBeta []*MyOtherType `json:"nullableBeta"`
	NullableDelta *MyInteger `json:"nullableDelta,omitempty"`
	NullableEpsilon []*custom.MyAlternateType `json:"nullableEpsilon"`
	NullableGamma *fred.MyAlternateInteger `json:"nullableGamma,omitempty"`
	NullableMeta MyType `json:"nullableMeta,omitempty"`

	ReqBeta []MyOtherType `json:"reqBeta"`
	ReqDelta *MyInteger `json:"reqDelta"`
	ReqEpsilon []custom.MyAlternateType `json:"reqEpsilon"`
	ReqGamma *fred.MyAlternateInteger `json:"reqGamma"`
	ReqMeta *MyType `json:"reqMeta"`
}

swagger:model Zzz

func (*Zzz) ContextValidate

func (m *Zzz) ContextValidate(ctx context.Context, formats strfmt.Registry) error

ContextValidate validate this zzz based on the context it is used

func (*Zzz) MarshalBinary

func (m *Zzz) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (*Zzz) UnmarshalBinary

func (m *Zzz) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*Zzz) Validate

func (m *Zzz) Validate(formats strfmt.Registry) error

Validate validates this zzz

Jump to

Keyboard shortcuts

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