Documentation ¶
Index ¶
- func EdgeViewName(n *gen.Type, e *gen.Edge, op Operation) (string, error)
- func GroupsForOperation(a gen.Annotations, op Operation) (serialization.Groups, error)
- func OgenSchema(f *gen.Field) (*ogen.Schema, error)
- func ViewName(n *gen.Type, op Operation) (string, error)
- func ViewNameEdge(vn string, e *gen.Edge) (string, error)
- func Views(g *gen.Graph) (map[string]*View, error)
- type Annotation
- func CreateOperation(opts ...OperationConfigOption) Annotation
- func DeleteOperation(opts ...OperationConfigOption) Annotation
- func EdgeAnnotation(e *gen.Edge) (*Annotation, error)
- func Example(v interface{}) Annotation
- func FieldAnnotation(f *gen.Field) (*Annotation, error)
- func Groups(gs ...string) Annotation
- func ListOperation(opts ...OperationConfigOption) Annotation
- func ReadOnly(readonly bool) Annotation
- func ReadOperation(opts ...OperationConfigOption) Annotation
- func Schema(s *ogen.Schema) Annotation
- func SchemaAnnotation(n *gen.Type) (*Annotation, error)
- func Skip(skip bool) Annotation
- func UpdateOperation(opts ...OperationConfigOption) Annotation
- type Config
- type Edge
- type Edges
- type Extension
- type ExtensionOption
- func DefaultPolicy(p Policy) ExtensionOption
- func MaxItemsPerPage(n int) ExtensionOption
- func MinItemsPerPage(n int) ExtensionOption
- func Mutations(ms ...MutateFunc) ExtensionOption
- func SimpleModels() ExtensionOption
- func Spec(spec *ogen.Spec) ExtensionOption
- func WriteTo(out io.Writer) ExtensionOption
- type MutateFunc
- type Operation
- type OperationConfig
- type OperationConfigOption
- type Policy
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EdgeViewName ¶
EdgeViewName returns the name for a view for a given 2nd leve operation on a gen.Edge.
func GroupsForOperation ¶
func GroupsForOperation(a gen.Annotations, op Operation) (serialization.Groups, error)
GroupsForOperation returns the requested groups as defined on the given Annotations for the Operation.
func OgenSchema ¶
OgenSchema returns the ogen.Schema to use for the given gen.Field.
func ViewNameEdge ¶
ViewNameEdge returns the name for a view that is an edge on the given node.
Types ¶
type Annotation ¶
type Annotation struct { // Groups holds the serialization groups to use on this field / edge. Groups serialization.Groups // OpenAPI Specification example value for a schema field. Example interface{} // OpenAPI Specification schema to use for a schema field. Schema *ogen.Schema // Create has meta information about a creation operation. Create OperationConfig // Read has meta information about a read operation. Read OperationConfig // Update has meta information about an update operation. Update OperationConfig // Delete has meta information about a delete operation. Delete OperationConfig // List has meta information about a list operation. List OperationConfig // ReadOnly specifies that the field/edge is read only (no create/update parameter) ReadOnly bool // Skip specifies that the field will be ignored in spec. Skip bool }
Annotation annotates fields and edges with metadata for spec generation.
func CreateOperation ¶
func CreateOperation(opts ...OperationConfigOption) Annotation
CreateOperation returns a create operation annotation.
func DeleteOperation ¶
func DeleteOperation(opts ...OperationConfigOption) Annotation
DeleteOperation returns a delete operation annotation.
func EdgeAnnotation ¶
func EdgeAnnotation(e *gen.Edge) (*Annotation, error)
EdgeAnnotation returns the Annotation on the given gen.Edge.
func FieldAnnotation ¶
func FieldAnnotation(f *gen.Field) (*Annotation, error)
FieldAnnotation returns the Annotation on the given gen.Field.
func Groups ¶
func Groups(gs ...string) Annotation
Groups returns a OperationConfigOption that adds the given serialization groups to a OperationConfig.
func ListOperation ¶
func ListOperation(opts ...OperationConfigOption) Annotation
ListOperation returns a list operation annotation.
func ReadOnly ¶
func ReadOnly(readonly bool) Annotation
ReadOnly returns a read only field/edge annotation
func ReadOperation ¶
func ReadOperation(opts ...OperationConfigOption) Annotation
ReadOperation returns a read operation annotation.
func SchemaAnnotation ¶
func SchemaAnnotation(n *gen.Type) (*Annotation, error)
SchemaAnnotation returns the Annotation on the given gen.Type.
func UpdateOperation ¶
func UpdateOperation(opts ...OperationConfigOption) Annotation
UpdateOperation returns an update operation annotation.
func (Annotation) Merge ¶
func (a Annotation) Merge(o schema.Annotation) schema.Annotation
Merge implements ent.Merger interface.
func (Annotation) Name ¶
func (Annotation) Name() string
Name implements schema.Annotation interface.
type Config ¶
type Config struct { // DefaultPolicy defines the default policy for endpoint generation. // It is used if no policy is set on a (sub-)resource. // Defaults to PolicyExpose. DefaultPolicy Policy // Whether or whether not to generate simple models instead of one model per endpoint. // // The OAS generator by default creates one view per endpoint. The naming strategy is the following: // - <S><Op> for 1st level operation Op on schema S // - <S><Op>_<E> for an eager loaded edge E on 1st level operation Op on schema S // - <S>_<E><Op> for a 2nd level operation Op on edge E on schema S // // By enabling she SimpleModels configuration the generator simply adds the defined schemas with all fields and edges. // Serialization groups have no effects in this mode. SimpleModels bool // Specify the minimum amount of itemsPerPage allowed in generated pagination. // Defaults to 1. MinItemsPerPage int64 // Specify the maximum amount of itemsPerPage allowed in generated pagination. // Defaults to 255. MaxItemsPerPage int64 }
Config provides global metadata for the generator. It is injected into the gen.Graph.
type Edge ¶
Edge wraps a gen.Edge and denotes an edge to be returned in an operation response. It recursively defines edges to load on the gen.Type the wrapped edge is pointing at.
type Edges ¶
type Edges []*Edge
type Extension ¶
type Extension struct { entc.DefaultExtension // contains filtered or unexported fields }
Extension implements entc.Extension interface for providing OpenAPI Specification generation.
func NewExtension ¶
func NewExtension(opts ...ExtensionOption) (*Extension, error)
NewExtension returns a new entoas extension with default values.
func (*Extension) Annotations ¶
func (ex *Extension) Annotations() []entc.Annotation
Annotations of the extensions.
type ExtensionOption ¶
ExtensionOption allows managing Extension configuration using functional arguments.
func DefaultPolicy ¶
func DefaultPolicy(p Policy) ExtensionOption
DefaultPolicy sets the default ExclusionPolicy to use of none is given on a (sub-)schema.
func MaxItemsPerPage ¶
func MaxItemsPerPage(n int) ExtensionOption
MaxItemsPerPage sets the maximum value for the 'itemsPerPage' parameter in list pagination.
func MinItemsPerPage ¶
func MinItemsPerPage(n int) ExtensionOption
MinItemsPerPage sets the minimum value for the 'itemsPerPage' parameter in list pagination.
func Mutations ¶
func Mutations(ms ...MutateFunc) ExtensionOption
Mutations adds the given mutations to the spec generator.
A MutateFunc is a simple closure that can be used to edit the generated spec. It can be used to add custom endpoints or alter the spec in any other way.
func SimpleModels ¶
func SimpleModels() ExtensionOption
SimpleModels enables the simple model generation feature.
Further information can be found at Config.SimpleModels.
func Spec ¶
func Spec(spec *ogen.Spec) ExtensionOption
Spec allows to configure a pointer to an existing ogen.Spec where the code generator writes the final result to. Any configured Mutations are run before the spec is written.
func WriteTo ¶
func WriteTo(out io.Writer) ExtensionOption
WriteTo writes the current specs content to the given io.Writer.
type MutateFunc ¶
MutateFunc defines a closure to be called on a generated spec.
type Operation ¶
type Operation string
func EdgeOperations ¶
EdgeOperations returns the list of operations to expose for this edge.
func NodeOperations ¶
NodeOperations returns the list of operations to expose for this node.
type OperationConfig ¶
type OperationConfig struct { Policy Policy Groups serialization.Groups }
OperationConfig holds meta information about a REST operation.
type OperationConfigOption ¶
type OperationConfigOption func(*OperationConfig)
OperationConfigOption allows managing OperationConfig using functional arguments.
func OperationGroups ¶
func OperationGroups(gs ...string) OperationConfigOption
OperationGroups returns a OperationConfigOption that adds the given serialization groups to a OperationConfig.
func OperationPolicy ¶
func OperationPolicy(p Policy) OperationConfigOption
OperationPolicy returns a OperationConfigOption that sets the Policy of a OperationConfig to the given one.