Skip to content

@fastify/swagger: Modify route.method in swaggerTransform function #1105

@xxzefgh

Description

@xxzefgh

💬 Modify route.method in swaggerTransform function

When using fastify.all for registering a route, openapi schema contains all possible methods for that route, that I want to limit to just POST. Directly modifying route.method in swaggerTransform function does exactly that, but I am wondering if that will break some things internally?

fastify.all(
	"/example",
	{
		config: {
			swaggerTransform: ({ schema, url, route }) => {
				route.method = ["POST"];
				return { schema, url };
			},
		},
	},
	(req, reply) => {
		///
	},
);

Your Environment

  • node version: 22.18
  • fastify version: >=5.4.0
  • os: Linux
  • @fastify/swagger version: >=9.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions