Created
April 13, 2021 03:07
-
-
Save thanakijwanavit/1512c46e6ebdea2851963e3ebfcef4b8 to your computer and use it in GitHub Desktop.
example of using marshmallow with json schema
This file contains hidden or 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
from marshmallow import Schema, fields | |
from marshmallow_jsonschema import JSONSchema | |
class UserSchema(Schema): | |
name = fields.String() | |
address = fields.String() | |
class Athlete(object): | |
user_schema = UserSchema() | |
def __init__(self): | |
self.name = 'sam' | |
class AthleteSchema(Schema): | |
user_schema = fields.Nested(JSONSchema) | |
name = fields.String() | |
athlete = Athlete() | |
athlete_schema = AthleteSchema() | |
athlete_schema.dump(athlete) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment