(self, def_dict, api, parent=None, language_model=None)
Construct a DataType.

    Args:
      def_dict: (dict) The discovery dictionary for this element.
      api: (Api) The Api instance which owns this element.
      parent: (CodeObject) The parent of this element.
      language_model: (LanguageModel) The language we are targetting.
        Dynamically defaults to the parent's language model.
Construct a DataType.
Construct a DataType .
def __init__(self, def_dict, api, parent=None, language_model=None):
    """Construct a DataType.

    Args:
      def_dict: (dict) The discovery dictionary for this element.
      api: (Api) The Api instance which owns this element.
      parent: (CodeObject) The parent of this element.
      language_model: (LanguageModel) The language we are targetting.
        Dynamically defaults to the parent's language model.
    """
    super(DataType, self).__init__(def_dict, api, parent=parent,
                                   language_model=language_model)
    self._json_type = def_dict.get('type')
    # If the schema has an id, that is a good default class name for it.
    schema_id = def_dict.get('id')
    if schema_id:
      self.SetTemplateValue('className', schema_id)
    # Top level primitive and container classes end up as known schema objects,
    # because some languages will want to generate definitions for them. Thus
    # they need a module. ComplexDataType instances might set a different
    # module in their constructor. The check for the api is to facilitiate
    # unit tests, which sometimes create types without any API.
    # TODO(user): Do not set _module here. Let it be dyanmically found from
    # the parent when needed. But, there is currently a problem with
    # BuildSchemaDefinitions where the top level schemas do not have a parent
    # because we are calling 'self.DataTypeFromJson(def_dict, name)' without
    # the parent parameter. If we add parent there, all hell seems to break.
    # Fix that and remove this.
    if self.api and hasattr(self.api, 'model_module'):
      self._module = self.api.model_module

    # Set some specific annotations as template values.
    annotations = def_dict.get('annotations')
    if annotations:
      required = annotations.get('required')
      self.SetTemplateValue('required_for_methods', required)
def __init__ ( self , def_dict , api , parent = None , language_model = None ) : super ( DataType , self ) . __init__ ( def_dict , api , parent = parent , language_model = language_model ) self . _json_type = def_dict . get ( 'type' ) # If the schema has an id, that is a good default class name for it. schema_id = def_dict . get ( 'id' ) if schema_id : self . SetTemplateValue ( 'className' , schema_id ) # Top level primitive and container classes end up as known schema objects, # because some languages will want to generate definitions for them. Thus # they need a module. ComplexDataType instances might set a different # module in their constructor. The check for the api is to facilitiate # unit tests, which sometimes create types without any API. # TODO(user): Do not set _module here. Let it be dyanmically found from # the parent when needed. But, there is currently a problem with # BuildSchemaDefinitions where the top level schemas do not have a parent # because we are calling 'self.DataTypeFromJson(def_dict, name)' without # the parent parameter. If we add parent there, all hell seems to break. # Fix that and remove this. if self . api and hasattr ( self . api , 'model_module' ) : self . _module = self . api . model_module # Set some specific annotations as template values. annotations = def_dict . get ( 'annotations' ) if annotations : required = annotations . get ( 'required' ) self . SetTemplateValue ( 'required_for_methods' , required )