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

Expose presence of explicit optional keyword on fields #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ var onfield = function (tokens) {
case 'repeated':
case 'required':
case 'optional':
case 'implicit-optional':
var t = tokens.shift()
field.required = t === 'required'
field.repeated = t === 'repeated'
if (t === 'optional') { field.optional = true }
field.type = tokens.shift()
field.name = tokens.shift()
break
Expand Down Expand Up @@ -219,7 +221,7 @@ var onmessagebody = function (tokens) {
// proto3 does not require the use of optional/required, assumed as optional
// "singular: a well-formed message can have zero or one of this field (but not more than one)."
// https://developers.google.com/protocol-buffers/docs/proto3#specifying-field-rules
tokens.unshift('optional')
tokens.unshift('implicit-optional')
body.fields.push(onfield(tokens))
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down Expand Up @@ -81,6 +82,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down Expand Up @@ -81,6 +82,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/complex.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {
"default": "HOME"
}
Expand Down Expand Up @@ -85,6 +86,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}, {
"name": "phone",
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/extend.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -49,6 +50,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -59,6 +61,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand Down Expand Up @@ -89,6 +92,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -109,6 +113,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -119,6 +124,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand Down Expand Up @@ -147,6 +153,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -157,6 +164,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/oneof.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"oneof": "test_oneof",
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -29,6 +30,7 @@
"oneof": "test_oneof",
"required": false,
"repeated": false,
"optional": true,
"options": {}
}

Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/option.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {
"my_field_option": "4.5"
}
Expand All @@ -54,6 +55,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand Down Expand Up @@ -92,6 +94,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
},
{
Expand All @@ -102,6 +105,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -122,6 +126,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {
"foo_options": {
"opt1": "123",
Expand All @@ -137,6 +142,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {
"foo_options": {
"opt1": "123",
Expand Down Expand Up @@ -169,6 +175,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -192,6 +199,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -215,6 +223,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -238,6 +247,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -261,6 +271,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -284,6 +295,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -307,6 +319,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand All @@ -330,6 +343,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
],
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {
"mylist": "\"some,values,[here]\""
}
Expand All @@ -36,6 +37,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {
"mylist2": "'[more, values], [here]'"
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"map": null,
"oneof": null,
"required": false,
"repeated": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down Expand Up @@ -81,6 +82,7 @@
"oneof": null,
"required": false,
"repeated": false,
"optional": true,
"options": {}
}
]
Expand Down