Annotation Reference
Annotations Summary
Annotation | Usage Location | Description |
---|---|---|
WithSkip | schema edge field | Sets the schema, edge, or field to be skipped in the REST API. |
WithReadOnly | field | Sets the field to be read-only in the REST API. |
WithExample | field | Sets the OpenAPI example for the specified field. |
WithEagerLoad | edge | Sets the edge to be eager-loaded in the REST API for each associated entity. |
WithSortable | field | Sets the field to be sortable in the REST API. |
WithDefaultSort | schema | Sets the default sort field for the schema in the REST API. |
WithDefaultOrder | schema | Sets the default sorting order for the schema in the REST API. |
WithFilter | schema edge field | Sets the field to be filterable with the provided predicate(s). |
WithFilterGroup | edge field | Adds the field to a group of other fields that are filtered together. |
WithSchema | field | Sets the OpenAPI schema for the specified field. |
WithPagination | schema edge | Sets the schema to be paginated in the REST API. |
WithOperationSummary | schema edge | Provides an OpenAPI summary for the specified operation. |
WithOperationDescription | schema edge | Provides an OpenAPI description for the specified operation. |
WithAdditionalTags | schema edge | Adds additional tags to all operations for this schema/edge. |
WithTags | schema edge | Sets the tags for all operations for this schema/edge. |
WithOperationID | schema edge | Provides an OpenAPI operation ID for the specified operation. |
WithDescription | schema edge field | Sets the OpenAPI description for the specified schema/edge. |
WithMinItemsPerPage | schema edge | Sets an explicit minimum number of items per page for paginated calls. |
WithMaxItemsPerPage | schema edge | Sets an explicit maximum number of items per page for paginated calls. |
WithItemsPerPage | schema edge | Sets an explicit default number of items per page for paginated calls. |
WithEagerLoadLimit | edge | Sets the limit for the max number of entities to eager-load for the edge. |
WithEdgeEndpoint | edge | Sets the edge to have an endpoint. |
WithEdgeUpdateBulk | edge | Sets the edge to be bulk updated on the entities associated with the edge. |
WithHandler | schema edge | Sets the schema/edge to be an HTTP handler generated for it. |
WithDeprecated | schema edge field | Sets the OpenAPI deprecated flag for the specified schema/edge/field. |
WithIncludeOperations | schema edge | Includes the specified operations in the REST API for the schema. |
WithExcludeOperations | schema edge | Excludes the specified operations in the REST API for the schema. |
WithSkip
[ pkg.go.dev | usage: schema edge field ]
Sets the schema, edge, or field to be skipped in the REST API. Primarily useful if an entire schema shouldn't be queryable, or if there is a sensitive field that should never be returned (but sensitive isn't set on the field for some reason).
Example
WithReadOnly
[ pkg.go.dev | usage: field ]
Sets the field to be read-only in the REST API. If you want to make a schema or edge read-only, use the Operations annotation instead.
Example
WithExample
[ pkg.go.dev | usage: field ]
Sets the OpenAPI example for the specified field. This is recommended if it's not obvious what the fields purpose is, or what the format could be. Many OpenAPI documentation browsers will use this information as an example value within the POST/PATCH body.
Example
WithEagerLoad
[ pkg.go.dev | usage: edge ]
Sets the edge to be eager-loaded in the REST API for each associated entity. Note that edges are not eager-loaded by default. Eager-loading, when enabled, means that the configured edge is always fetched when the parent entity is fetched (only covering the first level, it does not recurse).
See Eager Loading for more information. See also EntGo: Eager Loading.
Example
WithSortable
[ pkg.go.dev | usage: field ]
Sets the field to be sortable in the REST API. Note that only types that can be sorted, will be sortable.
Example
WithDefaultSort
[ pkg.go.dev | usage: schema ]
Sets the default sort field for the schema in the REST API. If not specified, will default to the
id
field (if it exists on the schema/edge). The provided field must exist on the schema, otherwise codegen will fail. You may provide any of the typical fields shown for thesort
field in the OpenAPI specification for this schema. E.g.id
,created_at
,someedge.count
(<edge>.<edge-field>
), etc.Note that this will also change the way eager-loaded edges which are based on this schema are sorted. This is currently the only way to sort eager-loaded data.
Example
WithDefaultOrder
[ pkg.go.dev | usage: schema ]
Sets the default sorting order for the schema in the REST API. If not specified, will default to ASC.
Note that this will also change the way eager-loaded edges which are based on this schema are sorted. This is currently the only way to sort eager-loaded data.
Example
WithFilter
[ pkg.go.dev | usage: schema edge field ]
Sets the field to be filterable with the provided predicate(s). When applied on an edge with
entrest.FilterEdge
applied, it will include the fields associated with the edge that are also filterable.See all predicate constants that can be used with
entrest.WithFilter
for more information.
Example 1
Example 2
WithFilterGroup
[ pkg.go.dev | usage: edge field ]
Adds the field to a group of other fields that are filtered together. Note that only common filter options across all of the groups will be supported. The goal of this is to group common fields that would be searched together.
You can also use WithFilterGroup on edges to also allow any matching groups on the edge to be included in this filter group. The group name must match when used on the edge if you want that edge to be included in that group.
Example
Using the following annotations:
And the following API query:
This would effectively result in the following psuedo-code being used behind the scenes:
WithSchema
[ pkg.go.dev | usage: field ]
Sets the OpenAPI schema for a field. This is required for any fields which are JSON based, or don't have a pre-defined ent type for the field.
You can use
entrest.SchemaObjectAny
for an object with any properties (effectivelyany
).
Example
WithPagination
[ pkg.go.dev | usage: schema edge ]
Sets the schema to be paginated in the REST API. This is not required to be provided unless pagination was disabled globally.
See Pagination for more information.
Example
WithOperationSummary
[ pkg.go.dev | usage: schema edge ]
Provides an OpenAPI summary for the specified operation. This should be a short summary of what the operation does.
Example
WithOperationDescription
[ pkg.go.dev | usage: schema edge ]
Provides an OpenAPI description for the specified operation. This should be a verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation.
Example
WithAdditionalTags
[ pkg.go.dev | usage: schema edge ]
Adds additional OpenAPI tags to all operations for this schema/edge. Tags can be used for logical grouping of operations by resources or any other qualifier.
Example
WithTags
[ pkg.go.dev | usage: schema edge ]
Sets the OpenAPI tags for all operations for this schema/edge. This will otherwise default to the schema/edge's name(s). Tags can be used for logical grouping of operations by resources or any other qualifier.
Example
WithOperationID
[ pkg.go.dev | usage: schema edge ]
Provides an OpenAPI operation ID for the specified operation. This should be snake-cased and must be unique for the operation.
Example
WithDescription
[ pkg.go.dev | usage: schema edge field ]
Sets the OpenAPI description for the specified schema/edge/field in the REST API. This will otherwise default to the schema/edge/field comment. It's recommended to use the field comment rather than setting this annotation when possible.
Example
WithMinItemsPerPage
[ pkg.go.dev | usage: schema edge ]
Sets an explicit minimum number of items per page for paginated calls.
See Pagination for more information.
Example
WithMaxItemsPerPage
[ pkg.go.dev | usage: schema edge ]
Sets an explicit maximum number of items per page for paginated calls.
See Pagination for more information.
Example
WithItemsPerPage
[ pkg.go.dev | usage: schema edge ]
Sets an explicit default number of items per page for paginated calls.
See Pagination for more information.
Example
WithEagerLoadLimit
[ pkg.go.dev | usage: edge ]
Sets the limit for the max number of entities to eager-load for the edge. There is a global default limit for eager-loading, which can be set via the
EagerLoadLimit
configuration option. Defaults to1000, and the limit can be disabled by setting the value to-1
.See Eager Loading for more information.
Example
WithEdgeEndpoint
[ pkg.go.dev | usage: edge ]
Sets the edge to have an endpoint. If the edge is eager-loaded, and the global config is set to disable endpoints for edges which are also eager-loaded, this will default to false. Not required to be provided unless endpoints are disabled globally and you want to specifically enable one edge to have an endpoint, or want to disable an edge from having an endpoint in general.
See Eager Loading for more information.
Example
WithEdgeUpdateBulk
[ pkg.go.dev | usage: edge ]
Sets the edge to be bulk updated on the entities associated with the edge. This is disabled by default, which will mean that you must use the
add_<field>
andremove_<field>
object references to associate/disassociate entities with the edge.This is disabled by default due to the fact that this can lead to accidental disassociation of a massive number of entities, if a user doesn't happen to fully understand the implications of providing values to the
bulk
field, which would just be<field>
(sets the non-unique edge to be set to those provided values).See Eager Loading for more information.
Example
WithHandler
[ pkg.go.dev | usage: schema edge ]
Sets the schema/edge to have an HTTP handler generated for it. Unless a schema/edge is skipped or has the specific operation disabled, an HTTP handler/endpoint will be generated for it by default. This does not prevent the endpoint from being created within the spec, rather only prevents the handler from being mounted. The handler functions will still be generated in case you want to build upon them.
See HTTP Handler for more information.
Example
WithDeprecated
[ pkg.go.dev | usage: schema edge field ]
Sets the OpenAPI deprecated flag for the specified schema/edge/field.
Example
WithIncludeOperations
[ pkg.go.dev | usage: schema edge ]
Includes the specified operations in the REST API for the schema. If empty, all operations are generated (unless globally disabled).
Example
WithExcludeOperations
[ pkg.go.dev | usage: schema edge ]
Excludes the specified operations in the REST API for the schema. If empty, all operations are generated (unless globally disabled).