fastify / fastify-swagger

Swagger documentation generator for Fastify
MIT License
889 stars 199 forks source link

fix: * param renamed to wildcard #775

Closed casantosmu closed 6 months ago

casantosmu commented 6 months ago

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 commented 6 months ago

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.

mcollina commented 6 months ago

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