-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 1 commit
2393a5d
7856cba
5616ea1
e9d560d
397d971
16ed0f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
alps: | ||
version: "1.0" | ||
name: microblogging | ||
doc: "The example profile here contains details on customizing any representation media type for a specific \n application domain: Micro-blogging. It contains descriptions of valid data and transition values that \n can appear within resource representations. This document is presented as a complete blueprint for \n implementing a compliant client or server that supports the basic features of the target application \n domain (Micro-blogging)." | ||
# metadata | ||
ext: | ||
- type: metadata | ||
name: title | ||
value: microblogging | ||
tags: "oas" | ||
- type: metadata | ||
name: id | ||
value: https://corntoole.github.io/api-profiles/microblogging | ||
tags: "oas" | ||
- type: metadata | ||
name: root | ||
value: http://api.example.org/microblogging | ||
tags: "oas" | ||
link: | ||
rel: help | ||
href: "http://amundsen.com/hypermedia/profiles/" | ||
descriptor: | ||
- doc: "Contains the UTC date-time the message was posted. When present, it SHOULD be valid per RFC3339." | ||
id: "date-time" | ||
type: semantic | ||
- doc: "Contains the text description of a user." | ||
id: description | ||
type: semantic | ||
- doc: "" | ||
id: xx | ||
type: semantic | ||
- doc: "A list representation of unfiltered results." | ||
id: all | ||
type: semantic | ||
descriptor: | ||
- href: "#users" | ||
- href: "#messages" | ||
- id: friends | ||
type: semantic | ||
doc: "A list representation." | ||
descriptor: | ||
- href: "#users" | ||
- href: "#messages" | ||
- id: followers | ||
type: semantic | ||
doc: "A list representation of all the users from the designated user's friends list." | ||
descriptor: | ||
href: "#users" | ||
- id: me | ||
type: semantic | ||
doc: "Contains the list of messages posted by the designated user or contains\n the designated user's profile." | ||
descriptor: | ||
- href: "#users" | ||
- href: "#messages" | ||
- id: mentions | ||
type: semantic | ||
doc: "A list representation of all the messages that mention the designated user" | ||
descriptor: | ||
href: "#messages" | ||
- id: message | ||
type: semantic | ||
doc: "A representation of a single message." | ||
descriptor: | ||
- href: "#user-text" | ||
- href: "#user-link" | ||
- href: "#message-text" | ||
- href: "#message-link" | ||
- href: "#user-image" | ||
- href: "#date-time" | ||
- id: empty | ||
- doc: "A link template to add a new message to the system by the designated (logged-in) user." | ||
descriptor: | ||
- href: "#message-text" | ||
rt: empty | ||
id: "message-post" | ||
type: unsafe | ||
- doc: "A link template to reply to an existing message." | ||
descriptor: | ||
- doc: "the author of the post to be replied-to" | ||
href: "#user-text" | ||
name: user | ||
- href: "#message-text" | ||
name: message | ||
id: "message-reply" | ||
type: unsafe | ||
rt: empty | ||
# - doc: "" | ||
# id: xx | ||
# type: semantic |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,7 @@ function toProto(doc) { | |
var rtn = ""; | ||
var obj; | ||
var coll; | ||
var val; | ||
|
||
// preamble | ||
rtn += 'syntax = "proto3";\n'; | ||
|
@@ -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); | ||
rtn += `message ${val}_params {\n`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -- updated --
|
||
var c = 0; | ||
c++; | ||
rtn += ` string ${msg.id} = ${c};\n`; | ||
rtn += ` string ${val} = ${c};\n`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -- update -- use
|
||
rtn += '}\n'; | ||
}); | ||
rtn += '\n'; | ||
|
||
// objects | ||
coll = doc.alps.descriptor.filter(groups); | ||
coll.forEach(function(msg) { | ||
rtn += `message ${msg.id} {\n`; | ||
val = makeSnakeCase(msg.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pascal case should be applied here as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. will make this change.-- #thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
rtn += `message ${val} {\n`; | ||
var c = 0; | ||
msg.descriptor.forEach(function(prop) { | ||
c++; | ||
rtn += ` string ${prop.href} = ${c};\n`; | ||
}); | ||
rtn += '}\n'; | ||
rtn += `message ${msg.id}Response {\n`; | ||
rtn += ` repeated ${msg.id} ${msg.id}Collection = 1;\n` | ||
rtn += `message ${val}_response {\n`; | ||
rtn += ` repeated ${val} ${val}_collection = 1;\n` | ||
rtn += '}\n'; | ||
rtn += `message ${msg.id}Empty {}\n`; | ||
rtn += `message ${val}_empty {}\n`; | ||
}); | ||
rtn += '\n'; | ||
|
||
// procedures | ||
rtn += `service ${doc.alps.ext.filter(metadata_title)[0].value.replace(/ /g,'_')||"ALPS_API"}_Service {\n`; | ||
val = doc.alps.ext.filter(metadata_title)[0].value.replace(/ /g,'-')||"ALPS-API"; | ||
val = makePascalCase(val) | ||
rtn += `service ${val}Service {\n`; | ||
|
||
coll = doc.alps.descriptor.filter(safe); | ||
coll.forEach(function(item) { | ||
rtn += ` rpc ${item.id}(` | ||
val = item.id; | ||
val = makePascalCase(val); | ||
rtn += ` rpc ${val}(` | ||
if(item.descriptor) { | ||
rtn += item.descriptor[0].href; | ||
val = makeSnakeCase(item.descriptor[0].href); | ||
rtn += val; | ||
} | ||
else { | ||
rtn += `${item.rt}Empty`; | ||
val = makeSnakeCase(item.rt); | ||
rtn += `${val}_empty`; | ||
} | ||
rtn += `) returns (${item.rt}Response) {};\n`; | ||
rtn += `) returns (${val}_response) {};\n`; | ||
}); | ||
|
||
coll = doc.alps.descriptor.filter(unsafe); | ||
coll.forEach(function(item) { | ||
rtn += ` rpc ${item.id}(` | ||
var val = item.id; | ||
val = makePascalCase(val); | ||
rtn += ` rpc ${val}(` | ||
if(item.descriptor) { | ||
rtn += item.descriptor[0].href; | ||
val = makeSnakeCase(item.descriptor[0].href); | ||
rtn += val; | ||
} | ||
rtn += `) returns (${item.rt}Response) {};\n`; | ||
val = makeSnakeCase(item.rt); | ||
rtn += `) returns (${val}_response) {};\n`; | ||
}); | ||
|
||
coll = doc.alps.descriptor.filter(idempotent); | ||
coll.forEach(function(item) { | ||
rtn += ` rpc ${item.id}(` | ||
var val = item.id; | ||
val = makePascalCase(val); | ||
rtn += ` rpc ${val}(` | ||
if(item.descriptor) { | ||
rtn += item.descriptor[0].href; | ||
val = makeSnakeCase(item.descriptor[0].href); | ||
rtn += val; | ||
if(item.descriptor[0].href === "#id") { | ||
rtn += "Params"; | ||
rtn += "_params"; | ||
} | ||
} | ||
rtn += `) returns (${item.rt}Response) {};\n`; | ||
val = makeSnakeCase(item.rt); | ||
rtn += `) returns (${val}_response) {};\n`; | ||
}); | ||
|
||
rtn += '}\n'; | ||
|
@@ -516,6 +533,40 @@ function toAsync(doc) { | |
return rtn; | ||
} | ||
|
||
//******************************************* | ||
// general support | ||
//******************************************* | ||
|
||
function makePascalCase(value) { | ||
var rtn = ""; | ||
var coll = []; | ||
coll = value.split('-'); | ||
if(coll.length===0) { | ||
coll = value.split('_'); | ||
} | ||
if(coll.length===0) { | ||
coll.push(rtn); | ||
} | ||
coll.forEach(function(item) { | ||
rtn += item.charAt(0).toUpperCase() + item.slice(1) | ||
}); | ||
return rtn; | ||
} | ||
|
||
function makeSnakeCase(value) { | ||
var rtn = ""; | ||
var coll = []; | ||
coll = value.split('-'); | ||
if(coll.length===0) { | ||
coll.push(rtn); | ||
} | ||
coll.forEach(function(item) { | ||
rtn += item.toLowerCase()+'_'; | ||
}); | ||
rtn = rtn.substring(0, rtn.length - 1); | ||
return rtn; | ||
} | ||
|
||
//******************************************* | ||
// collection filters | ||
//******************************************* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makePascalCase()
should be applied hereThere was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
wdyt?