Home > Enterprise >  .Net Core display DataMember name in Swagger
.Net Core display DataMember name in Swagger

Time:09-14

I have a request of displaying the name from DataMember attribute in the request body of Swagger, instead of displaying the property name.
For example, I have the Test class as below:

  [DataContract]
  public abstract class Test
  {
      [DataMember(Name = "my_test")]
      public Object MyTest{ get; set; }
  }

In the swagger request body, currently it's dispalying myTest, which is the name of property. But, I'd like to display my_test.
Does anyone have any idea how do I do it?

CodePudding user response:

You can decorate with a property name like so:

[DataContract]
public abstract class Test
{
    [DataMember(Name = "my_test")]
    [JsonPropertyName("my_test")]
    public Object MyTest { get; set; }
}
  • Related