prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add support for Pydantic's dataclasses
  **Describe the question**
  I am using a  pydantic.dataclasses.dataclass as a response_model of my fast api route.
  
  
  ```
  from fastapi import FastAPI
  from pydantic.dataclasses import dataclass
  
  
  @dataclass
  class Foo:
      bar: int
  
  app = FastAPI()
  
  @app.get('/foo', response_model=Foo)
  def get_bar() -> Foo:
      return Foo(bar=1)
  ```
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Create a file **app.py** with the above code.
  2. Start the app: `uvicorn app:app`
  3. Open the browser and go to **localhost:8000/foo**
  4. See error: 
  ```
  pydantic.error_wrappers.ValidationError: 1 validation error
  response
    __init__() got an unexpected keyword argument '__initialised__' (type=type_error)
  ```
  
  **Expected behavior**
  No validation error and serialized json does not contain any keys `__initialised__`.
  
  
  **Environment:**
   - OS: Linux
   - FastAPI Version 0.25.0
  - Python version 3.7.3
  
  
  </issue>
  <code>
  [start of fastapi/utils.py]
  1 import re
  2 from typing import Any, Dict, List, Sequence, Set, Type, cast
  3 
  4 from fastapi import routing
  5 from fastapi.openapi.constants import REF_PREFIX
  6 from pydantic import BaseConfig, BaseModel, Schema, create_model
  7 from pydantic.fields import Field
  8 from pydantic.schema import get_flat_models_from_fields, model_process_schema
  9 from pydantic.utils import lenient_issubclass
  10 from starlette.routing import BaseRoute
  11 
  12 
  13 def get_flat_models_from_routes(routes: Sequence[BaseRoute]) -> Set[Type[BaseModel]]:
  14     body_fields_from_routes: List[Field] = []
  15     responses_from_routes: List[Field] = []
  16     for route in routes:
  17         if getattr(route, "include_in_schema", None) and isinstance(
  18             route, routing.APIRoute
  19         ):
  20             if route.body_field:
  21                 assert isinstance(
  22                     route.body_field, Field
  23                 ), "A request body must be a Pydantic Field"
  24                 body_fields_from_routes.append(route.body_field)
  25             if route.response_field:
  26                 responses_from_routes.append(route.response_field)
  27             if route.response_fields:
  28                 responses_from_routes.extend(route.response_fields.values())
  29     flat_models = get_flat_models_from_fields(
  30         body_fields_from_routes + responses_from_routes, known_models=set()
  31     )
  32     return flat_models
  33 
  34 
  35 def get_model_definitions(
  36     *, flat_models: Set[Type[BaseModel]], model_name_map: Dict[Type[BaseModel], str]
  37 ) -> Dict[str, Any]:
  38     definitions: Dict[str, Dict] = {}
  39     for model in flat_models:
  40         m_schema, m_definitions, m_nested_models = model_process_schema(
  41             model, model_name_map=model_name_map, ref_prefix=REF_PREFIX
  42         )
  43         definitions.update(m_definitions)
  44         model_name = model_name_map[model]
  45         definitions[model_name] = m_schema
  46     return definitions
  47 
  48 
  49 def get_path_param_names(path: str) -> Set[str]:
  50     return {item.strip("{}") for item in re.findall("{[^}]*}", path)}
  51 
  52 
  53 def create_cloned_field(field: Field) -> Field:
  54     original_type = field.type_
  55     use_type = original_type
  56     if lenient_issubclass(original_type, BaseModel):
  57         original_type = cast(Type[BaseModel], original_type)
  58         use_type = create_model(  # type: ignore
  59             original_type.__name__,
  60             __config__=original_type.__config__,
  61             __validators__=original_type.__validators__,
  62         )
  63         for f in original_type.__fields__.values():
  64             use_type.__fields__[f.name] = f
  65     new_field = Field(
  66         name=field.name,
  67         type_=use_type,
  68         class_validators={},
  69         default=None,
  70         required=False,
  71         model_config=BaseConfig,
  72         schema=Schema(None),
  73     )
  74     new_field.has_alias = field.has_alias
  75     new_field.alias = field.alias
  76     new_field.class_validators = field.class_validators
  77     new_field.default = field.default
  78     new_field.required = field.required
  79     new_field.model_config = field.model_config
  80     new_field.schema = field.schema
  81     new_field.allow_none = field.allow_none
  82     new_field.validate_always = field.validate_always
  83     if field.sub_fields:
  84         new_field.sub_fields = [
  85             create_cloned_field(sub_field) for sub_field in field.sub_fields
  86         ]
  87     if field.key_field:
  88         new_field.key_field = create_cloned_field(field.key_field)
  89     new_field.validators = field.validators
  90     new_field.whole_pre_validators = field.whole_pre_validators
  91     new_field.whole_post_validators = field.whole_post_validators
  92     new_field.parse_json = field.parse_json
  93     new_field.shape = field.shape
  94     new_field._populate_validators()
  95     return new_field
  96 
  97 
  98 def generate_operation_id_for_path(*, name: str, path: str, method: str) -> str:
  99     operation_id = name + path
  100     operation_id = operation_id.replace("{", "_").replace("}", "_").replace("/", "_")
  101     operation_id = operation_id + "_" + method.lower()
  102     return operation_id
  103
  [end of fastapi/utils.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/fastapi/utils.py b/fastapi/utils.py
  --- a/fastapi/utils.py
  +++ b/fastapi/utils.py
  @@ -1,4 +1,5 @@
   import re
  +from dataclasses import is_dataclass
   from typing import Any, Dict, List, Sequence, Set, Type, cast
   
   from fastapi import routing
  @@ -52,6 +53,8 @@
   
   def create_cloned_field(field: Field) -> Field:
       original_type = field.type_
  +    if is_dataclass(original_type) and hasattr(original_type, "__pydantic_model__"):
  +        original_type = original_type.__pydantic_model__  # type: ignore
       use_type = original_type
       if lenient_issubclass(original_type, BaseModel):
           original_type = cast(Type[BaseModel], original_type)
  
verification_info: {"golden_diff": "diff --git a/fastapi/utils.py b/fastapi/utils.py\n--- a/fastapi/utils.py\n+++ b/fastapi/utils.py\n@@ -1,4 +1,5 @@\n import re\n+from dataclasses import is_dataclass\n from typing import Any, Dict, List, Sequence, Set, Type, cast\n \n from fastapi import routing\n@@ -52,6 +53,8 @@\n \n def create_cloned_field(field: Field) -> Field:\n     original_type = field.type_\n+    if is_dataclass(original_type) and hasattr(original_type, \"__pydantic_model__\"):\n+        original_type = original_type.__pydantic_model__  # type: ignore\n     use_type = original_type\n     if lenient_issubclass(original_type, BaseModel):\n         original_type = cast(Type[BaseModel], original_type)\n", "issue": "Add support for Pydantic's dataclasses\n**Describe the question**\r\nI am using a  pydantic.dataclasses.dataclass as a response_model of my fast api route.\r\n\r\n\r\n```\r\nfrom fastapi import FastAPI\r\nfrom pydantic.dataclasses import dataclass\r\n\r\n\r\n@dataclass\r\nclass Foo:\r\n    bar: int\r\n\r\napp = FastAPI()\r\n\r\n@app.get('/foo', response_model=Foo)\r\ndef get_bar() -> Foo:\r\n    return Foo(bar=1)\r\n```\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Create a file **app.py** with the above code.\r\n2. Start the app: `uvicorn app:app`\r\n3. Open the browser and go to **localhost:8000/foo**\r\n4. See error: \r\n```\r\npydantic.error_wrappers.ValidationError: 1 validation error\r\nresponse\r\n  __init__() got an unexpected keyword argument '__initialised__' (type=type_error)\r\n```\r\n\r\n**Expected behavior**\r\nNo validation error and serialized json does not contain any keys `__initialised__`.\r\n\r\n\r\n**Environment:**\r\n - OS: Linux\r\n - FastAPI Version 0.25.0\r\n- Python version 3.7.3\r\n\n", "before_files": [{"content": "import re\nfrom typing import Any, Dict, List, Sequence, Set, Type, cast\n\nfrom fastapi import routing\nfrom fastapi.openapi.constants import REF_PREFIX\nfrom pydantic import BaseConfig, BaseModel, Schema, create_model\nfrom pydantic.fields import Field\nfrom pydantic.schema import get_flat_models_from_fields, model_process_schema\nfrom pydantic.utils import lenient_issubclass\nfrom starlette.routing import BaseRoute\n\n\ndef get_flat_models_from_routes(routes: Sequence[BaseRoute]) -> Set[Type[BaseModel]]:\n    body_fields_from_routes: List[Field] = []\n    responses_from_routes: List[Field] = []\n    for route in routes:\n        if getattr(route, \"include_in_schema\", None) and isinstance(\n            route, routing.APIRoute\n        ):\n            if route.body_field:\n                assert isinstance(\n                    route.body_field, Field\n                ), \"A request body must be a Pydantic Field\"\n                body_fields_from_routes.append(route.body_field)\n            if route.response_field:\n                responses_from_routes.append(route.response_field)\n            if route.response_fields:\n                responses_from_routes.extend(route.response_fields.values())\n    flat_models = get_flat_models_from_fields(\n        body_fields_from_routes + responses_from_routes, known_models=set()\n    )\n    return flat_models\n\n\ndef get_model_definitions(\n    *, flat_models: Set[Type[BaseModel]], model_name_map: Dict[Type[BaseModel], str]\n) -> Dict[str, Any]:\n    definitions: Dict[str, Dict] = {}\n    for model in flat_models:\n        m_schema, m_definitions, m_nested_models = model_process_schema(\n            model, model_name_map=model_name_map, ref_prefix=REF_PREFIX\n        )\n        definitions.update(m_definitions)\n        model_name = model_name_map[model]\n        definitions[model_name] = m_schema\n    return definitions\n\n\ndef get_path_param_names(path: str) -> Set[str]:\n    return {item.strip(\"{}\") for item in re.findall(\"{[^}]*}\", path)}\n\n\ndef create_cloned_field(field: Field) -> Field:\n    original_type = field.type_\n    use_type = original_type\n    if lenient_issubclass(original_type, BaseModel):\n        original_type = cast(Type[BaseModel], original_type)\n        use_type = create_model(  # type: ignore\n            original_type.__name__,\n            __config__=original_type.__config__,\n            __validators__=original_type.__validators__,\n        )\n        for f in original_type.__fields__.values():\n            use_type.__fields__[f.name] = f\n    new_field = Field(\n        name=field.name,\n        type_=use_type,\n        class_validators={},\n        default=None,\n        required=False,\n        model_config=BaseConfig,\n        schema=Schema(None),\n    )\n    new_field.has_alias = field.has_alias\n    new_field.alias = field.alias\n    new_field.class_validators = field.class_validators\n    new_field.default = field.default\n    new_field.required = field.required\n    new_field.model_config = field.model_config\n    new_field.schema = field.schema\n    new_field.allow_none = field.allow_none\n    new_field.validate_always = field.validate_always\n    if field.sub_fields:\n        new_field.sub_fields = [\n            create_cloned_field(sub_field) for sub_field in field.sub_fields\n        ]\n    if field.key_field:\n        new_field.key_field = create_cloned_field(field.key_field)\n    new_field.validators = field.validators\n    new_field.whole_pre_validators = field.whole_pre_validators\n    new_field.whole_post_validators = field.whole_post_validators\n    new_field.parse_json = field.parse_json\n    new_field.shape = field.shape\n    new_field._populate_validators()\n    return new_field\n\n\ndef generate_operation_id_for_path(*, name: str, path: str, method: str) -> str:\n    operation_id = name + path\n    operation_id = operation_id.replace(\"{\", \"_\").replace(\"}\", \"_\").replace(\"/\", \"_\")\n    operation_id = operation_id + \"_\" + method.lower()\n    return operation_id\n", "path": "fastapi/utils.py"}]}