Skip to content

Commit

Permalink
fix: support for nested messages and enums within group blocks (#1790)
Browse files Browse the repository at this point in the history
* fix: support for nested messages and enums within group blocks

* test: support for nested messages and enums within group blocks

Co-authored-by: Joshua Wise <joshua.wise@postman.com>
  • Loading branch information
JoshuaWise and JoshuaWisePostmanaut committed Aug 17, 2022
1 parent d87978b commit f36d4e4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/parse.js
Expand Up @@ -443,6 +443,14 @@ function parse(source, root, options) {
}
break;

case "message":
parseType(type, token);
break;

case "enum":
parseEnum(type, token);
break;

/* istanbul ignore next */
default:
throw illegal(token); // there are no groups with proto3 semantics
Expand Down
55 changes: 51 additions & 4 deletions tests/data/test.json
Expand Up @@ -412,18 +412,26 @@
"type": "OptionalGroup",
"id": 3
},
"messageInGroup": {
"type": "MessageInGroup",
"id": 4
},
"enumInGroup": {
"type": "EnumInGroup",
"id": 5
},
"id": {
"type": "string",
"id": 4
"id": 6
},
"requiredSimple": {
"rule": "required",
"type": "Simple2",
"id": 5
"id": 7
},
"optionalSimple": {
"type": "Simple2",
"id": 6
"id": 8
}
},
"nested": {
Expand Down Expand Up @@ -464,6 +472,45 @@
}
},
"group": true
},
"MessageInGroup": {
"fields": {
"id": {
"rule": "required",
"type": "NetedMessage",
"id": 1
}
},
"nested": {
"NetedMessage": {
"fields": {
"id": {
"rule": "optional",
"type": "string",
"id": 1
}
}
}
},
"group": true
},
"EnumInGroup": {
"fields": {
"id": {
"rule": "required",
"type": "NestedEnum",
"id": 1
}
},
"nested": {
"NestedEnum": {
"values": {
"first": 0,
"second": 1
}
}
},
"group": true
}
}
},
Expand Down Expand Up @@ -1514,4 +1561,4 @@
}
}
}
}
}
19 changes: 16 additions & 3 deletions tests/data/test.proto
Expand Up @@ -182,9 +182,22 @@ message TestGroup {
optional group OptionalGroup = 3 {
required string id = 1;
}
optional string id = 4;
required Simple2 required_simple = 5;
optional Simple2 optional_simple = 6;
optional group MessageInGroup = 4 {
message NestedMessage {
optional string id = 1;
}
required NestedMessage id = 1;
}
optional group EnumInGroup = 5 {
enum NestedEnum {
first = 0;
second = 1;
}
required NestedEnum id = 1;
}
optional string id = 6;
required Simple2 required_simple = 7;
optional Simple2 optional_simple = 8;
}

message TestGroup1 {
Expand Down

0 comments on commit f36d4e4

Please sign in to comment.