Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

895
Visualizações
ASP.NET core: NSwag vs. Swashbuckle

we're currently using Swashbuckle.AspNetCore for API documentation purpose, but when it comes to generation of client-side models (Typescript) it seems there is a major drawback of it.

As a sample, I enhanced the known ASP.NET default project (WeatherForecast) with a base class

public class InfoEntryBase    
{        
   public string Name { get; set; }
   public string Description { get; set; }
}

public class WeatherForecast : InfoEntryBase
{
   public DateTime Date { get; set; }

   public int TemperatureC { get; set; }

   public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

   public string Summary { get; set; }
}

It then exposes WeatherForecast as

WeatherForecast{
name    string
nullable: true
description string
nullable: true
date    string($date-time)
temperatureC    integer($int32)
temperatureF    integer($int32)
readOnly: true
summary string
nullable: true
}

and the inheritance gets lost. This will make it impossible to auto-generate client-side models from the server-side code as we naturally like to port the inheritance to the Typescript code.

On investigating NSwag.AspNetCore I discovered it to take care about the inheritance. It exposes:

WeatherForecast{
name    string
description string
date*   string($date-time)
temperatureC*   integer($int32)
temperatureF*   integer($int32)
summary string
}
InfoEntryBase{
name    string
description string
}

Did I overlook something regarding Swashbuckle or is there no alternative to switch from it to NSwag?

You can review the code on https://github.com/ClemensOesterle/NSwagSpike/tree/swashbuckle whereas the NSwag implementation resides in the master branch.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This solved it.

services.AddSwaggerGen(options =>
{
    options.UseAllOfForInheritance();
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda