Skip to content

Commit

Permalink
fix: oneof name convert to camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
askuzminov committed Dec 25, 2020
1 parent 3a7f196 commit c413e12
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion proto/whisk/api/user/v2/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ message TestEmpty {

message GlobalRegion {}

oneof item {
oneof item_name_long {
GlobalRegion global = 2 [ required = true ];
GlobalRegion any = 3;
string local = 4;
Expand Down
2 changes: 2 additions & 0 deletions src/generator/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function message(pack: string, out: MakeOuts, item: Message, list: List[], enums
const required = isRequired(field);

if (isText(field.oneof)) {
field.oneof = camelCase(field.oneof);

oneof[field.oneof] = oneof[field.oneof] ?? [];
oneof[field.oneof].push(field);
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/oneof.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ describe('protobuf wrapper', () => {
it('encode/decode', () => {
const dataX: whisk_api_user_v2_TestEmpty = {
id: '1',
item: {
itemNameLong: {
oneof: 'global',
value: {},
},
};

const dataY = {
id: '1',
device: 'global',
itemNameLong: 'global',
global: {},
};

Expand Down
6 changes: 3 additions & 3 deletions tests/proto/debug/whisk/api/user/v2/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@
"options": {
"required": true
},
"oneof": "item"
"oneof": "item_name_long"
},
{
"name": "any",
Expand All @@ -1270,7 +1270,7 @@
"repeated": false,
"optional": false,
"options": {},
"oneof": "item"
"oneof": "item_name_long"
},
{
"name": "local",
Expand All @@ -1280,7 +1280,7 @@
"repeated": false,
"optional": false,
"options": {},
"oneof": "item"
"oneof": "item_name_long"
}
],
"extends": [],
Expand Down
6 changes: 3 additions & 3 deletions tests/proto/esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,9 @@ export var whisk_api_user_v2_TestOneof = function () { return [
]; };
export var whisk_api_user_v2_TestEmpty = function () { return [
[1, "id", "string", 1],
[2, "global", whisk_api_user_v2_TestEmpty_GlobalRegion, 1, "item"],
[3, "any", whisk_api_user_v2_TestEmpty_GlobalRegion, 0, "item"],
[4, "local", "string", 1, "item"],
[2, "global", whisk_api_user_v2_TestEmpty_GlobalRegion, 1, "itemNameLong"],
[3, "any", whisk_api_user_v2_TestEmpty_GlobalRegion, 0, "itemNameLong"],
[4, "local", "string", 1, "itemNameLong"],
]; };
export var whisk_api_user_v2_TestEmpty_GlobalRegion = function () { return []; };
export var whisk_api_user_v2_SearchRecipesResponse = function () { return [
Expand Down
2 changes: 1 addition & 1 deletion tests/proto/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ export type whisk_api_user_v2_TestOneof = {
export const whisk_api_user_v2_TestOneof: Field<whisk_api_user_v2_TestOneof>;
export type whisk_api_user_v2_TestEmpty = {
id: string;
item?:
itemNameLong?:
| { oneof: 'global'; value: whisk_api_user_v2_TestEmpty_GlobalRegion; }
| { oneof: 'any'; value?: whisk_api_user_v2_TestEmpty_GlobalRegion; }
| { oneof: 'local'; value: string; };
Expand Down
6 changes: 3 additions & 3 deletions tests/proto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ var whisk_api_user_v2_TestOneof = function () { return [
exports.whisk_api_user_v2_TestOneof = whisk_api_user_v2_TestOneof;
var whisk_api_user_v2_TestEmpty = function () { return [
[1, "id", "string", 1],
[2, "global", exports.whisk_api_user_v2_TestEmpty_GlobalRegion, 1, "item"],
[3, "any", exports.whisk_api_user_v2_TestEmpty_GlobalRegion, 0, "item"],
[4, "local", "string", 1, "item"],
[2, "global", exports.whisk_api_user_v2_TestEmpty_GlobalRegion, 1, "itemNameLong"],
[3, "any", exports.whisk_api_user_v2_TestEmpty_GlobalRegion, 0, "itemNameLong"],
[4, "local", "string", 1, "itemNameLong"],
]; };
exports.whisk_api_user_v2_TestEmpty = whisk_api_user_v2_TestEmpty;
var whisk_api_user_v2_TestEmpty_GlobalRegion = function () { return []; };
Expand Down
2 changes: 1 addition & 1 deletion tests/protobufjs/json-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ const $root = ($protobuf.roots["default"] || ($protobuf.roots["default"] = new $
},
TestEmpty: {
oneofs: {
item: {
itemNameLong: {
oneof: [
"global",
"any",
Expand Down
2 changes: 1 addition & 1 deletion tests/protobufjs/json.json
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@
},
"TestEmpty": {
"oneofs": {
"item": {
"itemNameLong": {
"oneof": [
"global",
"any",
Expand Down
4 changes: 2 additions & 2 deletions tests/protobufjs/out.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4393,8 +4393,8 @@ export namespace whisk {
/** TestEmpty local. */
public local: string;

/** TestEmpty item. */
public item?: ("global"|"any"|"local");
/** TestEmpty itemNameLong. */
public itemNameLong?: ("global"|"any"|"local");

/**
* Encodes the specified TestEmpty message. Does not implicitly {@link whisk.api.user.v2.TestEmpty.verify|verify} messages.
Expand Down
6 changes: 3 additions & 3 deletions tests/protobufjs/out.js
Original file line number Diff line number Diff line change
Expand Up @@ -9881,12 +9881,12 @@ export const whisk = $root.whisk = (() => {
let $oneOfFields;

/**
* TestEmpty item.
* @member {"global"|"any"|"local"|undefined} item
* TestEmpty itemNameLong.
* @member {"global"|"any"|"local"|undefined} itemNameLong
* @memberof whisk.api.user.v2.TestEmpty
* @instance
*/
Object.defineProperty(TestEmpty.prototype, "item", {
Object.defineProperty(TestEmpty.prototype, "itemNameLong", {
get: $util.oneOfGetter($oneOfFields = ["global", "any", "local"]),
set: $util.oneOfSetter($oneOfFields)
});
Expand Down

0 comments on commit c413e12

Please sign in to comment.