diff options
author | George Wangensteen <george.wangensteen@mongodb.com> | 2020-10-21 19:29:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-05 19:25:44 +0000 |
commit | cf2f9b8dafe6a58340076b2ba39039e8bcb0a110 (patch) | |
tree | 3041c616fb004a10fc447ef197beedae112ae581 /buildscripts/idl | |
parent | 2b81759028c92187706c28229572f9e1bbe2933b (diff) | |
download | mongo-cf2f9b8dafe6a58340076b2ba39039e8bcb0a110.tar.gz |
SERVER-51373 Create IDL definition for OkReply
Diffstat (limited to 'buildscripts/idl')
-rw-r--r-- | buildscripts/idl/idl/errors.py | 8 | ||||
-rw-r--r-- | buildscripts/idl/idl/generator.py | 5 | ||||
-rw-r--r-- | buildscripts/idl/idl/parser.py | 4 | ||||
-rw-r--r-- | buildscripts/idl/tests/test_parser.py | 18 |
4 files changed, 14 insertions, 21 deletions
diff --git a/buildscripts/idl/idl/errors.py b/buildscripts/idl/idl/errors.py index dfa678105a8..72172aacbca 100644 --- a/buildscripts/idl/idl/errors.py +++ b/buildscripts/idl/idl/errors.py @@ -53,7 +53,6 @@ ERROR_ID_DUPLICATE_NODE = "ID0005" ERROR_ID_UNKNOWN_TYPE = "ID0006" ERROR_ID_IS_NODE_VALID_BOOL = "ID0007" ERROR_ID_UNKNOWN_NODE = "ID0008" -ERROR_ID_EMPTY_FIELDS = "ID0009" ERROR_ID_MISSING_REQUIRED_FIELD = "ID0010" ERROR_ID_ARRAY_NOT_VALID_TYPE = "ID0011" ERROR_ID_MISSING_AST_REQUIRED_FIELD = "ID0012" @@ -362,13 +361,6 @@ class ParserContext(object): self._add_node_error(node, ERROR_ID_DUPLICATE_NODE, "Duplicate node found for '%s'" % (node_name)) - def add_empty_struct_error(self, node, name): - # type: (yaml.nodes.Node, str) -> None - """Add an error about a struct without fields.""" - self._add_node_error(node, ERROR_ID_EMPTY_FIELDS, - ("Struct '%s' must either have fields, chained_types, or " + - "chained_structs specified but neither were found") % (name)) - def add_missing_required_field_error(self, node, node_parent, node_name): # type: (yaml.nodes.Node, str, str) -> None """Add an error about a YAML node missing a required child.""" diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index 81cec424345..caf340a9c3c 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -1533,6 +1533,10 @@ class _CppSourceFileWriter(_CppFileWriterBase): func_def = struct_type_info.get_deserializer_method().get_definition() with self._block('%s {' % (func_def), '}'): + # If the struct contains no fields, there's nothing to deserialize, so we write an empty function stub. + if not struct.fields: + return + # Deserialize all the fields field_usage_check = self._gen_fields_deserializer_common(struct, "bsonObject") @@ -1547,6 +1551,7 @@ class _CppSourceFileWriter(_CppFileWriterBase): """Generate the C++ deserializer method definitions from OpMsgRequest.""" # pylint: disable=invalid-name # Commands that have concatentate_with_db namespaces require db name as a parameter + # 'Empty' structs (those with no fields) don't need to be deserialized if not isinstance(struct, ast.Command): return diff --git a/buildscripts/idl/idl/parser.py b/buildscripts/idl/idl/parser.py index a70afe8b7d9..9378db49531 100644 --- a/buildscripts/idl/idl/parser.py +++ b/buildscripts/idl/idl/parser.py @@ -458,10 +458,6 @@ def _parse_struct(ctxt, spec, name, node): "generate_comparison_operators": _RuleDesc("bool_scalar"), }) - # TODO: SHOULD WE ALLOW STRUCTS ONLY WITH CHAINED STUFF and no fields??? - if struct.fields is None and struct.chained_types is None and struct.chained_structs is None: - ctxt.add_empty_struct_error(node, struct.name) - spec.symbols.add_struct(ctxt, struct) diff --git a/buildscripts/idl/tests/test_parser.py b/buildscripts/idl/tests/test_parser.py index 753ada14760..17ec8f76d9f 100644 --- a/buildscripts/idl/tests/test_parser.py +++ b/buildscripts/idl/tests/test_parser.py @@ -304,6 +304,15 @@ class TestParser(testcase.IDLTestcase): foo: bar """)) + # Missing fields + self.assert_parse( + textwrap.dedent(""" + structs: + foo: + description: foo + strict: true + """)) + def test_struct_negative(self): # type: () -> None """Negative struct test cases.""" @@ -315,15 +324,6 @@ class TestParser(testcase.IDLTestcase): foo: foo """), idl.errors.ERROR_ID_IS_NODE_TYPE) - # Missing fields - self.assert_parse_fail( - textwrap.dedent(""" - structs: - foo: - description: foo - strict: true - """), idl.errors.ERROR_ID_EMPTY_FIELDS) - # unknown field self.assert_parse_fail( textwrap.dedent(""" |