-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from Fatal1ty/json-schema-plugins
Add a plugin system to json schema
- Loading branch information
Showing
6 changed files
with
310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from dataclasses import is_dataclass | ||
from inspect import cleandoc | ||
from typing import Optional | ||
|
||
from mashumaro.jsonschema.models import Context, JSONSchema | ||
from mashumaro.jsonschema.schema import Instance | ||
|
||
|
||
class BasePlugin: | ||
def get_schema( | ||
self, | ||
instance: Instance, | ||
ctx: Context, | ||
schema: Optional[JSONSchema] = None, | ||
) -> Optional[JSONSchema]: | ||
pass | ||
|
||
|
||
class DocstringDescriptionPlugin(BasePlugin): | ||
def get_schema( | ||
self, | ||
instance: Instance, | ||
ctx: Context, | ||
schema: Optional[JSONSchema] = None, | ||
) -> Optional[JSONSchema]: | ||
if schema and is_dataclass(instance.type) and instance.type.__doc__: | ||
schema.description = cleandoc(instance.type.__doc__) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.