Bug with optional fields in .proto and one more thing
ngorohov opened this issue · comments
Hello.
I've tried to generate some JS client for my Twirp server and found these bugs:
1.
api/v1/dummy.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-twirpscript hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--twirpscript_out:
- there is no notes in readme about supporting optional fields, but in example You use proto3, that's why I've decide that You support it.
- Some of my .proto files just not complie with syntax error:
/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/index.js:12528
throw error;
^
SyntaxError: Unexpected token, expected "," (65:240)
63 | path: 'api.v1.CheckService',
64 | methods: {
> 65 | Info: createMethodHandler({ handler: service.Info, encode: InfoResponse.encode, decode: InfoRequest.decode }),DoStuff: createMethodHandler({ handler: service.DoStuff, encode: DoStuffResponse.encode, decode: DoStuffRequest.decode }),export function createVerificationServiceHandler(service) { return {
| ^
66 | path: 'api.v1.VerificationService',
67 | methods: {
68 | Verify: createMethodHandler({ handler: service.Verify, encode: VerifyResponse.encode, decode: VerifyRequest.decode }),}
at li (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/parser-babel.js:22:11986)
at di (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/parser-babel.js:22:12115)
at Object.parse (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/parser-babel.js:22:336232)
at Object.parse$a [as parse] (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/index.js:12513:19)
at coreFormat (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/index.js:14044:16)
at formatWithCursor$1 (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/index.js:14284:14)
at /Users/ngorohov/projects/node/twirphouse/node_modules/prettier/index.js:59304:12
at format (/Users/ngorohov/projects/node/twirphouse/node_modules/prettier/index.js:59324:12)
at writeFile (/Users/ngorohov/projects/node/twirphouse/node_modules/twirpscript/dist/compiler.js:18:43)
at /Users/ngorohov/projects/node/twirphouse/node_modules/twirpscript/dist/compiler.js:27:5 {
loc: { start: { line: 65, column: 240 } },
codeFrame: " 63 | path: 'api.v1.CheckService',\n" +
' 64 | methods: {\n' +
'> 65 | Info: createMethodHandler({ handler: service.Info, encode: InfoResponse.encode, decode: InfoRequest.decode }),DoStuff: createMethodHandler({ handler: service.DoStuff, encode: DoStuffResponse.encode, decode: DoStuffRequest.decode }),export function createVerificationServiceHandler(service) { return {\n' +
' | ^\n' +
" 66 | path: 'api.v1.VerificationService',\n" +
' 67 | methods: {\n' +
' 68 | Verify: createMethodHandler({ handler: service.Verify, encode: VerifyResponse.encode, decode: VerifyRequest.decode }),}'
}
there's example file:
syntax = "proto3";
package api.v1;
option go_package = "./;api";
service CheckService {
rpc Info(InfoRequest) returns (InfoResponse);
rpc DoStuff(DoStuffRequest) returns (DoStuffResponse);
}
message InfoRequest {}
message DoStuffRequest {}
message InfoResponse {
string hostname = 1;
}
message DoStuffResponse {
string data = 1;
}
service VerificationService {
rpc Verify(VerifyRequest) returns (VerifyResponse);
}
message VerifyRequest {
string token = 1;
int64 nonce = 2;
}
message VerifyResponse {
bool status = 1;
string sign = 2;
}
So due to package it located in /api/v1 directory
Hey @ngorohov I'll take a look at this. Thank you for the examples.
#11 fixes bullet point 2. Generation was failing when multiple services were defined in the same proto -- sorry about that!
This has been released in v0.0.23.
Protobuf v3.15 reintroduced optional
fields (after removing them in the 2
-> 3 conversion) https://github.com/protocolbuffers/protobuf/releases/tag/v3.15.0. I'm happy to look into support in TwirpScript.
I published v0.0.24 with support for proto3 optional
labels. Try it out and let me know if you run into any issues!