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

mods to add Camel and snake_case for proto #13

Closed
wants to merge 6 commits into from
Closed

mods to add Camel and snake_case for proto #13

wants to merge 6 commits into from

Conversation

mamund
Copy link
Owner

@mamund mamund commented Dec 31, 2020

working to support better proto3 code styles.

src/index.js Outdated
@@ -185,65 +186,81 @@ function toProto(doc) {
// params
coll = doc.alps.descriptor.filter(semantic);
coll.forEach(function(msg) {
rtn += `message ${msg.id}Params {\n`;
val = makeSnakeCase(msg.id);

Choose a reason for hiding this comment

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

makePascalCase() should be applied here

Copy link
Owner Author

Choose a reason for hiding this comment

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

OK. will make this change.-- #thanks

Copy link
Owner Author

Choose a reason for hiding this comment

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

@corntoole :

pretty sure these changes resullt in an invalid proto file:

syntax = "proto3";
package ToDo_API;

// *******************************************************************
// generated by "unified" from todo-alps.yaml
// date: Thu Dec 31 2020 19:28:00 GMT-0500 (Eastern Standard Time)
// http://github.com/mamund/2020-11-unified
// *******************************************************************

message Id_params {
  string Id = 1;
}
message Body_params {
  string Body = 1;
}

message TodoItem {
  string id = 1;
  string body = 2;
}
message TodoItem_response {
  repeated TodoItem TodoItem_collection = 1;
}
message TodoItem_empty {}

service TodoApiService {
  rpc TodoList(todo_item_empty) returns (todo_item_response) {};
  rpc TodoAdd(todo_item) returns (todo_item_response) {};
  rpc TodoRemove(id_params) returns (todo_item_response) {};
}

wdyt?

src/index.js Outdated
rtn += '}\n';
});
rtn += '\n';

// objects
coll = doc.alps.descriptor.filter(groups);
coll.forEach(function(msg) {
rtn += `message ${msg.id} {\n`;
val = makeSnakeCase(msg.id);

Choose a reason for hiding this comment

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

Pascal case should be applied here as well.

Copy link
Owner Author

Choose a reason for hiding this comment

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

OK. will make this change.-- #thanks

Copy link
Owner Author

Choose a reason for hiding this comment

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

see above -- i think the snake and pascal casing routines no longer match

Copy link

@corntoole corntoole left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this issue. The changes so far fix the syntax errors caused by identifiers with en-dashes.

I left comments suggesting that Pascal case be applied anytime the converter is emit a proto Message type. Otherwise this looks good.

The .proto generated with this input still won't compile because the RPC method signatures contain references to undefined message types; but that should probably be addressed in separate issues through some combination of refining the mappings between ALPS and ProtocolBuffer concepts and/or tweaking the ALPS input for this particular case.

@mamund
Copy link
Owner Author

mamund commented Jan 1, 2021

@corntoole :

the ALPS file you are using as your example is not valid semantically. it contains several non-reference-able href values.

when you fix those, we can see if the latest changes have brokekn any proto syntax elements.

you can also test this w/ the todo-alps.yaml example in the repo. that should generate valid proto files.

@mamund
Copy link
Owner Author

mamund commented Jan 1, 2021

@corntoole

made additional mods to this branch to force the code to generate a valid proto file that passes validation using this protogen online site: https://protogen.marcgravell.com/

right now, it's all using makePascalCase() (not ideal, but it works). please check it out and let's see what needs to be changed to makeSnakeCase in order to get the proper style and still validate/generate valid code.

check out the todo-alps.yaml and todo-alps.proto files and let me know what you think.

@@ -185,65 +186,82 @@ function toProto(doc) {
// params
coll = doc.alps.descriptor.filter(semantic);
coll.forEach(function(msg) {
rtn += `message ${msg.id}Params {\n`;
val = makePascalCase(msg.id);
rtn += `message ${val}_params {\n`;
Copy link

@corntoole corntoole Jan 1, 2021

Choose a reason for hiding this comment

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

-- updated --
Also capture a snake-case formatted value to be used in the next hunk.

val1 = makeSnakeCase(msg.id);

var c = 0;
c++;
rtn += ` string ${msg.id} = ${c};\n`;
rtn += ` string ${val} = ${c};\n`;
Copy link

@corntoole corntoole Jan 1, 2021

Choose a reason for hiding this comment

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

-- update --
This should be snake-case.

use val1 (whatever variable you used to store the snake-case ID) here.

    rtn += `  string ${val1} = ${c};\n`;    

var c = 0;
msg.descriptor.forEach(function(prop) {
c++;
rtn += ` string ${prop.href} = ${c};\n`;
val2 = makePascalCase(prop.href.slice(1));

Choose a reason for hiding this comment

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

Use snake-case here

rtn += `message ${msg.id}Response {\n`;
rtn += ` repeated ${msg.id} ${msg.id}Collection = 1;\n`
rtn += `message ${val1}_response {\n`;
rtn += ` repeated ${val1} ${val1}_collection = 1;\n`
Copy link

@corntoole corntoole Jan 1, 2021

Choose a reason for hiding this comment

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

change to

    rtn += `  repeated ${val1} ${val1SnakeCase}_collection = 1;\n`

-- updated --
I did some testing. My earlier suggestion introduces a bug in the name of the collection field.
When processing group descriptors, grab a snake-case version of the descriptorID to be used as the name of the collection field.

@mamund
Copy link
Owner Author

mamund commented Apr 16, 2021

this PR has timed out. i'll take arnother run at this issue sometime soon.

@mamund mamund closed this Apr 16, 2021
@mamund mamund deleted the issue10 branch April 16, 2021 14:16
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