How to configure Swashbuckle to ignore property on model

后端 未结 15 1766
旧巷少年郎
旧巷少年郎 2020-12-02 15:10

I\'m using Swashbuckle to generate swagger documentation\\UI for a webapi2 project. Our models are shared with some legacy interfaces so there are a couple of properties I

15条回答
  •  长情又很酷
    2020-12-02 16:13

    Solution for .NET Core 3.1 and .NET Standard 2.1:

    Use JsonIgnore from System.Text.Json.Serialization namespace.

    ( JsonIgnore from Newtonsoft.Json will NOT work )

    public class Test
    {
        [System.Text.Json.Serialization.JsonIgnore]
        public int HiddenProperty { get; set; }
        public int VisibleProperty { get; set; }
    }
    

提交回复
热议问题