(cls, api, default_name, def_dict, wire_name, parent=None)
Construct a Schema or DataType from a discovery dictionary.

    Schemas contain either object declarations, simple type declarations, or
    references to other Schemas.  Object declarations conceptually map to real
    classes.  Simple types will map to a target language built-in type.
    References should effectively be replaced by the referenced Schema.

    Args:
      api: (Api) the Api instance owning the Schema
      default_name: (str) the default name of the Schema. If there is an 'id'
        member in the definition, that is used for the name instead.
      def_dict: (dict) a discovery dictionary
      wire_name: The name which will identify objects of this type in data on
        the wire. The path of wire_names can trace an item back through
        discovery.
      parent: (Schema) The containing schema. To be used to establish nesting
        for anonymous sub-schemas.

    Returns:
      A Schema or DataType.

    Raises:
      ApiException: If the definition dict is not correct.
Construct a Schema or DataType from a discovery dictionary.
Construct a Schema or DataType from a discovery dictionary .
def Create(cls, api, default_name, def_dict, wire_name, parent=None):
    """Construct a Schema or DataType from a discovery dictionary.

    Schemas contain either object declarations, simple type declarations, or
    references to other Schemas.  Object declarations conceptually map to real
    classes.  Simple types will map to a target language built-in type.
    References should effectively be replaced by the referenced Schema.

    Args:
      api: (Api) the Api instance owning the Schema
      default_name: (str) the default name of the Schema. If there is an 'id'
        member in the definition, that is used for the name instead.
      def_dict: (dict) a discovery dictionary
      wire_name: The name which will identify objects of this type in data on
        the wire. The path of wire_names can trace an item back through
        discovery.
      parent: (Schema) The containing schema. To be used to establish nesting
        for anonymous sub-schemas.

    Returns:
      A Schema or DataType.

    Raises:
      ApiException: If the definition dict is not correct.
    """

    schema_id = def_dict.get('id')
    if schema_id:
      name = schema_id
    else:
      name = default_name
    class_name = api.ToClassName(name, None, element_type='schema')

    _LOGGER.debug('Create: %s, parent=%s', name,
                  parent.values.get('wireName', '<anon>') if parent else 'None')

    # Schema objects come in several patterns.
    #
    # 1. Simple objects
    #    { type: object, properties: { "foo": {schema} ... }}
    #
    # 2. Maps of objects
    #    { type: object, additionalProperties: { "foo": {inner_schema} ... }}
    #
    #    What we want is a data type which is Map<string, {inner_schema}>
    #    The schema we create here is essentially a built in type which we
    #    don't want to generate a class for.
    #
    # 3. Arrays of objects
    #    { type: array, items: { inner_schema }}
    #
    #    Same kind of issue as the map, but with List<{inner_schema}>
    #
    # 4. Primitive data types, described by type and format.
    #    { type: string, format: int32 }
    #    { type: string, enum: ["value", ...], enumDescriptions: ["desc", ...]}
    #
    # 5. Refs to another schema.
    #    { $ref: name }
    #
    # 6. Variant schemas
    #    { type: object, variant: { discriminant: "prop", map:
    #             [ { 'type_value': value, '$ref': wireName }, ... ] } }
    #
    #    What we do is map the variant schema to a schema with a single
    #    property for the discriminant. To that property, we attach
    #    the variant map which specifies which discriminator values map
    #    to which schema references. We also collect variant information
    #    in the api so we can later associate discriminator value and
    #    base type with the generated variant subtypes.

    if 'type' in def_dict:
      # The 'type' field of the schema can either be 'array', 'object', or a
      # base json type.
      json_type = def_dict['type']
      if json_type == 'object':

        # Look for variants
        variant = def_dict.get('variant')
        if variant:
          return cls._CreateVariantType(variant, api, name,
                                        def_dict, wire_name, parent)

        # Look for full object definition.  You can have properties or
        # additionalProperties, but it does not  do anything useful to have
        # both.

        # Replace properties dict with Property's
        props = def_dict.get('properties')
        if props:
          # This case 1 from above
          return cls._CreateObjectWithProperties(props, api, name,
                                                 def_dict, wire_name, parent)

        # Look for case 2
        additional_props = def_dict.get(_ADDITIONAL_PROPERTIES)
        if additional_props:
          return cls._CreateMapType(additional_props, api, name, wire_name,
                                    class_name, parent)

        # no properties
        return cls._CreateSchemaWithoutProperties(api, name, def_dict,
                                                  wire_name, parent)

      elif json_type == 'array':
        # Case 3: Look for array definition
        return cls._CreateArrayType(api, def_dict, wire_name, class_name,
                                    schema_id, parent)
      else:
        # Case 4: This must be a basic type.  Create a DataType for it.
        return data_types.CreatePrimitiveDataType(def_dict, api, wire_name,
                                                  parent=parent)

    referenced_schema = def_dict.get('$ref')
    if referenced_schema:
      # Case 5: Reference to another Schema.
      #
      # There are 4 ways you can see '$ref' in discovery.
      # 1. In a property of a schema or a method request/response, pointing
      #    back to a previously defined schema
      # 2. As above, pointing to something not defined yet.
      # 3. In a method request or response or property of a schema pointing to
      #    something undefined.
      #
      # For case 1, the schema will be in the API name to schema map.
      #
      # For case 2, just creating this placeholder here is fine.  When the
      # actual schema is hit in the loop in _BuildSchemaDefinitions, we will
      # replace the entry and DataTypeFromJson will resolve the to the new def.
      #
      # For case 3, we will end up with a dangling reference and fail later.
      schema = api.SchemaByName(referenced_schema)
      # The stored "schema" may not be an instance of Schema, but rather a
      # data_types.PrimitiveDataType, which has no 'wireName' value.
      if schema:
        _LOGGER.debug('Schema.Create: %s => %s',
                      default_name, schema.values.get('wireName', '<unknown>'))
        return schema
      return data_types.SchemaReference(referenced_schema, api)

    raise ApiException('Cannot decode JSON Schema for: %s' % def_dict)
