Skip to content

Should Route Requirements be Surround with ^...$ in Path Schema Patterns? #1873

@chrisguitarguy

Description

@chrisguitarguy

Given a route like this:

    <route
        id="users.view"
        methods="GET"
        path="/users/{userId}"
        controller="App\Controller\UsersController::view">
            <requirement key="userId">[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}</requirement>
    </route>

an open API schema gets generated where the path parameter looks like this:

parameters:
  -
    name: userId
    in: path
    required: true
    schema:
      type: string
      pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'

But the pattern docs say that without ^ and $ the pattern is a partial match, not a full string.

For a route, where the generated regex would require the specific, full string it might make sense to change the route describer to surround the requirement with ^...$.

Here's the regex that symfony generates on that route, for context:

Screen Shot 2021-09-14 at 10 58 10 AM

Thoughts?

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