Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc-gen-openapiv2: RPC visibility setting transitively applied to messages #2880

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
422 changes: 320 additions & 102 deletions examples/internal/proto/examplepb/visibility_rule_echo_service.pb.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ message VisibilityRuleSimpleMessage {
VisibilityEnum an_enum = 10;
}

// MessageInPreviewMethod doesn't define its own visibility restrictions,
// but is only included in a method marked as "PREVIEW", so it will only
// appear if `visibility_restriction_selectors` include "PREVIEW".
message VisibilityRuleMessageInPreviewMethod {
string id = 1;
VisibilityRuleSubMessageInPreviewMethod sub_message = 2;
VisibilityRuleEnumInPreviewMethod enum = 3;
}

// SubMessageInPreviewMethod doesn't define its own visibility restrictions,
// but is only included in a method marked as "PREVIEW", so it will only
// appear if `visibility_restriction_selectors` include "PREVIEW".
message VisibilityRuleSubMessageInPreviewMethod {
string id = 1;
}

// EnumInPreviewMethod doesn't define its own visibility restrictions,
// but is only included in a method marked as "PREVIEW", so it will only
// appear if `visibility_restriction_selectors` include "PREVIEW".
enum VisibilityRuleEnumInPreviewMethod {
VISIBILITY_RULE_ENUM_IN_PREVIEW_METHOD_UNSPECIFIED = 0;
}

// VisibilityRuleEchoService service responds to incoming echo requests.
// Different services will be available in the swagger documentation depending
// based on `google.api.VisibilityRule`s and the set `visibility_restriction_selectors`
Expand All @@ -75,7 +98,7 @@ service VisibilityRuleEchoService {
}
// EchoPreview is a preview API that should only be visible in the OpenAPI spec
// if `visibility_restriction_selectors` includes "PREVIEW".
rpc EchoPreview(VisibilityRuleSimpleMessage) returns (VisibilityRuleSimpleMessage) {
rpc EchoPreview(VisibilityRuleSimpleMessage) returns (VisibilityRuleMessageInPreviewMethod) {
option (google.api.method_visibility).restriction = "PREVIEW";
option (google.api.http) = {
get: "/v1/example/echo_preview"
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbVisibilityRuleSimpleMessage"
"$ref": "#/definitions/examplepbVisibilityRuleMessageInPreviewMethod"
}
},
"default": {
Expand Down Expand Up @@ -721,6 +721,29 @@
},
"description": "Embedded represents a message embedded in SimpleMessage."
},
"examplepbVisibilityRuleEnumInPreviewMethod": {
"type": "string",
"enum": [
"VISIBILITY_RULE_ENUM_IN_PREVIEW_METHOD_UNSPECIFIED"
],
"default": "VISIBILITY_RULE_ENUM_IN_PREVIEW_METHOD_UNSPECIFIED",
"description": "EnumInPreviewMethod doesn't define its own visibility restrictions,\nbut is only included in a method marked as \"PREVIEW\", so it will only\nappear if `visibility_restriction_selectors` include \"PREVIEW\"."
},
"examplepbVisibilityRuleMessageInPreviewMethod": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"subMessage": {
"$ref": "#/definitions/examplepbVisibilityRuleSubMessageInPreviewMethod"
},
"enum": {
"$ref": "#/definitions/examplepbVisibilityRuleEnumInPreviewMethod"
}
},
"description": "MessageInPreviewMethod doesn't define its own visibility restrictions,\nbut is only included in a method marked as \"PREVIEW\", so it will only\nappear if `visibility_restriction_selectors` include \"PREVIEW\"."
},
"examplepbVisibilityRuleSimpleMessage": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -761,6 +784,15 @@
},
"description": "SimpleMessage represents a simple message sent to the Echo service."
},
"examplepbVisibilityRuleSubMessageInPreviewMethod": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"description": "SubMessageInPreviewMethod doesn't define its own visibility restrictions,\nbut is only included in a method marked as \"PREVIEW\", so it will only\nappear if `visibility_restriction_selectors` include \"PREVIEW\"."
},
"protobufAny": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/examplepbVisibilityRuleSimpleMessage"
"$ref": "#/definitions/examplepbVisibilityRuleMessageInPreviewMethod"
}
},
"default": {
Expand Down Expand Up @@ -389,6 +389,29 @@
},
"description": "Embedded represents a message embedded in SimpleMessage."
},
"examplepbVisibilityRuleEnumInPreviewMethod": {
"type": "string",
"enum": [
"VISIBILITY_RULE_ENUM_IN_PREVIEW_METHOD_UNSPECIFIED"
],
"default": "VISIBILITY_RULE_ENUM_IN_PREVIEW_METHOD_UNSPECIFIED",
"description": "EnumInPreviewMethod doesn't define its own visibility restrictions,\nbut is only included in a method marked as \"PREVIEW\", so it will only\nappear if `visibility_restriction_selectors` include \"PREVIEW\"."
},
"examplepbVisibilityRuleMessageInPreviewMethod": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"subMessage": {
"$ref": "#/definitions/examplepbVisibilityRuleSubMessageInPreviewMethod"
},
"enum": {
"$ref": "#/definitions/examplepbVisibilityRuleEnumInPreviewMethod"
}
},
"description": "MessageInPreviewMethod doesn't define its own visibility restrictions,\nbut is only included in a method marked as \"PREVIEW\", so it will only\nappear if `visibility_restriction_selectors` include \"PREVIEW\"."
},
"examplepbVisibilityRuleSimpleMessage": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -426,6 +449,15 @@
},
"description": "SimpleMessage represents a simple message sent to the Echo service."
},
"examplepbVisibilityRuleSubMessageInPreviewMethod": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
},
"description": "SubMessageInPreviewMethod doesn't define its own visibility restrictions,\nbut is only included in a method marked as \"PREVIEW\", so it will only\nappear if `visibility_restriction_selectors` include \"PREVIEW\"."
},
"protobufAny": {
"type": "object",
"properties": {
Expand Down
4 changes: 4 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ func findServicesMessagesAndEnumerations(s []*descriptor.Service, reg *descripto
for _, meth := range svc.Methods {
// Request may be fully included in query
{
if !isVisible(getMethodVisibilityOption(meth), reg) {
continue
}

swgReqName, ok := fullyQualifiedNameToOpenAPIName(meth.RequestType.FQMN(), reg)
if !ok {
glog.Errorf("couldn't resolve OpenAPI name for FQMN '%v'", meth.RequestType.FQMN())
Expand Down