code: def _add_example_helper(self, example):
          
  
          # Check for fields in the example that don't belong.
          for label, example_field in example.fields.items():
              if not any(label == f.name for f in self.all_fields):
                  raise InvalidSpec(
                      "Example for '%s' has unknown field '%s'." %
                      (self.name, label),
                      example_field.lineno, example_field.path,
                  )
  
          for field in self.all_fields:
              if field.name in example.fields:
                  example_field = example.fields[field.name]
                  try:
                      field.data_type.check_example(example_field)
                  except InvalidSpec as e:
                      e.msg = "Bad example for field '{}': {}".format(
                          field.name, e.msg)
                      raise
              elif field.has_default or isinstance(field.data_type, Nullable):
                  # These don't need examples.
                  pass
              else:
                  raise InvalidSpec(
                      "Missing field '%s' in example." % field.name,
                      example.lineno, example.path)
  
          self._raw_examples[example.label] = example
docs: Validates examples for structs without enumerated subtypes.