swagger icon indicating copy to clipboard operation
swagger copied to clipboard

fix: fix numeric enum values

Open petrzjunior opened this issue 4 years ago • 0 comments

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [x] Bugfix
  • [ ] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

What is the current behavior?

Numeric enums

enum Size {
  SMALL = 1,
  BIG = 2,
}

are currently displayed as

['SMALL', 'BIG']

Issue Number: #1884

What is the new behavior?

Numeric enums

enum Size {
  SMALL = 1,
  BIG = 2,
}

should be displayed as

[1, 2]

This is done by fixing the logic which removes reverse mapping.

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

I consider this more of a bug than a breaking change.

Other information

Besides numeric enum, this handles heterogenous enums as well (not in tests, because Swagger officially supports only enum values of the same type) and keeps the order of keys for them.

References:

  • https://www.typescriptlang.org/docs/handbook/enums.html
  • https://swagger.io/docs/specification/data-models/enums/

petrzjunior avatar Apr 25 '22 10:04 petrzjunior