question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger plugin v4 not recognizing enum as a key in validated object

See original GitHub issue

Bug Report

Current behavior

I’ve updated my code to use swagger v4 with plugin, so it exposes DTO validations automatically. Everything work correctly, unless i use enum as a key of validated object. In output code, enum is not being imported and nest assumes it is global.

Input Code

import { IsBoolean, IsOptional } from 'class-validator';
import { ReservationReminderType } from '../../../shared/reservation/enums/reservation.reminder.type.enum';

export class UpdateShopNotifiactionsDto {
  @IsBoolean()
  @IsOptional()
  [ReservationReminderType.OneDayBefore]?: boolean;
}

Output Code (compiled)

const openapi = require("@nestjs/swagger");
const class_validator_1 = require("class-validator");
const reservation_reminder_type_enum_1 = require("../../../shared/reservation/enums/reservation.reminder.type.enum");

class UpdateShopNotifiactionsDto {
    static _OPENAPI_METADATA_FACTORY() {
        return { [ReservationReminderType.OneDayBefore]: { required: false, type: () => Boolean }, };
    }
}

Expected behavior

Output code should use reservation_reminder_type_enum_1 in its static _OPENAPI_METADATA_FACTORY() method.

Error

(node:22659) UnhandledPromiseRejectionWarning: ReferenceError: ReservationReminderType is not defined
    at Function._OPENAPI_METADATA_FACTORY ([...]/shop.notifications.update.dto.js:18:19)

Environment


Nest version: 6.10.13

 
For Tooling issues:
- Node version: 10.16.0  
- Platform:  Mac, Linux

Others:
Build works correctly, error happens at runtime (dev & prod start)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Jan 20, 2020

@arvinsingla, please, create a separate issue with a repository which reproduces your problem.

0reactions
nartccommented, Nov 14, 2020

@karer is this still an issue with the latest version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document Enum in Swagger - Baeldung
Learn how to document enum in Swagger using the Maven plugin and verify the generated JSON document in the Swagger editor.
Read more >
Enums - Swagger
You can use the enum keyword to specify possible values of a request parameter or a model property. ... Using nullable: true alone...
Read more >
Swagger UI Web Api documentation Present enums as strings?
I don't think Swagger supports a enum type with both the string and integer value.
Read more >
Using Templates - OpenAPI Generator
Gradle Plugin: templateDir. Built-in templates are written in Mustache and processed by jmustache. Beginning with version 4.0.0, we support ...
Read more >
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found