Skip to content

Commit 0b7eb1b

Browse files
authored
Allow creation of object-types with an empty relations block (#318)
1 parent d99e34d commit 0b7eb1b

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

pkg/authz/objecttype/spec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type ObjectTypeSpec struct {
4444
type CreateObjectTypeSpec struct {
4545
Type string `json:"type" validate:"required,valid_object_type"`
4646
Source *Source `json:"source,omitempty"`
47-
Relations map[string]RelationRule `json:"relations" validate:"required,min=1,dive"` // NOTE: map key = name of relation
47+
Relations map[string]RelationRule `json:"relations" validate:"required,dive"` // NOTE: map key = name of relation
4848
}
4949

5050
func (spec CreateObjectTypeSpec) ToObjectType() (*ObjectType, error) {

tests/v1/object-types-crud.json

+30-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"tests": [
66
{
7-
"name": "failToCreateObjectWithoutRelations",
7+
"name": "failToCreateObjectTypeWithoutRelations",
88
"request": {
99
"method": "POST",
1010
"url": "/v1/object-types",
@@ -21,6 +21,34 @@
2121
}
2222
}
2323
},
24+
{
25+
"name": "createObjectTypeWithEmptyRelations",
26+
"request": {
27+
"method": "POST",
28+
"url": "/v1/object-types",
29+
"body": {
30+
"type": "A",
31+
"relations": {}
32+
}
33+
},
34+
"expectedResponse": {
35+
"statusCode": 200,
36+
"body": {
37+
"type": "A",
38+
"relations": {}
39+
}
40+
}
41+
},
42+
{
43+
"name": "deleteObjectTypeWithEmptyRelations",
44+
"request": {
45+
"method": "DELETE",
46+
"url": "/v1/object-types/A"
47+
},
48+
"expectedResponse": {
49+
"statusCode": 200
50+
}
51+
},
2452
{
2553
"name": "createObjectTypeReport",
2654
"request": {
@@ -342,4 +370,4 @@
342370
}
343371
}
344372
]
345-
}
373+
}

tests/v2/object-types-crud.json

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"tests": [
66
{
7-
"name": "failToCreateObjectWithoutRelations",
7+
"name": "failToCreateObjectTypeWithoutRelations",
88
"request": {
99
"method": "POST",
1010
"url": "/v2/object-types",
@@ -21,6 +21,34 @@
2121
}
2222
}
2323
},
24+
{
25+
"name": "createObjectTypeWithEmptyRelations",
26+
"request": {
27+
"method": "POST",
28+
"url": "/v2/object-types",
29+
"body": {
30+
"type": "A",
31+
"relations": {}
32+
}
33+
},
34+
"expectedResponse": {
35+
"statusCode": 200,
36+
"body": {
37+
"type": "A",
38+
"relations": {}
39+
}
40+
}
41+
},
42+
{
43+
"name": "deleteObjectTypeWithEmptyRelations",
44+
"request": {
45+
"method": "DELETE",
46+
"url": "/v2/object-types/A"
47+
},
48+
"expectedResponse": {
49+
"statusCode": 200
50+
}
51+
},
2452
{
2553
"name": "createObjectTypeReport",
2654
"request": {

0 commit comments

Comments
 (0)