question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApiModelProperty groups

See original GitHub issue

Hi,

thank you with your contribution of nest and swagger.

I have a question, is there a possibility that the properties with the decorator @ApiModelProperty support groups?

Similar to class-validator groups https://github.com/typestack/class-validator#validation-groups.

export class MyClass {

    @ApiModelProperty({ groups: ["edit"] })
    id: string;

    @ApiModelProperty({ groups: ["edit", "create"] })
    name: string;

    @ApiModelProperty({ groups: ["edit", "create"] })
    description: string;

}

in controller

@ApiImplicitBody({ required: true, type: MyClass, name: "name", groups:["create"]  })
//or
@ApiResponse({ status: 200, description: "OK", type: MyClass, groups:["edit"] })


or is there an alternative to not show all the attributes in a response or body? Currently I am creating additional classes.

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:19
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
kamilmysliwieccommented, Mar 26, 2020

In the latest release (4.5.0), we added PartialType, OmitType, and PickType functions which can mimic the behavior of built-in TypeScript types (respectively Partial, Omit, and Pick).

Example:

class CreateUserDto {
  @ApiProperty()
  email: string;

  @ApiProperty()
  password: string;

  @ApiProperty()
  firstName: string
}

and to create the UpdateUserDto class based on the CreateUserDto, but with all properties marked as optional, use the following code:

export class UpdateUserDto extends PartialType(CreateUserDto) {}

If you want to exclude, let’s say, the email property (because, for instance, email has to be unique and cannot be modified), compose OmitType and PartialType functions, as follows:

export class UpdateUserDto extends PartialType(OmitType(CreateUserDto, ['email'])) {}
3reactions
oaoitcommented, Jan 31, 2018

Its a very useful functionality. Hope will add in future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

swagger @ApiModelProperty example value for List<String ...
I managed to get this to work, generating a List of Strings. Within the ApiModelProperty with springfox 2, write your example as follows:...
Read more >
ApiModelProperty considered differently for POST or for GET ...
Hi there, I am having some problems restricting the documentation for a ApiModelProperty whether the model is to be displayed for a POST...
Read more >
io.swagger.annotations.ApiModelProperty Java Examples
This page shows Java code examples of io.swagger.annotations.ApiModelProperty.
Read more >
@io.swagger.annotations.ApiModelProperty(value = Parent group ...
ApiModelProperty (value = Parent group name the property belongs to.). Learn how to use java api @io.swagger.annotations.ApiModelProperty(value = Parent ...
Read more >
Swagger @ApiParam vs @ApiModelProperty | Baeldung
Learn the difference between Swagger's @ApiParam and @ApiModelProperty.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found