0

How to change in "Example value" of method decimal value from 0 to 0,00? I found this solution, but it doesn't help to replace value

I use Swashbuckle.AspNetCore v6.1.4 enter image description here

Also I tried this option, but it doesn't work:

public void Apply(OpenApiSchema schema, SchemaFilterContext context)

{
    var fields = context.Type.GetFields();

    if (fields.Length == 0)
        return;

    foreach (var field in fields)
    {
        if (field.FieldType == typeof(Decimal))
        {
            schema.Properties[field.Name] = new OpenApiSchema
            {
                MultipleOf = 0.0000001M
            };
        }
    }
}
Russo
  • 137
  • 7

1 Answers1

0

Please refer to this SO:

As per this solution, the API response is getting deserialized to Javascript objects. Now, 0.00 and 0 both deserialize to the same value (which is what you are seeing in the UI). swagger-ui - which is what Swashbuckle.AspNetCore uses for its UI - only knows that it is a Number at this point: it is displaying what your API JSON deserialized to, and 0.00 and 0 deserialize to the same value.

It is therefore suggested to use multiple of.

 public void Apply(OpenApiSchema schema, SchemaFilterContext context)
 {
      var underlyingType = Nullable.GetUnderlyingType(context.Type);
      if(underlyingType != null && underlyingType == typeof(Decimal))
      {
            schema.MultipleOf = 0.0000001M;
      }
 }
Gauravsa
  • 6,330
  • 2
  • 21
  • 30
  • I used it early, I added in description some similar method, but it doesn't work. I added class with logic which you write and set up swagger c.SchemaFilter(), but it also shows decimal value like int. What the problem could it be? – Russo Oct 05 '22 at 11:38