Andreas Aravena
Andreas Aravena

Reputation: 41

LB4: How to hide method from Swagger

I am using LoopBack4 for my services but one of them (Documentacion - /files/{filename}), for security reasons, would be better not to be shown in Swagger. It looks like this:

enter image description here

Code wise:

export class Documentacion {
  constructor(@inject(STORAGE_DIRECTORY) private storageDirectory: string) { }

  @get('/files/{filename}')
  @oas.response.file()
  async descargarExcel(
    @param.path.string('filename') fileName: string,
    @inject(RestBindings.Http.RESPONSE) response: Response,
  ) {
     ...
    }
  }

From another post I found that I could change the @get decorator to be like this:

export class Documentacion {
  constructor(@inject(STORAGE_DIRECTORY) private storageDirectory: string) { }

  @get('/files/{filename}', {'x-visibility': 'undocumented'})

But when I try it I get an error saying that "{'x-visibility': 'undocumented'} is not assignable to parameter of type OperationObject".

I looked up what OperationObject was in LB4. I found the next code but I got the same kind of error:

const spec = {
  // You can specify `operationId` as an universal property that's
  // understood by other frameworks.
  operationId: 'MyController.checkExist'
  parameters: [{name: 'name', schema: {type: 'string'}, in: 'query'}],
  responses: {
    '200': {
      description: 'greeting text',
      content: {
        'application/json': {
          schema: {type: 'boolean'},
        },
      },
    },
  },
};
class MyController {
  @operation('HEAD', '/checkExist', spec)
  checkExist(name: string) {}
}

There are a lot of posts like this around here, but most of them are using other things (Restler; Spring; etc) or trying to hide specific parameters from a method (which I tried anyway but none worked).

If it helps in any way, it's the only Get method I have.

Upvotes: 0

Views: 82

Answers (0)

Related Questions