fastify / fastify-swagger

Swagger documentation generator for Fastify
MIT License
910 stars 200 forks source link

Expose swagger/openapi version for transform hook #737

Closed samchungy closed 1 year ago

samchungy commented 1 year ago

Prerequisites

🚀 Feature Proposal

Add the openapi/swagger version to transform hook parameters. Unless there is a way to access the options passed into a plugin..?

Motivation

I need to know what version of schema I am creating otherwise I may transform the schema into something that is incompatible.

Example

transform: ({ schema, url, version }) => {
  if (version === '3.0.3') {
    // generate 3.0.3 schema
  }
}
mcollina commented 1 year ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Uzlopak commented 1 year ago

we should maybe pass the whole options object to transform. version is too unspecific. In #732 it is requested to access the constraint, which also could contain version. Then people could get confused which version we actually mean. So better to pass config/options and constraints

Liam-Tait commented 1 year ago

@mcollina I think this is a duplicate of https://github.com/fastify/fastify-swagger/issues/732 which I have made a pr for

samchungy commented 1 year ago

@mcollina I think this is a duplicate of #732 which I have made a pr for

Slightly different. I'm looking for the swagger/openapi version as opposed to the API version which is different.

@Uzlopak makes a good point