Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: * param renamed to wildcard #775

Merged
merged 1 commit into from
Dec 28, 2023
Merged

fix: * param renamed to wildcard #775

merged 1 commit into from
Dec 28, 2023

Conversation

casantosmu
Copy link
Contributor

This plugin transforms the route "/example/*" into "/example/{wildcard}". Therefore, the schema for a route with a wildcard should be defined as follows:

fastify.get(
  "/example/*",
  {
    schema: {
      params: {
        wildcard: { type: "string" },
      },
    },
  },
  (request, reply) => {
    const path = request.params["*"];
    reply.send(path);
  }
);

This pull request allows defining the schema for a route with a wildcard as expected:

fastify.get(
  "/example/*",
  {
    schema: {
      params: {
        "*": { type: "string" },
      },
    },
  },
  (request, reply) => {
    const path = request.params["*"];
    reply.send(path);
  }
);

This resolves the issue discussed in this GitHub issue.

Checklist

@casantosmu
Copy link
Contributor Author

As mentioned in the issue, there was another potential solution: when transforming the Fastify schema to OpenAPI, updating the parameter "*" to "wildcard" could have been an option. Similar to the transformation applied to the URL. However, I believe it is simpler for everyone to maintain consistency by preserving the parameter names in the path rather than modifying them.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Member

looking at the change, I don't think it's semver-major.

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the change, I don't think it's semver-major.

Yes, changing the displayed pathname doesn't cause any problem.
It just not good for identify what it intended to do.

Note: The same thing would happen on unnamed RegExp param.

@Eomm Eomm merged commit 3c2522c into fastify:master Dec 28, 2023
19 checks passed
@Eomm Eomm linked an issue Dec 28, 2023 that may be closed by this pull request
2 tasks
@casantosmu casantosmu deleted the fix/wildcard-path branch December 28, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wildcard paths fails Swagger validation
4 participants