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

Add ability to filter by version constraint #732

Closed
2 tasks done
Liam-Tait opened this issue Jun 19, 2023 · 1 comment · Fixed by #739
Closed
2 tasks done

Add ability to filter by version constraint #732

Liam-Tait opened this issue Jun 19, 2023 · 1 comment · Fixed by #739
Labels
feature request New feature to be added

Comments

@Liam-Tait
Copy link
Contributor

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

When generating a specification I want to be able to filter by the API version constraint so I can have multiple schema files with specific versions associated. For example, a schema for version 1 routes and version 2 routes.

There are two ways of adding this that come to mind:

Add a specific filter for the version constraint to the Options object

This approach makes it easy to integrate with find-my-way versioned routes using the same server logic. The options object would have an additional property such as apiVersion with a semver string that filters for only routes that match the server.

Allow a route's constraints to be accessed within the transform function

This would give users the option to use any constraint to to modify the schema, for version constraints this would be adding a step within the transform function to add the. Maximum flexibility but means it's user land code to ensure the versioning logic matches with find-my-way

Motivation

When creating an API I would like to generate several API specifications, one for each major version.

Example

await fastify.register(require('@fastify/swagger'), {
  openapi: { ... },
  apiVersion: "1.0.0"
})

or

await fastify.register(require('@fastify/swagger'), {
  swagger: { ... },
  transform: ({ schema, url, constraints }) => {
    if (!semver.satisfies(constraints.version, "1.0.0")) {
      schema.hide = true
    }
    return { schema, url }
  }
})
@mcollina
Copy link
Member

This would be a nice feature to add. Would you like to send a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature to be added
Projects
None yet
2 participants