Skip to content

Fix gRPC stub validation#36

Merged
danslapman merged 1 commit intoleviysoft:mainfrom
ashashev:fix/grpc-prerequisite-validation
Dec 17, 2023
Merged

Fix gRPC stub validation#36
danslapman merged 1 commit intoleviysoft:mainfrom
ashashev:fix/grpc-prerequisite-validation

Conversation

@ashashev
Copy link
Copy Markdown
Contributor

@ashashev ashashev commented Dec 16, 2023

The validation fails if gRPC prerequisites refer to fields with custom types.

Problem

For example, with the following proto-file:

syntax = "proto3";

enum Bar {
  KZERO = 0;
  KONE = 1;
}

message Foo {
  string value = 1;
}

message Request {
    optional Bar bar = 1;
    optional Foo foo = 2;
}

message Response {
    string value = 1;
}

service Service {
    rpc Call (Request) returns (Response);
}

Attempt to create gRPC returns an error:

curl -i -X POST http://127.0.0.1:8228/api/internal/mockingbird/v2/grpcStub \
  -d '
{
  "name": "GRPC ***",
  "labels": [],
  "scope": "persistent",
  "methodName": "Service/Call",
  "requestCodecs": "c3ludGF4ID0gInByb3RvMyI7CgplbnVtIEJhciB7CiAgS1pFUk8gPSAwOwogIEtPTkUgPSAxOwp9CgptZXNzYWdlIEZvbyB7CiAgc3RyaW5nIHZhbHVlID0gMTsKfQoKbWVzc2FnZSBSZXF1ZXN0IHsKICAgIG9wdGlvbmFsIEJhciBiYXIgPSAxOwogICAgRm9vIGZvbyA9IDI7Cn0KCm1lc3NhZ2UgUmVzcG9uc2UgewogICAgc3RyaW5nIHZhbHVlID0gMTsKfQoKc2VydmljZSBTZXJ2aWNlIHsKICAgIHJwYyBDYWxsIChSZXF1ZXN0KSByZXR1cm5zIChSZXNwb25zZSk7Cn0K",
  "requestClass": "Request",
  "requestPredicates": {
    "bar": {"==": "KONE"},
    "foo.value": {"==": "foo"}
  },
  "responseCodecs": "c3ludGF4ID0gInByb3RvMyI7CgplbnVtIEJhciB7CiAgS1pFUk8gPSAwOwogIEtPTkUgPSAxOwp9CgptZXNzYWdlIEZvbyB7CiAgc3RyaW5nIHZhbHVlID0gMTsKfQoKbWVzc2FnZSBSZXF1ZXN0IHsKICAgIG9wdGlvbmFsIEJhciBiYXIgPSAxOwogICAgRm9vIGZvbyA9IDI7Cn0KCm1lc3NhZ2UgUmVzcG9uc2UgewogICAgc3RyaW5nIHZhbHVlID0gMTsKfQoKc2VydmljZSBTZXJ2aWNlIHsKICAgIHJwYyBDYWxsIChSZXF1ZXN0KSByZXR1cm5zIChSZXNwb25zZSk7Cn0K",
  "responseClass": "Response",
  "response": {
    "mode": "fill",
    "data": {
      "value": "OK: KONE, foo"
    }
  },
  "state": null,
  "seed": null,
  "service": "first"
}
'

The error is "Message with type .Bar not found".

@mockingbird/maintainers

The validation fails if gRPC prerequisites refer to fields with custom types.
Copy link
Copy Markdown
Member

@danslapman danslapman left a comment

Choose a reason for hiding this comment

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

LGTM

@danslapman danslapman merged commit 526c9d4 into leviysoft:main Dec 17, 2023
@ashashev ashashev deleted the fix/grpc-prerequisite-validation branch December 17, 2023 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants