Repository: Fatal1ty/mashumaro

Issue:
When generating a jsonschema, use "description" in field metadata
**Is your feature request related to a problem? Please describe.**
We've labeled our jsonschema objects with descriptions in field metadata:
```
    project_name: Optional[str] = field(                           
        default=None,                    
        metadata={                                                     
            "description": "Name of the root project",
        },
    )    
```
It would be nice if we could do the same thing using mashumaro's json schema generation.

I guess we could post-process the jsonschema object instead. I see that it's also available in the json_schema["properties"] config, but I think that only works if you want to replace the complete json_schema which isn't feasible.


Discussion:

Patch:
diff --git a/README.md b/README.md
index d1287b9..96a1ff2 100644
--- a/README.md
+++ b/README.md
@@ -2364,7 +2364,7 @@ For simple one-time cases it's recommended to start from using a configurable
 serialized to json or to dict:
 
 ```python
-from dataclasses import dataclass
+from dataclasses import dataclass, field
 from typing import List
 from uuid import UUID
 
@@ -2374,7 +2374,7 @@ from mashumaro.jsonschema import build_json_schema
 @dataclass
 class User:
     id: UUID
-    name: str
+    name: str = field(metadata={"description": "User name"})
 
 
 print(build_json_schema(List[User]).to_json())
@@ -2395,7 +2395,8 @@ print(build_json_schema(List[User]).to_json())
                 "format": "uuid"
             },
             "name": {
-                "type": "string"
+                "type": "string",
+                "description": "User name"
             }
         },
         "additionalProperties": false,
diff --git a/mashumaro/jsonschema/schema.py b/mashumaro/jsonschema/schema.py
index 65c3ec3..7779aa6 100644
--- a/mashumaro/jsonschema/schema.py
+++ b/mashumaro/jsonschema/schema.py
@@ -306,6 +306,9 @@ def on_dataclass(instance: Instance, ctx: Context) -> Optional[JSONSchema]:
                 f_name = f_instance.alias
             if f_default is not MISSING:
                 f_schema.default = f_default
+            description = f_instance.metadata.get("description")
+            if description:
+                f_schema.description = description
 
             if not has_default:
                 required.append(f_name)


Test patch:
diff --git a/tests/test_jsonschema/test_jsonschema_generation.py b/tests/test_jsonschema/test_jsonschema_generation.py
index 626f977..5bf61a6 100644
--- a/tests/test_jsonschema/test_jsonschema_generation.py
+++ b/tests/test_jsonschema/test_jsonschema_generation.py
@@ -126,7 +126,9 @@ def test_jsonschema_for_dataclass():
         c: Optional[int] = field(default=None, metadata={"alias": "cc"})
         d: str = ""
         e: int = field(init=False)
-        f: List[int] = field(default_factory=list)
+        f: List[int] = field(
+            default_factory=list, metadata={"description": "description for f"}
+        )
 
         class Config:
             aliases = {"a": "aa", "d": "dd"}
@@ -145,7 +147,8 @@ def test_jsonschema_for_dataclass():
             ),
             "dd": JSONSchema(type=JSONSchemaInstanceType.STRING, default=""),
             "f": JSONArraySchema(
-                items=JSONSchema(type=JSONSchemaInstanceType.INTEGER)
+                items=JSONSchema(type=JSONSchemaInstanceType.INTEGER),
+                description="description for f",
             ),
         },
         additionalProperties=False,