Categories: Articles

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

При внедрении 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; }
    }
}

Saqwel

Share
Published by
Saqwel

Recent Posts

Azure App Configuration and access to Key Vault references

We decided to use an Azure App Configuration to store configs of backend. App Configuration…

2023-08-24

Azure cli az acr login hangs

I have encountered an issue with az acr login --name <acr_name> command. It hanged and…

2023-08-23

Error: Unable to read Docker image into resource: unable to find or pull image nginx:latest

I have tried to learn terraform from scratch and found pretty simple tutorial for beginners.…

2022-09-09

Прогноз цен на акции

Около года назад я решил попробовать заработать на фондовой бирже, покупая и продавая акции. Изучая…

2019-07-20

Installation failed with error code: (0x00000490), “Element not found. “

Во время установки .NET Framework столкнулся с ошибкой Installation failed with error code: (0x00000490), "Element…

2018-12-20

Huawei Watch 2 – замена телефону. Полный обзор

Почти целый год я размышлял и прикидывал, о том, смогу ли я использовать умные часы…

2018-10-06