def Create ( cls , api , default_name , def_dict , wire_name , parent = None ) : schema_id = def_dict . get ( 'id' ) if schema_id : name = schema_id else : name = default_name class_name = api . ToClassName ( name , None , element_type = 'schema' ) _LOGGER . debug ( 'Create: %s, parent=%s' , name , parent . values . get ( 'wireName' , '<anon>' ) if parent else 'None' ) # Schema objects come in several patterns. # # 1. Simple objects #    { type: object, properties: { "foo": {schema} ... }} # # 2. Maps of objects #    { type: object, additionalProperties: { "foo": {inner_schema} ... }} # #    What we want is a data type which is Map<string, {inner_schema}> #    The schema we create here is essentially a built in type which we #    don't want to generate a class for. # # 3. Arrays of objects #    { type: array, items: { inner_schema }} # #    Same kind of issue as the map, but with List<{inner_schema}> # # 4. Primitive data types, described by type and format. #    { type: string, format: int32 } #    { type: string, enum: ["value", ...], enumDescriptions: ["desc", ...]} # # 5. Refs to another schema. #    { $ref: name } # # 6. Variant schemas #    { type: object, variant: { discriminant: "prop", map: #             [ { 'type_value': value, '$ref': wireName }, ... ] } } # #    What we do is map the variant schema to a schema with a single #    property for the discriminant. To that property, we attach #    the variant map which specifies which discriminator values map #    to which schema references. We also collect variant information #    in the api so we can later associate discriminator value and #    base type with the generated variant subtypes. if 'type' in def_dict : # The 'type' field of the schema can either be 'array', 'object', or a # base json type. json_type = def_dict [ 'type' ] if json_type == 'object' : # Look for variants variant = def_dict . get ( 'variant' ) if variant : return cls . _CreateVariantType ( variant , api , name , def_dict , wire_name , parent ) # Look for full object definition.  You can have properties or # additionalProperties, but it does not  do anything useful to have # both. # Replace properties dict with Property's props = def_dict . get ( 'properties' ) if props : # This case 1 from above return cls . _CreateObjectWithProperties ( props , api , name , def_dict , wire_name , parent ) # Look for case 2 additional_props = def_dict . get ( _ADDITIONAL_PROPERTIES ) if additional_props : return cls . _CreateMapType ( additional_props , api , name , wire_name , class_name , parent ) # no properties return cls . _CreateSchemaWithoutProperties ( api , name , def_dict , wire_name , parent ) elif json_type == 'array' : # Case 3: Look for array definition return cls . _CreateArrayType ( api , def_dict , wire_name , class_name , schema_id , parent ) else : # Case 4: This must be a basic type.  Create a DataType for it. return data_types . CreatePrimitiveDataType ( def_dict , api , wire_name , parent = parent ) referenced_schema = def_dict . get ( '$ref' ) if referenced_schema : # Case 5: Reference to another Schema. # # There are 4 ways you can see '$ref' in discovery. # 1. In a property of a schema or a method request/response, pointing #    back to a previously defined schema # 2. As above, pointing to something not defined yet. # 3. In a method request or response or property of a schema pointing to #    something undefined. # # For case 1, the schema will be in the API name to schema map. # # For case 2, just creating this placeholder here is fine.  When the # actual schema is hit in the loop in _BuildSchemaDefinitions, we will # replace the entry and DataTypeFromJson will resolve the to the new def. # # For case 3, we will end up with a dangling reference and fail later. schema = api . SchemaByName ( referenced_schema ) # The stored "schema" may not be an instance of Schema, but rather a # data_types.PrimitiveDataType, which has no 'wireName' value. if schema : _LOGGER . debug ( 'Schema.Create: %s => %s' , default_name , schema . values . get ( 'wireName' , '<unknown>' ) ) return schema return data_types . SchemaReference ( referenced_schema , api ) raise ApiException ( 'Cannot decode JSON Schema for: %s' % def_dict )