# Path: rest_framework_json_schema/exceptions.py
# class NoSchema(Exception):
#     """
#     Schema not found on the data to render.
# 
#     This is a programmer error.
#     """
# 
# Path: rest_framework_json_schema/schema.py
# class Context:
# class BaseLinkedObject:
# class ResourceObject(BaseLinkedObject):
# class ResourceIdObject(BaseLinkedObject):
# class RelationshipObject(BaseLinkedObject):
# class LinkObject:
# class UrlLink(LinkObject):
#     def __init__(
#         self,
#         request: Request,
#         include: Optional[Dict] = None,
#         fields: Optional[Dict] = None,
#     ) -> None:
#     def render_links(self, data: ObjDataType, context: Context) -> OrderedDict:
#     def render_meta(self, data: Any, context: Context) -> Optional[Dict]:
#     def __init__(self, **kwargs: Any) -> None:
#         def _normalize_rel(rel: RelOptType) -> RelType:
#     def parse(self, data: ObjDataType, context: Context) -> Dict:
#     def render(self, data: ObjDataType, context: Context) -> RenderResultType:
#     def render_attributes(self, data: Dict, context: Context) -> ObjDataType:
#     def render_relationships(self, data: Dict, context: Context) -> RenderResultType:
#     def render_relationship(
#         self, data: Dict, rel_name: str, rel: "RelationshipObject", context: Context
#     ) -> RenderResultType:
#     def from_data(self, data: Dict, attr: str) -> Any:
#     def filter_by_fields(
#         self, names: Sequence[RelType], fields: Dict, name_fn: Callable[[RelType], str]
#     ) -> Iterator[RelType]:
#     def filter_by_fields(
#         self, names: Sequence[str], fields: Dict, name_fn: Callable[[str], str]
#     ) -> Iterator[str]:
#     def filter_by_fields(
#         self, names: Sequence[Any], fields: Dict, name_fn: Callable[[Any], str]
#     ) -> Iterator[Any]:
#     def __init__(self, **kwargs: Any) -> None:
#     def render(self, request: Request) -> Dict[str, Any]:
#     def get_schema(self) -> ResourceObject:
#     def get_data(self) -> Dict[str, Any]:
#     def __init__(self, **kwargs: Any) -> None:
#     def render_included(
#         self, rel_data: "ResourceIdObject", context: Context
#     ) -> List[Dict[str, Any]]:
#     def render(
#         self,
#         obj_data: ObjDataType,
#         rel_data: ResourceIdObject,
#         context: Context,
#         include_this: bool,
#     ) -> RenderResultType:
#     def parse(
#         self, obj_data: ObjDataType, context: Context
#     ) -> Union[str, List[str], None]:
#     def __init__(self, **kwargs: Any) -> None:
#     def render(self, data: ObjDataType, request: Request) -> Any:
#     def render(self, data: ObjDataType, request: Request) -> Any:
# 
# Path: rest_framework_json_schema/utils.py
# def parse_include(include: str) -> Dict[str, Dict]:
#     """
#     Parse an include parameter into its constituent paths.
# 
#     It returns a tree of include paths, for instance:
# 
#     a,a.b,a.c.d,e.f,g
#     Returns:
#     {
#         'a': {
#             'b': {},
#             'c', {
#                 'd': {}
#             }
#         },
#         'e': {
#             'f': {}
#         },
#         'g': {}
#     }
#     """
#     result: Dict[str, Dict] = {}
#     split = include.split(",")
#     for path in split:
#         if path:
#             components = path.split(".")
#             level = result
#             for c in components:
#                 if c not in level:
#                     level[c] = {}
#                 level = level[c]
#     return result


import re
from collections import OrderedDict
from typing import Any, Dict, Optional, Mapping, List, Union, Tuple, Type
from rest_framework.renderers import JSONRenderer
from .exceptions import NoSchema
from .schema import Context, ResourceObject, ObjDataType, RenderResultType
from .utils import parse_include



RX_FIELDS = re.compile(r"^fields\[([a-zA-Z0-9\-_]+)\]$")


