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

Arrays and objects are not managed properly when located in first level of @Query() #1112

Closed
arnaud-cortisse opened this issue Dec 27, 2020 · 3 comments

Comments

@arnaud-cortisse
Copy link
Contributor

I'm submitting a...


[ ] Regression 
[ 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.

Current behavior

I created these DTOs:

class ObjectDto {
  @ApiProperty()
  field: string;
}

export class HelloWorldDto {
  @ApiProperty({
    isArray: true,
    type: ObjectDto,
  })
  arrayOfObjectsDto: ObjectDto[];
}

And expected them as query parameters:

  @Get('/Not Working')
  getHello(@Query() helloWorldDto: HelloWorldDto): string {
    return this.appService.getHello();
  }

I got the following output:
image

Expected behavior

I would expect something like this:
image
As you can see, it's an actual array of objects.

I was able to get it to work by doing the following:

class ObjectDto {
  @ApiProperty()
  field: string;
}

export class Params {
  @ApiProperty({
    isArray: true,
    type: ObjectDto,
  })
  arrayOfObjectsDto: ObjectDto[];
}

export class HelloWorldDto2 {
  @ApiProperty()
  params: Params;
}

As you can see, arrays seem to be declared correctly when they are located in the deeper level in the DTO.
However, this is not a viable option, since the path HelloWorldDto2.params actually doesn't exist...

Minimal reproduction of the problem with instructions

See https://github.com/arnaud-cortisse/nestjs-openapi-array-of-objects-bug

What is the motivation / use case for changing the behavior?

I want to be able to declare arrays of complex objects in the first level of DTOs

Environment


Nest version: 7.5.1

 
For Tooling issues:
- Node version: node:alpine docker image
- Platform: node:alpine docker image
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@arnaud-cortisse arnaud-cortisse changed the title Arrays of objects are not detected as such when located in first level of DTO Arrays and objects are not managed properly when located in first level of @Query() Dec 28, 2020
@arnaud-cortisse
Copy link
Contributor Author

@kamilmysliwiec I've just created a PR here: #1113 👍

@kamilmysliwiec
Copy link
Member

Thanks! Let's track this here #1113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants