From d7c51d33339c74f7bc4193c45dcc9075955a98fa Mon Sep 17 00:00:00 2001 From: Patrik Date: Fri, 21 Jan 2022 16:06:09 +0100 Subject: [PATCH 1/2] fix: openapi spec and internal SDK --- internal/e2e/sdk_client_test.go | 10 +- .../delete_relation_tuples_parameters.go | 239 ++++++++++++++++++ internal/relationtuple/transact_server.go | 2 +- spec/api.json | 44 ++++ 4 files changed, 289 insertions(+), 6 deletions(-) diff --git a/internal/e2e/sdk_client_test.go b/internal/e2e/sdk_client_test.go index 05af604fa..0ead09edb 100644 --- a/internal/e2e/sdk_client_test.go +++ b/internal/e2e/sdk_client_test.go @@ -53,7 +53,7 @@ func (c *sdkClient) getWriteClient() *httpclient.OryKeto { func (c *sdkClient) createTuple(t require.TestingT, r *relationtuple.InternalRelationTuple) { payload := &models.RelationQuery{ - Namespace: &r.Namespace, + Namespace: r.Namespace, Object: r.Object, Relation: r.Relation, } @@ -76,7 +76,7 @@ func (c *sdkClient) createTuple(t require.TestingT, r *relationtuple.InternalRel } func (c *sdkClient) deleteTuple(t require.TestingT, r *relationtuple.InternalRelationTuple) { - params := write.NewDeleteRelationTupleParamsWithTimeout(time.Second). + params := write.NewDeleteRelationTuplesParamsWithTimeout(time.Second). WithNamespace(&r.Namespace). WithObject(&r.Object). WithRelation(&r.Relation) @@ -90,12 +90,12 @@ func (c *sdkClient) deleteTuple(t require.TestingT, r *relationtuple.InternalRel WithSubjectSetRelation(&s.Relation) } - _, err := c.getWriteClient().Write.DeleteRelationTuple(params) + _, err := c.getWriteClient().Write.DeleteRelationTuples(params) require.NoError(t, err) } func (c *sdkClient) deleteAllTuples(t require.TestingT, q *relationtuple.RelationQuery) { - params := write.NewDeleteRelationTupleParamsWithTimeout(time.Second). + params := write.NewDeleteRelationTuplesParamsWithTimeout(time.Second). WithNamespace(&q.Namespace). WithObject(&q.Object). WithRelation(&q.Relation) @@ -112,7 +112,7 @@ func (c *sdkClient) deleteAllTuples(t require.TestingT, q *relationtuple.Relatio } } - _, err := c.getWriteClient().Write.DeleteRelationTuple(params) + _, err := c.getWriteClient().Write.DeleteRelationTuples(params) require.NoError(t, err) } diff --git a/internal/httpclient/client/write/delete_relation_tuples_parameters.go b/internal/httpclient/client/write/delete_relation_tuples_parameters.go index b1d92d98f..587a28768 100644 --- a/internal/httpclient/client/write/delete_relation_tuples_parameters.go +++ b/internal/httpclient/client/write/delete_relation_tuples_parameters.go @@ -58,6 +58,49 @@ func NewDeleteRelationTuplesParamsWithHTTPClient(client *http.Client) *DeleteRel Typically these are written to a http.Request. */ type DeleteRelationTuplesParams struct { + + /* Namespace. + + Namespace of the Relation Tuple + */ + Namespace *string + + /* Object. + + Object of the Relation Tuple + */ + Object *string + + /* Relation. + + Relation of the Relation Tuple + */ + Relation *string + + /* SubjectID. + + SubjectID of the Relation Tuple + */ + SubjectID *string + + /* SubjectSetNamespace. + + Namespace of the Subject Set + */ + SubjectSetNamespace *string + + /* SubjectSetObject. + + Object of the Subject Set + */ + SubjectSetObject *string + + /* SubjectSetRelation. + + Relation of the Subject Set + */ + SubjectSetRelation *string + timeout time.Duration Context context.Context HTTPClient *http.Client @@ -111,6 +154,83 @@ func (o *DeleteRelationTuplesParams) SetHTTPClient(client *http.Client) { o.HTTPClient = client } +// WithNamespace adds the namespace to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithNamespace(namespace *string) *DeleteRelationTuplesParams { + o.SetNamespace(namespace) + return o +} + +// SetNamespace adds the namespace to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetNamespace(namespace *string) { + o.Namespace = namespace +} + +// WithObject adds the object to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithObject(object *string) *DeleteRelationTuplesParams { + o.SetObject(object) + return o +} + +// SetObject adds the object to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetObject(object *string) { + o.Object = object +} + +// WithRelation adds the relation to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithRelation(relation *string) *DeleteRelationTuplesParams { + o.SetRelation(relation) + return o +} + +// SetRelation adds the relation to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetRelation(relation *string) { + o.Relation = relation +} + +// WithSubjectID adds the subjectID to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithSubjectID(subjectID *string) *DeleteRelationTuplesParams { + o.SetSubjectID(subjectID) + return o +} + +// SetSubjectID adds the subjectId to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetSubjectID(subjectID *string) { + o.SubjectID = subjectID +} + +// WithSubjectSetNamespace adds the subjectSetNamespace to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithSubjectSetNamespace(subjectSetNamespace *string) *DeleteRelationTuplesParams { + o.SetSubjectSetNamespace(subjectSetNamespace) + return o +} + +// SetSubjectSetNamespace adds the subjectSetNamespace to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetSubjectSetNamespace(subjectSetNamespace *string) { + o.SubjectSetNamespace = subjectSetNamespace +} + +// WithSubjectSetObject adds the subjectSetObject to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithSubjectSetObject(subjectSetObject *string) *DeleteRelationTuplesParams { + o.SetSubjectSetObject(subjectSetObject) + return o +} + +// SetSubjectSetObject adds the subjectSetObject to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetSubjectSetObject(subjectSetObject *string) { + o.SubjectSetObject = subjectSetObject +} + +// WithSubjectSetRelation adds the subjectSetRelation to the delete relation tuples params +func (o *DeleteRelationTuplesParams) WithSubjectSetRelation(subjectSetRelation *string) *DeleteRelationTuplesParams { + o.SetSubjectSetRelation(subjectSetRelation) + return o +} + +// SetSubjectSetRelation adds the subjectSetRelation to the delete relation tuples params +func (o *DeleteRelationTuplesParams) SetSubjectSetRelation(subjectSetRelation *string) { + o.SubjectSetRelation = subjectSetRelation +} + // WriteToRequest writes these params to a swagger request func (o *DeleteRelationTuplesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -119,6 +239,125 @@ func (o *DeleteRelationTuplesParams) WriteToRequest(r runtime.ClientRequest, reg } var res []error + if o.Namespace != nil { + + // query param namespace + var qrNamespace string + + if o.Namespace != nil { + qrNamespace = *o.Namespace + } + qNamespace := qrNamespace + if qNamespace != "" { + + if err := r.SetQueryParam("namespace", qNamespace); err != nil { + return err + } + } + } + + if o.Object != nil { + + // query param object + var qrObject string + + if o.Object != nil { + qrObject = *o.Object + } + qObject := qrObject + if qObject != "" { + + if err := r.SetQueryParam("object", qObject); err != nil { + return err + } + } + } + + if o.Relation != nil { + + // query param relation + var qrRelation string + + if o.Relation != nil { + qrRelation = *o.Relation + } + qRelation := qrRelation + if qRelation != "" { + + if err := r.SetQueryParam("relation", qRelation); err != nil { + return err + } + } + } + + if o.SubjectID != nil { + + // query param subject_id + var qrSubjectID string + + if o.SubjectID != nil { + qrSubjectID = *o.SubjectID + } + qSubjectID := qrSubjectID + if qSubjectID != "" { + + if err := r.SetQueryParam("subject_id", qSubjectID); err != nil { + return err + } + } + } + + if o.SubjectSetNamespace != nil { + + // query param subject_set.namespace + var qrSubjectSetNamespace string + + if o.SubjectSetNamespace != nil { + qrSubjectSetNamespace = *o.SubjectSetNamespace + } + qSubjectSetNamespace := qrSubjectSetNamespace + if qSubjectSetNamespace != "" { + + if err := r.SetQueryParam("subject_set.namespace", qSubjectSetNamespace); err != nil { + return err + } + } + } + + if o.SubjectSetObject != nil { + + // query param subject_set.object + var qrSubjectSetObject string + + if o.SubjectSetObject != nil { + qrSubjectSetObject = *o.SubjectSetObject + } + qSubjectSetObject := qrSubjectSetObject + if qSubjectSetObject != "" { + + if err := r.SetQueryParam("subject_set.object", qSubjectSetObject); err != nil { + return err + } + } + } + + if o.SubjectSetRelation != nil { + + // query param subject_set.relation + var qrSubjectSetRelation string + + if o.SubjectSetRelation != nil { + qrSubjectSetRelation = *o.SubjectSetRelation + } + qSubjectSetRelation := qrSubjectSetRelation + if qSubjectSetRelation != "" { + + if err := r.SetQueryParam("subject_set.relation", qSubjectSetRelation); err != nil { + return err + } + } + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/internal/relationtuple/transact_server.go b/internal/relationtuple/transact_server.go index aae99bace..902200c30 100644 --- a/internal/relationtuple/transact_server.go +++ b/internal/relationtuple/transact_server.go @@ -80,7 +80,7 @@ type bodyRelationTuple struct { // The basic ACL relation tuple // -// swagger:parameters getCheck deleteRelationTuple +// swagger:parameters getCheck deleteRelationTuples // nolint:deadcode,unused type queryRelationTuple struct { // Namespace of the Relation Tuple diff --git a/spec/api.json b/spec/api.json index c2520d8db..0791079f2 100755 --- a/spec/api.json +++ b/spec/api.json @@ -768,6 +768,50 @@ ], "summary": "Delete Relation Tuples", "operationId": "deleteRelationTuples", + "parameters": [ + { + "type": "string", + "description": "Namespace of the Relation Tuple", + "name": "namespace", + "in": "query" + }, + { + "type": "string", + "description": "Object of the Relation Tuple", + "name": "object", + "in": "query" + }, + { + "type": "string", + "description": "Relation of the Relation Tuple", + "name": "relation", + "in": "query" + }, + { + "type": "string", + "description": "SubjectID of the Relation Tuple", + "name": "subject_id", + "in": "query" + }, + { + "type": "string", + "description": "Namespace of the Subject Set", + "name": "subject_set.namespace", + "in": "query" + }, + { + "type": "string", + "description": "Object of the Subject Set", + "name": "subject_set.object", + "in": "query" + }, + { + "type": "string", + "description": "Relation of the Subject Set", + "name": "subject_set.relation", + "in": "query" + } + ], "responses": { "204": { "description": "Empty responses are sent when, for example, resources are deleted. The HTTP status code for empty responses is typically 201." From eec1478c25aad58d4263d5577518fb8df03006d4 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Fri, 21 Jan 2022 15:12:17 +0000 Subject: [PATCH 2/2] autogen(openapi): Regenerate swagger spec and internal client --- internal/httpclient/models/expand_tree.go | 14 +++++++++++++- .../models/get_relation_tuples_response.go | 4 ++++ .../httpclient/models/internal_relation_tuple.go | 4 ++++ internal/httpclient/models/patch_delta.go | 4 ++++ internal/httpclient/models/relation_query.go | 4 ++++ spec/api.json | 7 +++++-- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/internal/httpclient/models/expand_tree.go b/internal/httpclient/models/expand_tree.go index 986d71d19..f76285ca1 100644 --- a/internal/httpclient/models/expand_tree.go +++ b/internal/httpclient/models/expand_tree.go @@ -30,7 +30,11 @@ type ExpandTree struct { // subject set SubjectSet *SubjectSet `json:"subject_set,omitempty"` - // type + // + // union Union + // exclusion Exclusion + // intersection Intersection + // leaf Leaf // Required: true // Enum: [union exclusion intersection leaf] Type *string `json:"type"` @@ -72,6 +76,8 @@ func (m *ExpandTree) validateChildren(formats strfmt.Registry) error { if err := m.Children[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("children" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("children" + "." + strconv.Itoa(i)) } return err } @@ -91,6 +97,8 @@ func (m *ExpandTree) validateSubjectSet(formats strfmt.Registry) error { if err := m.SubjectSet.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("subject_set") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("subject_set") } return err } @@ -174,6 +182,8 @@ func (m *ExpandTree) contextValidateChildren(ctx context.Context, formats strfmt if err := m.Children[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("children" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("children" + "." + strconv.Itoa(i)) } return err } @@ -190,6 +200,8 @@ func (m *ExpandTree) contextValidateSubjectSet(ctx context.Context, formats strf if err := m.SubjectSet.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("subject_set") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("subject_set") } return err } diff --git a/internal/httpclient/models/get_relation_tuples_response.go b/internal/httpclient/models/get_relation_tuples_response.go index e83f0dc18..e2e257e0d 100644 --- a/internal/httpclient/models/get_relation_tuples_response.go +++ b/internal/httpclient/models/get_relation_tuples_response.go @@ -56,6 +56,8 @@ func (m *GetRelationTuplesResponse) validateRelationTuples(formats strfmt.Regist if err := m.RelationTuples[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("relation_tuples" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("relation_tuples" + "." + strconv.Itoa(i)) } return err } @@ -88,6 +90,8 @@ func (m *GetRelationTuplesResponse) contextValidateRelationTuples(ctx context.Co if err := m.RelationTuples[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("relation_tuples" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("relation_tuples" + "." + strconv.Itoa(i)) } return err } diff --git a/internal/httpclient/models/internal_relation_tuple.go b/internal/httpclient/models/internal_relation_tuple.go index e17517c99..fc6445dbb 100644 --- a/internal/httpclient/models/internal_relation_tuple.go +++ b/internal/httpclient/models/internal_relation_tuple.go @@ -102,6 +102,8 @@ func (m *InternalRelationTuple) validateSubjectSet(formats strfmt.Registry) erro if err := m.SubjectSet.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("subject_set") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("subject_set") } return err } @@ -130,6 +132,8 @@ func (m *InternalRelationTuple) contextValidateSubjectSet(ctx context.Context, f if err := m.SubjectSet.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("subject_set") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("subject_set") } return err } diff --git a/internal/httpclient/models/patch_delta.go b/internal/httpclient/models/patch_delta.go index 2a02a7efb..e29ac7336 100644 --- a/internal/httpclient/models/patch_delta.go +++ b/internal/httpclient/models/patch_delta.go @@ -97,6 +97,8 @@ func (m *PatchDelta) validateRelationTuple(formats strfmt.Registry) error { if err := m.RelationTuple.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("relation_tuple") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("relation_tuple") } return err } @@ -125,6 +127,8 @@ func (m *PatchDelta) contextValidateRelationTuple(ctx context.Context, formats s if err := m.RelationTuple.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("relation_tuple") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("relation_tuple") } return err } diff --git a/internal/httpclient/models/relation_query.go b/internal/httpclient/models/relation_query.go index 18e256a82..16b082e0f 100644 --- a/internal/httpclient/models/relation_query.go +++ b/internal/httpclient/models/relation_query.go @@ -59,6 +59,8 @@ func (m *RelationQuery) validateSubjectSet(formats strfmt.Registry) error { if err := m.SubjectSet.Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("subject_set") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("subject_set") } return err } @@ -87,6 +89,8 @@ func (m *RelationQuery) contextValidateSubjectSet(ctx context.Context, formats s if err := m.SubjectSet.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("subject_set") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("subject_set") } return err } diff --git a/spec/api.json b/spec/api.json index 0791079f2..8fa95aae8 100755 --- a/spec/api.json +++ b/spec/api.json @@ -1069,7 +1069,8 @@ "enum": [ "insert", "delete" - ] + ], + "x-go-enum-desc": "insert ActionInsert\ndelete ActionDelete" }, "relation_tuple": { "$ref": "#/definitions/InternalRelationTuple" @@ -1141,13 +1142,15 @@ "$ref": "#/definitions/SubjectSet" }, "type": { + "description": "\nunion Union\nexclusion Exclusion\nintersection Intersection\nleaf Leaf", "type": "string", "enum": [ "union", "exclusion", "intersection", "leaf" - ] + ], + "x-go-enum-desc": "union Union\nexclusion Exclusion\nintersection Intersection\nleaf Leaf" } } },