Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

891
Views
Núcleo de ASP.NET: NSwag frente a Swashbuckle

actualmente estamos usando Swashbuckle.AspNetCore para fines de documentación de API, pero cuando se trata de la generación de modelos del lado del cliente (Typescript), parece que hay un gran inconveniente.

Como muestra, mejoré el conocido proyecto predeterminado de ASP.NET (WeatherForecast) con una clase base

 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; } }

Luego expone WeatherForecast como

 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 }

y la herencia se pierde. Esto hará que sea imposible generar automáticamente modelos del lado del cliente a partir del código del lado del servidor, ya que, naturalmente, nos gusta trasladar la herencia al código de TypeScript.

Al investigar NSwag.AspNetCore , descubrí que se ocupa de la herencia. Expone:

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

¿Pasé por alto algo relacionado con Swashbuckle o no hay otra alternativa para cambiar de él a NSwag?

Puede revisar el código en https://github.com/ClemensOesterle/NSwagSpike/tree/swashbuckle mientras que la implementación de NSwag reside en la rama maestra.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto lo resolvió.

 services.AddSwaggerGen(options => { options.UseAllOfForInheritance();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!