routing-controllers-openapi icon indicating copy to clipboard operation
routing-controllers-openapi copied to clipboard

controllers field is not being used

Open tmouchart opened this issue 3 years ago • 3 comments
trafficstars

When generating swagger specifications, the controllers fields in RoutingControllersOptions is actually ignored

Metadata information is taken from a global variable.

My problem is that I would like to generate 2 separate swagger for 2 different sets of controllers, but they get merged as I am not able to separate them using the controllers field

Code to reproduce:

import { v1Controllers } from './controllers/http/v1';

v1Controllers;

export function generateV1API(): OpenAPIObject {
  const v1ApiOptions: RoutingControllersOptions = {
    controllers: [],
    routePrefix: '/v1',
    defaultErrorHandler: false,
    validation: {
      whitelist: true,
    },
    defaults: {
      // with this option, null will return 204 by default
      nullResultCode: 204,
      // with this option, void or Promise<void> will return 204 by default
      undefinedResultCode: 204,
    },
  };

Even with an empty controllers array [], the controllers are added to the result OpenAPIObject

tmouchart avatar Dec 16 '21 14:12 tmouchart

+1

talbSE avatar Sep 04 '22 09:09 talbSE

Currently there is no way to document a 204 ONLY response.

e.g.

@ResponseSchema(undefined, { statusCode: 204 }) // error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string | Function'.

Workaround:

@OpenAPI({ responses: { "204": { description: "No content" } } })

But both 200 and 204 are displayed ⬇️

image

kenberkeley avatar Dec 15 '22 05:12 kenberkeley

Looks like I'm having the same issue as well, but there's no solution yet. I have two sets of APIs, one open to internal members and one open to external members, and I want to generate two different sets of API documents for different target users. What is your final solution?

sxlvalue avatar Jan 29 '24 08:01 sxlvalue