Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): isArray always false for enum arrays in plugin metadata #1696

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

ArielPrevu3D
Copy link
Contributor

@ArielPrevu3D ArielPrevu3D commented Nov 24, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • 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?

Enum arrays in plugin-generated metadata never have 'isArray' to true.

Issue Number: 1676

What is the new behavior?

Enum arrays in plugin-generated metadata always have 'isArray' to true.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@ArielPrevu3D
Copy link
Contributor Author

ArielPrevu3D commented Nov 24, 2021

@kamilmysliwiec is an enum array with 1 value supposed to have isArray to true? Seems like the test disagrees. In my mind, this means the API is expecting an array so isArray should be true.

@nawaz-pasha
Copy link

Oh, I ran into this....
@kamilmysliwiec Can we please plan to get this merged?
@ArielPrevu3D is there any work around to get this going while we wait for the release?

@ArielPrevu3D
Copy link
Contributor Author

Oh, I ran into this.... @kamilmysliwiec Can we please plan to get this merged? @ArielPrevu3D is there any work around to get this going while we wait for the release?

This is the workaround we're using. This fixes the schema after generating the schema document.

  // Workaround for enum arrays
  //   https://github.com/nestjs/swagger/issues/1676
  if (document?.components?.schemas) {
    for (const schemaKey in document.components.schemas) {
      const schema = document.components.schemas[schemaKey];
      if (
        'type' in schema &&
        schema.type === 'object' &&
        schema.properties
      ) {
        for (const schemaPropKey in schema.properties) {
          const property = schema.properties[schemaPropKey];
          if ('items' in property && 'enum' in property) {
            delete property.enum;
          }
        }
      }
    }
  }

@nawaz-pasha
Copy link

Thank you @ArielPrevu3D !

@kamilmysliwiec kamilmysliwiec merged commit 3f7a813 into nestjs:master Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants