Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-forbidden-response
Browse files Browse the repository at this point in the history
  • Loading branch information
Vic-Dev committed Oct 16, 2024
2 parents 563f911 + 94a1320 commit a8862b8
Show file tree
Hide file tree
Showing 6 changed files with 2,131 additions and 2,088 deletions.
29 changes: 29 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
# This is a simple check to ensure people remember to regenerate the docs
# and the pb.go files if they change a .proto file.
# It's not iron-clad but it's better than finding out later in github.

# AMD = added, modified, deleted
files=$(git diff --cached --name-only --diff-filter=AMD)

LIGHT_RED='\033[1;31m'
RESET='\033[0m' # No Color

# naive regex check for .proto extension
if [[ "$files" =~ \.proto ]]
then
# Check if there's a staged diff in /docs and in the generated pb.go files
docs_change=$(git diff --cached --raw docs/)
go_change=$(git diff --cached --raw proto/openfga/)
if [ -n "$docs_change" ] && [ -n "$go_change" ]; then
# Both were changed, we're good
exit 0
else
# One of the two directories does not have changes, block this commit
echo "This commit contains .proto changes but either the docs or generated /proto files are not part of this commit."
echo "${LIGHT_RED}Your changes were not committed, please run 'make all' and add the resulting changes${RESET}\n"
exit 1
fi
fi

exit 0
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
all: patch-swagger-doc format

buf-gen:
buf-gen: init-git-hooks
./buf.gen.yaml

patch-swagger-doc: buf-gen
./scripts/update_swagger.sh docs/openapiv2/apidocs.swagger.json

format: buf-gen
buf format -w

init-git-hooks:
git config --local core.hooksPath .githooks/
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ To generate source code from the protobuf definitions contained in this project
> **Note**: You must have [Buf CLI](https://docs.buf.build/installation) installed to run the following command.
>
```bash
./buf.gen.yaml
make buf-gen
```

The command above will generate source code in the `proto/` directory.
The command above will generate source code in the `proto/` directory. It will also configure a local git hook to check
that files requiring auto-generation after `.proto` changes have been updated. There are some cases where that git hook
may be overly strict. In those cases you can bypass it with `commit --no-verify`.

## Use the generated sources in OpenFGA

Expand All @@ -31,6 +33,8 @@ The command above will generate source code in the `proto/` directory.
## Generating OpenAPI Documentation
To generate the OpenAPI documentation from the protobuf sources you can run the following commands:
> **Note**: You must have [jq](https://jqlang.github.io/jq/download/) installed to run the `format` step below
```bash
./buf.gen.yaml
./scripts/update_swagger.sh docs/openapiv2/apidocs.swagger.json
Expand All @@ -40,4 +44,4 @@ buf format -w
Or you can just use
```bash
make
```
```
6 changes: 4 additions & 2 deletions docs/openapiv2/apidocs.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions openfga/v1/openfga_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ service OpenFGAService {
"You may also provide a `context` object that will be used to evaluate the conditioned tuples in the system. It is strongly recommended to provide a value for all the input parameters of all the conditions, to ensure that all tuples be evaluated correctly.\n"
"The response will contain the related users in an array in the \"users\" field of the response. These results may include specific objects, usersets \n"
"or type-bound public access. Each of these types of results is encoded in its own type and not represented as a string."
"In cases where a type-bound public acces result is returned (e.g. `user:*`), it cannot be inferred that all subjects\n"
"In cases where a type-bound public access result is returned (e.g. `user:*`), it cannot be inferred that all subjects\n"
"of that type have a relation to the object; it is possible that negations exist and checks should still be queried\n"
"on individual subjects to ensure access to that document."
"The number of users in the response array will be limited by the execution timeout specified in the flag OPENFGA_LIST_USERS_DEADLINE "
Expand Down Expand Up @@ -993,7 +993,11 @@ message ReadRequest {
gte: 1
lte: 100
},
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {example: "50"}
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
example: "50"
minimum: 1
maximum: 100
}
];

string continuation_token = 4 [
Expand Down
Loading

0 comments on commit a8862b8

Please sign in to comment.