Home Menu Search

Saqwel

IT and other things blog

Скрыть поле модели от Swagger (Hide field of model from Swagger)

Share

При внедрении Swagger в проекте .Net Core Web API потребовалось скрыть одно поле из примера, отображаемого в Swagger. Так как я использовал библиотеку Swashbuckle, то для исключения поля достаточно использовать библиотеку Swashbuckle.AspNetCore.Annotations и указать атрибут в классе модели [SwaggerScheme(ReadOnly = true)]. Ниже пример:

Sometimes while implementing Swagger at .Net Core Web API project required to hide a field from example block of Swagger web page. I have used Swashbuckle library, so enough to use Swashbuckle.AspNetCore.Annotations library and set attribute in model class [SwaggerScheme(ReadOnly = true)] like in example below:

using System;
using Swashbuckle.AspNetCore.Annotations;

namespace Example.Models
{
    public partial class Table1
    {
        [SwaggerScheme(ReadOnly = true)]
        public int Id { get; set; }
        public string Value { get; set; }
    }
}

Leave a Reply