Swagger plugin v4 not recognizing enum as a key in validated object
See original GitHub issueBug 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:
- Created 4 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@arvinsingla, please, create a separate issue with a repository which reproduces your problem.
@karer is this still an issue with the latest version?