Search code examples
javascriptnode.jsnestjsswagger-ui

How to remove "--" from swagger UI dropdown list


everyone how can i remove -- from swagger Ui dropdown list. i paste the code below and also upload picture of swagger Ui form. thanks

@Post('upload')
  @ApiConsumes('multipart/form-data')
  @ApiBody({
    required: true,
    schema: {
      type: 'object',
      properties: {
        FileModule:{type:'string', enum:[FileModule.GEOXING, FileModule.common], description: "Choose Module to Upload"},
        FileType:{type:'string', enum:[FileType.IMG, FileType.DOC, FileType.XML], description: "Choose type of file to Upload" }, 
        FileCategory:{type:'string', enum:[FileCategory.SITE, FileCategory.EXHIBITOR, FileCategory.SERVICE], description: "Choose category to upload"}, 
        file: {
          type: 'string',
          format: 'binary',
        },
      },
    },
  })
  @UseInterceptors(FileExtender)
  @UseInterceptors(FileInterceptor('file'))
  async uploadFile(@UploadedFile('file') file: any) {
    console.log(file)
    return await this.fileUploadService.uploadFile(file);
  }

enter image description here


Solution

  • That's actually quite simple. The ApiBody of @nestjs/swagger uses the JSONSchema to define its properties. As such, you should follow the schema format requirements and adjust the property accordingly.

    Dashes here basically mean that the property is optional. If you want to remove the dashes, it means you want to make the property required.

    So you would simply adjust your schema definition to make the given fields required.

      @ApiBody({
        required: true,
        schema: {
          type: 'object',
          required: ["FileModule", "FileType", "FileCategory"], // here i made fields non optional
          properties: {
            FileModule:{type:'string', enum:[FileModule.GEOXING, FileModule.common], description: "Choose Module to Upload"},
            FileType:{type:'string', enum:[FileType.IMG, FileType.DOC, FileType.XML], description: "Choose type of file to Upload" }, 
            FileCategory:{type:'string', enum:[FileCategory.SITE, FileCategory.EXHIBITOR, FileCategory.SERVICE], description: "Choose category to upload"}, 
            file: {
              type: 'string',
              format: 'binary',
            },
          },
        },
      })