79652025

Date: 2025-06-04 00:38:51
Score: 1
Natty:
Report link

I posted this also on the marshmallow github page, and was able to get a good response there.

https://github.com/marshmallow-code/marshmallow/issues/2829

from marshmallow import Schema, fields, validate

class RequestNumber(fields.String):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, metadata={'description': 'Request Number', 'example':'REQUEST12345'}, validate=validate.Regexp(regex=r"^REQUEST\d{3,9}$", error="Input string didn't match required format - REQUEST12345")), **kwargs)


class Api1():

    class Input1(Schema):
        request_number = RequestNumber()
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Stephan