From 185b78ea4766c77ff885082ee572df0de577f2ac Mon Sep 17 00:00:00 2001 From: Stephen Walker Date: Mon, 15 Apr 2024 14:47:34 -0500 Subject: [PATCH] Skip edges with skip annotation. Skip fields with skip annotation. Do not generate operations for skipped edges with annotations. --- entoas/generator.go | 51 ++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/entoas/generator.go b/entoas/generator.go index 0a2d6f8ee..7964ea5f8 100644 --- a/entoas/generator.go +++ b/entoas/generator.go @@ -70,14 +70,20 @@ func schemas(g *gen.Graph, spec *ogen.Spec) error { return fmt.Errorf("schema %q not found for edge %q on %q", e.Type.Name, e.Name, n.Name) } es = es.ToNamed(e.Type.Name).AsLocalRef() - if !e.Unique { - es = es.AsArray() + a, err := EdgeAnnotation(e) + if err != nil { + return fmt.Errorf("could not parse %q edge annotation for %q on %q", e.Type.Name, e.Name, n.Name) + } + if !a.Skip { + if !e.Unique { + es = es.AsArray() + } + addProperty( + spec.Components.Schemas[n.Name], + ogen.NewProperty().SetName(e.Name).SetSchema(es), + !e.Optional, + ) } - addProperty( - spec.Components.Schemas[n.Name], - ogen.NewProperty().SetName(e.Name).SetSchema(es), - !e.Optional, - ) } } // If the SimpleModels feature is enabled to not generate a schema per response. @@ -110,14 +116,20 @@ func schemas(g *gen.Graph, spec *ogen.Spec) error { return fmt.Errorf("schema %q not found for edge %q on %q", vn, e.Name, n) } es = es.ToNamed(vn).AsLocalRef() - if !e.Unique { - es = es.AsArray() + a, err := EdgeAnnotation(e) + if err != nil { + return fmt.Errorf("could not parse %q edge annotation for %q on %q", e.Name, e.Name, n) + } + if !a.Skip { + if !e.Unique { + es = es.AsArray() + } + addProperty( + spec.Components.Schemas[n], + ogen.NewProperty().SetName(e.Name).SetSchema(es), + !e.Optional, + ) } - addProperty( - spec.Components.Schemas[n], - ogen.NewProperty().SetName(e.Name).SetSchema(es), - !e.Optional, - ) } } } @@ -662,6 +674,10 @@ func EdgeOperations(e *gen.Edge) ([]Operation, error) { if err := ant.Decode(e.Annotations[ant.Name()]); err != nil { return nil, err } + // Skipped edges get no operations + if ant.Skip { + return nil, nil + } var ops []Operation m := make(map[Operation]OperationConfig) if e.Unique { @@ -724,6 +740,13 @@ func reqBody(n *gen.Type, op Operation, allowClientUUIDs bool) (*ogen.RequestBod if err != nil { return nil, err } + a, err := EdgeAnnotation(e) + if err != nil { + return nil, err + } + if a.ReadOnly || a.Skip { + continue + } if !e.Unique { s = s.AsArray() }