Is there a way to pre-define built-in validators that can be used multiple times?
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với tài liệu marshmallow.validate được liên kết và các entry point hiện có của validator. Xác định xem các validator tích hợp có thể tái sử dụng đã được hỗ trợ hay chưa, đồng thời ghi lại một ví dụ phù hợp về cách áp dụng một validator trên nhiều schema; công việc được xem là hoàn tất khi pattern được khuyến nghị đã rõ ràng trong tài liệu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I'm working on an API based flask app with flask-smorest and marshmallow validations. The issue I'm running into, is that many api endpoints require the same type of data, and I don't want to continually copy/paste the same validations over and over. Something like below would happen....
from marshmallow import Schema, fields, validate
class api1():
class input1(Schema):
request_number = fields.Str(metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=validate.Regexp(regex=r"^REQUEST\d{3,9}$", error="Input string didn't match required format - REQUEST12345"))
class api2():
class input1(Schema):
request_number = fields.Str(metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=validate.Regexp(regex=r"^REQUEST\d{3,9}$", error="Input string didn't match required format - REQUEST12345"))
What I want to do is create some sort of function or class BEFORE I define every api field/schema that I could recall.
Below is the idea, though I don't believe it works.
from marshmallow import Schema, fields, validate
class repetative_validators():
request_number = validate.Regexp(regex=r"^REQUEST\d{3,9}$", error="Input string didn't match required format - REQUEST12345"))
class api1():
class input1(Schema):
request_number = fields.Str(metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=repetative_validators().request_number)
class api2():
class input1(Schema):
request_number = fields.Str(metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=repetative_validators().request_number)
I was able to successfully test creating my own function for validation as described here, but was hoping to use the built in validators.
from marshmallow import Schema, fields, validate, ValidationError
import re
def validate_request_number(value):
if not re.match(r"^REQUEST\d{3,9}$"):
raise ValidationError("Input string didn't match required format - REQUEST12345")
class api1():
class input1(Schema):
request_number = fields.Str(metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=validate_request_number)
class api2():
class input1(Schema):
request_number = fields.Str(metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=validate_request_number)
If anyone can link to appropriate documentation or an example that would be helpful. I haven't found anything like this in the marshmallow docs yet
- Ngôn ngữ chính
- Python
- Star
- 7.2k
- Fork
- 790
- Merge trung bình
- 10 giờ 40 phút
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của marshmallow-code/marshmallow
-
ContainsOnly raises TypeError for unhashable input with set-based choicesCó thể đã có người làm @prathamchoksi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
marshmallow-code/marshmallow#3115 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`validate.Email` accepts a leading/trailing hyphen in the last domain labelCó thể đã có người làm @syahra712 đã nhận 35 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
marshmallow-code/marshmallow#3072 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 68/100
marshmallow-code/marshmallow#3068 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Negative POSIX timestamps cannot be deserialized after timestamp serializationCó thể đã có người làm @lafrech đã nhận 90 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
marshmallow-code/marshmallow#3019 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SchemaOpts misses partialCó thể đã có người làm @number492 đã nhận 489 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
marshmallow-code/marshmallow#2834 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của marshmallow-code/marshmallow
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Netcracker/qubership-ai-packages#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
PROCESSED_DATA_FOLDER: strip whitespace and treat empty as unsetCó thể đã có người làm @TorecLuik đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
NL-BioImaging/BIOMERO.importer#63 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
MLX training-complete chat/merge suggestions omit --backend mlxCó thể đã có người làm @vaputa đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
MakazhanAlpamys/Soup#2913 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:security effort:S priority:P3 status:needs-triage type:chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
randomparity/kdive#3657 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aws/mcp-proxy-for-aws#476 ·
Maintainer thường phản hồi trong vòng 1 ngày