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.

Disable validation for dto properties not working

See original GitHub issue

Hi, I have a Dto with a property name Guid, I want set this property in server side, so I set this attribute with DisableValidation attribute and pass this dto from angular with guid value empty string. but i got status code 400 (bad request). what is solution for my scenario?

C#

public class ContentEntityBaseDto : FullAuditedEntityDto<int>
  {
      [DisableValidation]
      public Guid Guid { get; set; } = Guid.NewGuid();
  }

angular:

export abstract class ContentEntityBase extends FullAuditedEntityBase {
    guid: string  = '';
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, Feb 21, 2019

BTW, if it will be always null, then just don’t add it to your DTO. This would be a better design.

0reactions
hikalkancommented, Feb 21, 2019

[DisableValidation] works for ABP. But a non-null Guid (a value type) is considered as “required” and MVC validation marks it as invalid. Even we (somehow, I don’t know) handle it with ABP, your ModelState.IsValid will be still false. So, you should make it nullable if you allow nulls to set by clients. This is the true design. Other solutions will be just workarounds.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to disable javax.persistence.validation in ...
We are using SpringBoot version 2.7.9, in which I am trying to switch off the automatic validation of the DTOs. However, this does...
Read more >
Remove Dto Validation - architectural change #10
Hi,. I think there are two types of validation: Simply validating format of the DTO properties, like it should not be empty ([Required]) ......
Read more >
Spring Boot DTO Validation Example
In this tutorial, we will learn how to validate Spring boot REST API DTO requests ... @NotNull validates that the annotated property value...
Read more >
Validation | NestJS - A progressive Node.js framework
skipUndefinedProperties, boolean, If set to true then validator will skip validation of all properties that are undefined in the validating object.
Read more >
Validation with Spring Boot - the Complete Guide
If for any reason we want to disable Bean Validation in our Spring Data repositories, we can set the Spring Boot property spring.jpa.properties....
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