Skip to content

Commit

Permalink
Use standard validators instead of custom one in README
Browse files Browse the repository at this point in the history
  • Loading branch information
izxxr committed Mar 1, 2024
1 parent 17347ad commit 8c64266
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ is handled using Oblate:
from oblate import validate, fields
import oblate

# A schema defines the structure of data

class Author(oblate.Schema):
name = fields.String() # Field must be a string
bio = fields.String(none=True) # Field allows None to be passed
rating = fields.Integer(default=0) # Optional field that defaults to 0

# Apply custom validations to a field
@validate.field(rating)
def validate_rating(self, value, ctx):
assert value >= 0 and value <= 10, 'Rating must be in range 0-10 inclusive'
name = fields.String() # Value should be of string data type
bio = fields.String(none=True) # Allows None to be passed
rating = fields.Integer(default=0, validators=[validate.Range(0, 10)]) # Defaults to 0 and allows values between 0 to 10 (inclusive)


class Book(oblate.Schema):
title = fields.String()
Expand Down

0 comments on commit 8c64266

Please sign in to comment.