#OpenApi + TransformInterceptor for response

1 messages · Page 1 of 1 (latest)

hot heron
#

Hi, I have a TransformInterceptor that wraps all of my responses like this:

{
   result: <the-data-returned-by-controller>
}

The OpenApi spec generated by the swagger integration does not seem to honor that transformer.

I'm curious if there is a way to configure swagger or nest to specify that wrapper type for all of my responses?

It don't mind specifying this statically, I would just like to be able to do it in one place and not on every controller/route.

west radish
#

How would a decorator, a meta programming concept, know how your transformer, a runtime construct, changes your response?

hot heron
#

It don't mind specifying this statically, I would just like to be able to do it in one place and not on every controller/route.

west radish
#

Why not create a wrapper around the @ApiResponse() decorator where you pass the type you expect and it passes the wrapped type that your transformer will create to @ApiResponse()?

hot heron
#

I think I left out an important detail. I'm using the nest cli plugin so that we don't have to specify @ApiResponse.

west radish
#

Then that won't be possible to automatically detect

#

You could manually modify the JSON that gets created, but that would be quite a modification

hot heron
#

Gotcha, I guess i was hoping there was a swagger option for this that was exposed through nest.js somehow.