0

I am using Swagger-Net 8.43.* in .Net 4.8 Web Api

Is it possible to show null values in response body (not in Example value) only in Swagger UI without changing SerializerSettings for whole Api?

Now I have registered IgnoreNulls

config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;

and not going to change it. But want to show ONLY in swagger

Emin Hasanov
  • 1,299
  • 1
  • 13
  • 29
  • 2
    Not natively. Why would you want to do this? Swagger is meant to produce exactly what your API produces. – squillman Oct 08 '21 at 16:22
  • because some dummy consumers, when doesn't see some fileds, they are accepting it as breaking changes. Because of performance, I turned off null values api real response – Emin Hasanov Oct 08 '21 at 16:24
  • 3
    Wouldn't you still have the problem though when they go to consume your API and the fields aren't there? I'd think that if your example response includes the fields that you could clearly explain in the response description that fields will not be present if they are null. You can also indicate in the Swagger docs that the field is nullable (ie- `nullable: true`). – squillman Oct 08 '21 at 16:35
  • 1
    defeats the purpose of swagger.... because now your swagger does not match your api – Jonathan Alfaro Oct 08 '21 at 16:50

0 Answers0