entoas - Do not generate endpoints for skipped edges#574
entoas - Do not generate endpoints for skipped edges#574swalkerhppr wants to merge 2 commits intoent:masterfrom
Conversation
… not generate operations for skipped edges with annotations.
|
I was going to submit a similar PR yesterday (make skip supports fields, edges, and entire schemas), but noticed this is actually already supported, just not through the I do still think the documentation is lacking, and the choice of using |
|
Tried again using the operation policy exclude annotations and it seems that there are still references to the "skipped" edges: $ go get -u entgo.io/contrib/entoas@master
$ go generate ./...
$ grep -i "password\|secret" ent/openapi.json
"secret_parent": {
"secret_children": {
"secret_parent": {
"secret_children": {
"secret_parent": {
"secret_children": {The updated code from above // ent/schema/user.go
package schema
import (
"entgo.io/contrib/entoas"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("username"),
field.String("password").
Annotations(
entoas.Skip(true), // Skip the "password" field (this works)
),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("secret_children", User.Type).
Annotations(
//entoas.Skip(true), // Skip the "secret_parent" edge
entoas.CreateOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.ReadOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.ListOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.UpdateOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.DeleteOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
).
From("secret_parent").
Unique().
Annotations(
//entoas.Skip(true), // Skip the "secret_parent" edge
entoas.CreateOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.ReadOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.ListOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.UpdateOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
entoas.DeleteOperation(entoas.OperationPolicy(entoas.PolicyExclude)),
),
edge.To("children", User.Type).
From("parent").
Unique(),
}
}Here is the full generated openapi.json I'm not sure if this is intended, but from my perspective a "Skip"ped field or edge should not show up in the spec at all, and with the current version it doesn't seem to be possible. I think it would make sense to allow both where:
I definitely agree that there could be more documentation on using annotations. It may be more clear to be able to use the same annotations on fields and edges and have them behave in the same way. Skip only works with fields right now. |
|
It has been a while without any feedback/changes. Thanks! |
|
@masseelch @a8m any thoughts on this? |
entoas
Issue
Generated openapi.json generates properties and operations for skipped edges:
Code that causes the issue
Expected behavior
go generate ./...grep -i "password\|secret" ent/openapi.jsonshould show no references to secret_children nor secret_parent