-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
entoas - Do not generate endpoints for skipped edges #574
base: master
Are you sure you want to change the base?
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! |
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.json
should show no references to secret_children nor secret_parent