Search code examples
javascriptnode.jsnestjsopenapi

How to update NestJS Swagger module but use OpenAPI 2.0(Swagger)?


We are making an API in Node.js/Typescript with NestJS framework. We use @nestjs/swagger package to make it conform to OpenAPI(formerly known as Swagger). It is inteneded to be used with Azure/autorest to generate client code.

Autorest supports OpenAPI 2.0 and not 3.0 yet. @nestjs/swagger 3.*.* implemented OpenAPI 2.0. When we update @nestjs/swagger to 4.*.* it turns into OpenAPI 3.0. This doesn't fit our needs because we can't use Autorest anymore. On the other hand not updating the package means we might miss out security updates or not even be able to update the entire NestJS framework.

Is there any way to update @nestjs/swagger and stay with OpenAPI 2.0?


Solution

  • Unfortunately no. Internally, @nestjs/swagger v4 is specifically generating OpenAPI 3.0 specification specifically. There are two options right now while you wait for autorest 3 to be released officially.

    • Stay on @nestjs/swagger v3. As for update the entire NestJS framework, you don't have to worry about this because @nestjs/swagger is a pretty much stand alone package. Security issue regarding dependencies, I can see your concern is valid there.
    • Try autorest 3.beta out to see if it's stable enough for you to use.