Skip to content

Commit

Permalink
Exclude private API calls from swagger (grpc-ecosystem#7)
Browse files Browse the repository at this point in the history
* add generation second file with  private methods

* update logic

* update README.md

* remove private definitions
  • Loading branch information
Aliaksei Burau authored and Evgeniy-L committed Oct 26, 2018
1 parent d9dd6d2 commit 7052263
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 11 deletions.
123 changes: 117 additions & 6 deletions Gopkg.lock

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

12 changes: 12 additions & 0 deletions protoc-gen-grpc-gateway/descriptor/registry.go
Expand Up @@ -47,6 +47,9 @@ type Registry struct {
// atlasPatch ...
atlasPatch bool

//withPrivateOperations if true exclude all operations with tag "private"
withPrivateOperations bool

// mergeFileName target swagger file name after merge
mergeFileName string
}
Expand Down Expand Up @@ -325,6 +328,15 @@ func (r *Registry) SetAtlasPatch(atlas bool) {
r.atlasPatch = atlas
}

// IsWithPrivateOperations if true exclude all operations with tag "private"
func (r *Registry) IsWithPrivateOperations() bool {
return r.withPrivateOperations
}

func (r *Registry) SetWithPrivateOperations(withPrivateOperations bool) {
r.withPrivateOperations = withPrivateOperations
}

// SetMergeFileName controls the target swagger file name out of multiple protos
func (r *Registry) SetMergeFileName(mergeFileName string) {
r.mergeFileName = mergeFileName
Expand Down
22 changes: 21 additions & 1 deletion protoc-gen-swagger/README.md
Expand Up @@ -27,4 +27,24 @@ Patch includes following changes:
query parameters, also id.payload_id is replaced with id in path.

* Unused references elimination.


* Exclude all operations tagged as "private" see example below
```
rpc Update (UpdateNetworkRequest) returns (UpdateNetworkResponse) {
option (google.api.http) = {
put: "/network/{payload.id.resource_id}"
body: "payload"
additional_bindings {
patch: "/network/{payload.id.resource_id}",
body: "payload"
}
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
tags: "private"
};
}
```
* Introduced new `with_private` flag if set generate service.private.swagger.json
with all operation (including tagged as "private")

0 comments on commit 7052263

Please sign in to comment.