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

feat: add RPCs returning unknown enum values over REST #856

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

vchudnov-g
Copy link
Contributor

This adds two new RPCs, Compliance.RepeatWithUnknown{,Optional}Enum() which, when called over REST, populate enum fields in the JSON responses with string values that do not correspond to enum values in the protobuf definition. This should be used by generators to ensure that when the server returns an unknown enum value as part of a REST response, the GAPICs handle it gracefully.

Below are command-line examples of calling these RPCs. Note that LIFE_KINGDOM_NEW is the unknown enum value not present in the proto.

Non-optional enum fields:

❯ curl -i -X POST http://localhost:7469/v1beta1/repeat:invalidenum -d'{}' -H "Content-Type: application/json" -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0"                                                                    
HTTP/1.1 200 OK
Date: Wed, 25 Aug 2021 17:34:20 GMT
Content-Length: 514
Content-Type: text/plain; charset=utf-8

{
  "request": {
    "name": "",
    "info": {
      "fString": "",
      "fInt32": 0,
      "fSint32": 0,
      "fSfixed32": 0,
      "fUint32": 0,
      "fFixed32": 0,
      "fInt64": "0",
      "fSint64": "0",
      "fSfixed64": "0",
      "fUint64": "0",
      "fFixed64": "0",
      "fDouble": 0,
      "fFloat": 0,
      "fBool": false,
      "fBytes": "",
      "fKingdom": "LIFE_KINGDOM_NEW",
      "fChild": null
    },
    "serverVerify": false,
    "fInt32": 0,
    "fInt64": "0",
    "fDouble": 0
  }
}

Optional enum fields:

❯ curl -i -X POST http://localhost:7469/v1beta1/repeat:invalidoptionalenum -d'{}' -H "Content-Type: application/json" -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0"
HTTP/1.1 200 OK
Date: Wed, 25 Aug 2021 17:35:22 GMT
Content-Length: 560
Content-Type: text/plain; charset=utf-8

{
  "request": {
    "name": "",
    "info": {
      "fString": "",
      "fInt32": 0,
      "fSint32": 0,
      "fSfixed32": 0,
      "fUint32": 0,
      "fFixed32": 0,
      "fInt64": "0",
      "fSint64": "0",
      "fSfixed64": "0",
      "fUint64": "0",
      "fFixed64": "0",
      "fDouble": 0,
      "fFloat": 0,
      "fBool": false,
      "fBytes": "",
      "fKingdom": "LIFE_KINGDOM_UNSPECIFIED",
      "fChild": null,
      "pKingdom": "LIFE_KINGDOM_NEW"
    },
    "serverVerify": false,
    "fInt32": 0,
    "fInt64": "0",
    "fDouble": 0
  }
}

NEXT:
- clean up init function for go view creator
- add custom operation for unknown enum
NEXT: need tests, clean up code
Asa  result of the test, also fixed NPE by ensuring submessages are present before referencing them.
This allows isolating unknown enum values in specific fields.
@vchudnov-g vchudnov-g requested a review from a team as a code owner August 25, 2021 17:43
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 25, 2021
Comment on lines +104 to +116
rpc RepeatWithUnknownEnum(RepeatRequest) returns (RepeatResponse) {
option (google.api.http) = {
post: "/v1beta1/repeat:invalidenum"
body: "*"
};
}

// This method returns an unknown value for an optional enum field. Client libraries should either
// error gracefully (not crash), ignore the value, or, depending on the API, set it to the zero
// default.
//
// This only works over REST currently. Requests over gRPC will simply echo the request.
rpc RepeatWithUnknownOptionalEnum(RepeatRequest) returns (RepeatResponse) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these be one request with two fields and maybe a field to toggle behavior? For example, we have the Echo RPC which could return either an EchoResponse or an error status depending on what was sent in the request oneof. Might simplify the implementation a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about this (and sidetracked by other issues, sorry). We could keep just the previously existing RPCs and add a top-level field to RepeatRequest to generate the unknown enum. In fact, I would change RepeatRequest.server_verify to be an enum like server_behavior that could be verify, or generate_unknown_enum, or something else in the future.

Not too concerned about that being a breaking change because (a) most generators are not yet using the compliance suite, and (b) the compliance suite is meant to be parsed form this repo and then used to issue requests, without the client code modifying the request.

WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds great to me. Thanks for considering this.

@parthea parthea assigned parthea and unassigned parthea Apr 17, 2024
@parthea parthea marked this pull request as draft April 17, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants