def _add_data_types_and_routes_to_api(self, namespace, desc):
env = self._get_or_create_env(namespace.name)<EOL>for item in desc:<EOL><INDENT>if isinstance(item, AstTypeDef):<EOL><INDENT>api_type = self._create_type(env, item)<EOL>namespace.add_data_type(api_type)<EOL>self._check_canonical_name_available(item, namespace.name)<EOL><DEDENT>elif isinstance(item, AstStructPatch) or isinstance(item, AstUnionPatch):<EOL><INDENT>base_name = self._get_base_name(item.name, namespace.name)<EOL>self._patch_data_by_canonical_name[base_name] = (item, namespace)<EOL><DEDENT>elif isinstance(item, AstRouteDef):<EOL><INDENT>route = self._create_route(env, item)<EOL>namespace.add_route(route)<EOL>self._check_canonical_name_available(item, namespace.name, allow_duplicate=True)<EOL><DEDENT>elif isinstance(item, AstImport):<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(item, AstAlias):<EOL><INDENT>alias = self._create_alias(env, item)<EOL>namespace.add_alias(alias)<EOL>self._check_canonical_name_available(item, namespace.name)<EOL><DEDENT>elif isinstance(item, AstAnnotationDef):<EOL><INDENT>annotation = self._create_annotation(env, item)<EOL>namespace.add_annotation(annotation)<EOL>self._check_canonical_name_available(item, namespace.name)<EOL><DEDENT>elif isinstance(item, AstAnnotationTypeDef):<EOL><INDENT>annotation_type = self._create_annotation_type(env, item)<EOL>namespace.add_annotation_type(annotation_type)<EOL>self._check_canonical_name_available(item, namespace.name)<EOL><DEDENT>else:<EOL><INDENT>raise AssertionError('<STR_LIT>' %<EOL>item.__class__.__name__)<EOL><DEDENT><DEDENT>
From the raw output of the parser, create forward references for each
user-defined type (struct, union, route, and alias).

Args:
    namespace (stone.api.Namespace): Namespace for definitions.
    desc (List[stone.stone.parser._Element]): All AST nodes in a spec
        file in the order they were defined. Should not include a
        namespace declaration.