class JSONAPIRenderer(JSONRenderer):
    """Renderer which serializes to JSON API."""

    media_type: str = "application/vnd.api+json"
    format: str = "vnd.api+json"
    # You can specify top-level items here.
    meta: Optional[Dict[str, Any]] = None
    jsonapi: Optional[Any] = None

    def render_obj(
        self,
        obj: ObjDataType,
        schema: ResourceObject,
        renderer_context: Mapping[str, Any],
        context: Context,
    ) -> RenderResultType:
        """Render a single resource object as primary data."""
        return schema.render(obj, context)

    def render_list(
        self,
        obj_list: List[ObjDataType],
        schema: ResourceObject,
        renderer_context: Mapping[str, Any],

# Path: rest_framework_json_schema/exceptions.py
# class NoSchema(Exception):
#     """
#     Schema not found on the data to render.
# 
#     This is a programmer error.
#     """
# 
# Path: rest_framework_json_schema/schema.py
# class Context:
# class BaseLinkedObject:
# class ResourceObject(BaseLinkedObject):
# class ResourceIdObject(BaseLinkedObject):
# class RelationshipObject(BaseLinkedObject):
# class LinkObject:
# class UrlLink(LinkObject):
#     def __init__(
#         self,
#         request: Request,
#         include: Optional[Dict] = None,
#         fields: Optional[Dict] = None,
#     ) -> None:
#     def render_links(self, data: ObjDataType, context: Context) -> OrderedDict:
#     def render_meta(self, data: Any, context: Context) -> Optional[Dict]:
#     def __init__(self, **kwargs: Any) -> None:
#         def _normalize_rel(rel: RelOptType) -> RelType:
#     def parse(self, data: ObjDataType, context: Context) -> Dict:
#     def render(self, data: ObjDataType, context: Context) -> RenderResultType:
#     def render_attributes(self, data: Dict, context: Context) -> ObjDataType:
#     def render_relationships(self, data: Dict, context: Context) -> RenderResultType:
#     def render_relationship(
#         self, data: Dict, rel_name: str, rel: "RelationshipObject", context: Context
#     ) -> RenderResultType:
#     def from_data(self, data: Dict, attr: str) -> Any:
#     def filter_by_fields(
#         self, names: Sequence[RelType], fields: Dict, name_fn: Callable[[RelType], str]
#     ) -> Iterator[RelType]:
#     def filter_by_fields(
#         self, names: Sequence[str], fields: Dict, name_fn: Callable[[str], str]
#     ) -> Iterator[str]:
#     def filter_by_fields(
#         self, names: Sequence[Any], fields: Dict, name_fn: Callable[[Any], str]
#     ) -> Iterator[Any]:
#     def __init__(self, **kwargs: Any) -> None:
#     def render(self, request: Request) -> Dict[str, Any]:
#     def get_schema(self) -> ResourceObject:
#     def get_data(self) -> Dict[str, Any]:
#     def __init__(self, **kwargs: Any) -> None:
#     def render_included(
#         self, rel_data: "ResourceIdObject", context: Context
#     ) -> List[Dict[str, Any]]:
#     def render(
#         self,
#         obj_data: ObjDataType,
#         rel_data: ResourceIdObject,
#         context: Context,
#         include_this: bool,
#     ) -> RenderResultType:
#     def parse(
#         self, obj_data: ObjDataType, context: Context
#     ) -> Union[str, List[str], None]:
#     def __init__(self, **kwargs: Any) -> None:
#     def render(self, data: ObjDataType, request: Request) -> Any:
#     def render(self, data: ObjDataType, request: Request) -> Any:
# 
# Path: rest_framework_json_schema/utils.py
# def parse_include(include: str) -> Dict[str, Dict]:
#     """
#     Parse an include parameter into its constituent paths.
# 
#     It returns a tree of include paths, for instance:
# 
#     a,a.b,a.c.d,e.f,g
#     Returns:
#     {
#         'a': {
#             'b': {},
#             'c', {
#                 'd': {}
#             }
#         },
#         'e': {
#             'f': {}
#         },
#         'g': {}
#     }
#     """
#     result: Dict[str, Dict] = {}
#     split = include.split(",")
#     for path in split:
#         if path:
#             components = path.split(".")
#             level = result
#             for c in components:
#                 if c not in level:
#                     level[c] = {}
#                 level = level[c]
#     return result


# Path: rest_framework_json_schema/renderers.py
import re
from collections import OrderedDict
from typing import Any, Dict, Optional, Mapping, List, Union, Tuple, Type
from rest_framework.renderers import JSONRenderer
from .exceptions import NoSchema
from .schema import Context, ResourceObject, ObjDataType, RenderResultType
from .utils import parse_include




RX_FIELDS = re.compile(r"^fields\[([a-zA-Z0-9\-_]+)\]$")


class JSONAPIRenderer(JSONRenderer):
    """Renderer which serializes to JSON API."""

    media_type: str = "application/vnd.api+json"
    format: str = "vnd.api+json"
    # You can specify top-level items here.
    meta: Optional[Dict[str, Any]] = None
    jsonapi: Optional[Any] = None

    def render_obj(
        self,
        obj: ObjDataType,
        schema: ResourceObject,
        renderer_context: Mapping[str, Any],
        context: Context,
    ) -> RenderResultType:
        """Render a single resource object as primary data."""
        return schema.render(obj, context)

    def render_list(
        self,
        obj_list: List[ObjDataType],
        schema: ResourceObject,
        renderer_context: Mapping[str, Any],

        context: Context,