Skip to content

[Question] Use the rule patterns somewhere else #95

Description

@PvanGarderen

Hi! First of all, thank you for creating this package, it’s really helpful!

My problem

We’re building an application that processes user information, and we use the PostalCode rule to validate the postal codes provided in requests. The validation itself works perfectly, but I’m struggling with one thing: I’m generating a Swagger (OpenAPI) documentation for our APIs, and in it, I’d like to specify a pattern for the postal code like this:

new OA\Property(
    property: 'postal_code', 
    type: 'string', 
    pattern: '^\d{4}[A-Z]{2}$'
),

But now I want to match the pattern used in Intervention\Validation\Rules\Postalcode, which seems a bit difficult. Besides, the pattern function is private, and it doesn't seem to accept functions in the Swagger documentation anyway. I'm currently using a public constant or an enum.

My questions

Has anyone had the same problem in the past? Did you solve it in some way, or did you just hardcode the pattern in your docs and hope it never changes within the package? Is there a way to fetch the pattern(s) that I just didn't see before?

Hope someone can help me out, Thnx

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions