Repository: nestjs/swagger (ts)

Issue:
Prop isArray is incorrectly added when using @ApiQuery decorator with enum values
<!--
PLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.

ISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.
-->

## I'm submitting a...
<!-- 
Please search GitHub for a similar issue or PR before submitting.
Check one of the following options with "x" -->
<pre><code>
[ ] Regression <!--(a behavior that used to work and stopped working in a new release)-->
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
</code></pre>

## Current behavior
Applying an `APIQuery` decorator to a controller method which uses an enum:

<pre><code>@ApiQuery({
    name: 'pagingStrategy',
    type: 'enum',
    required: false,
    enum: ['withCount', 'noCount'],
  })</code></pre>

produces json:

<pre><code>{
    "name": "pagingStrategy",
    "required": false,
    "in": "query",
    "isArray": false,
    "schema": {
        "enum": [
            "withCount",
           "noCount"
        ],
        "type": "string"
    }
}</code></pre>

When converted to yaml and pasted into the Swagger Editor produces validation errors as the `isArray` property should not exist.

Manually removing the isArray property in the [Swagger Editor ](https://editor.swagger.io/) solves the issue.

## Expected behavior

The `isArray` property should not be present when a query parameter is an enum value.

## Minimal reproduction of the problem with instructions

[Minimal Reproduction Repo](https://github.com/tourlbr/nesting)

**Instructions**

1. Using the default nest setup add an ApiQuery decorator to the endpoint method and retrieve the json version of the OpenApi spec (-json in URL).
2. Paste into the [Swagger Editor](https://editor.swagger.io/)

## What is the motivation / use case for changing the behavior?

To create valid OpenAPI documents.

## Environment

<pre><code>
Nest version: 7.5.1
 
For Tooling issues:
- Node version: v14.12.0
- Platform:  Mac

</code></pre>


Pull request description:
fix: add isArray prop for enums on api query decorator when applicable
Only add isArray prop to params list when it is an array.
This change is needed to create valid OpenAPI documents.

Closes #1221

## 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)
- [x] Docs have been added / updated (for bug fixes / features)


## PR Type
What kind of change does this PR introduce?

<!-- Please check the one that applies to this PR using "x". -->
```
[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?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->

Issue Number: #1221 


## What is the new behavior?

Add isArray prop for enums on the Api Query decorator when applicable.

This is needed to create valid Open API documentation

## Does this PR introduce a breaking change?
```
[ ] Yes
[x] No
```

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. -->


## Other information

Patch:
diff --git a/lib/decorators/api-query.decorator.ts b/lib/decorators/api-query.decorator.ts
index 087eeeba..7a41b81b 100644
--- a/lib/decorators/api-query.decorator.ts
+++ b/lib/decorators/api-query.decorator.ts
@@ -46,8 +46,7 @@ export function ApiQuery(options: ApiQueryOptions): MethodDecorator {
     name: isNil(options.name) ? defaultQueryOptions.name : options.name,
     in: 'query',
     ...omit(options, 'enum'),
-    type,
-    isArray
+    type
   };
 
   if (isEnumArray(options)) {
@@ -56,5 +55,9 @@ export function ApiQuery(options: ApiQueryOptions): MethodDecorator {
     addEnumSchema(param, options);
   }
 
+  if (isArray) {
+    param.isArray = isArray;
+  }
+
   return createParamDecorator(param, defaultQueryOptions);
 }


Test patch:
diff --git a/test/explorer/swagger-explorer.spec.ts b/test/explorer/swagger-explorer.spec.ts
index 2fd9b6b6..f9cf5fa8 100644
--- a/test/explorer/swagger-explorer.spec.ts
+++ b/test/explorer/swagger-explorer.spec.ts
@@ -796,6 +796,20 @@ describe('SwaggerExplorer', () => {
       }
     }
 
+    @Controller('')
+    class Foo2Controller {
+      @Get('foos/:objectId')
+      @ApiParam({
+        name: 'objectId',
+        enum: ParamEnum
+      })
+      @ApiQuery({ name: 'order', enum: QueryEnum })
+      @ApiQuery({ name: 'page', enum: ['d', 'e', 'f'] })
+      find(): Promise<Foo[]> {
+        return Promise.resolve([]);
+      }
+    }
+
     @Controller('')
     class BarController {
       @Get('bars/:objectId')
@@ -829,14 +843,15 @@ describe('SwaggerExplorer', () => {
       expect(routes[0].root.parameters).toEqual([
         {
           in: 'query',
+          isArray: true,
           name: 'page',
           required: true,
           schema: {
-            type: 'array',
             items: {
               type: 'string',
-              enum: ['d', 'e', 'f']
-            }
+              enum: ['d', 'e', 'f'],
+            },
+            type: "array"
           }
         },
         {
@@ -860,6 +875,47 @@ describe('SwaggerExplorer', () => {
       ]);
     });
 
+    it('should properly define enum and not add isArray prop to params', () => {
+      const explorer = new SwaggerExplorer(schemaObjectFactory);
+      const routes = explorer.exploreController(
+        {
+          instance: new Foo2Controller(),
+          metatype: Foo2Controller
+        } as InstanceWrapper<Foo2Controller>,
+        'path'
+      );
+
+      expect(routes[0].root.parameters).toEqual([
+        {
+          in: 'query',
+          name: 'page',
+          required: true,
+          schema: {
+            type: 'string',
+            enum: ['d', 'e', 'f'],
+          }
+        },
+        {
+          in: 'query',
+          name: 'order',
+          required: true,
+          schema: {
+            type: 'string',
+            enum: ['d', 'e', 'f']
+          }
+        },
+        {
+          in: 'path',
+          name: 'objectId',
+          required: true,
+          schema: {
+            type: 'string',
+            enum: ['a', 'b', 'c']
+          }
+        }
+      ])
+    })
+
     it('should properly define enum as schema with lazy function', () => {
       const explorer = new SwaggerExplorer(schemaObjectFactory);
       const routes = explorer.exploreController(