Skip to content

Commit

Permalink
Skip edges with skip annotation. Skip fields with skip annotation. Do…
Browse files Browse the repository at this point in the history
… not generate operations for skipped edges with annotations.
  • Loading branch information
Stephen Walker committed Apr 15, 2024
1 parent 4ec1976 commit 73bbfc9
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions entoas/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 73bbfc9

Please sign in to comment.