RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.77k stars 1.29k forks source link

Can't create anyof from xml documentation c# #2753

Open sebapala-neta opened 4 years ago

sebapala-neta commented 4 years ago

I am implementing nswag to create swagger.json from the xml documentation of a webapi c # project.

But I can't get an anyOf object like the following to be returned:

`Reservations: description: Lista de reservas incluidas en el itinerario anyOf:

How can I achieve this? Sorry for my English

RicoSuter commented 4 years ago

Maybe this helps: https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance

RicoSuter commented 4 years ago

Or maybe you can add multiple OpenApiReponse attributes

sebapala-neta commented 4 years ago

Nop, sorry for my english i try explain my problem.

I have this:

  public class Product
  {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Category { get; set; }
        public decimal Price { get; set; }
        /// <summary>
        /// Lista de mascotas
        /// </summary>
        public List<Pet> Pets { get; set; }
    }
    /// <summary>
    /// Clase generica de mascota
    /// </summary>
    public abstract class Pet
    {
        /// <summary>
        /// Nombre
        /// </summary>
        public string Name { get; set; }
    }

    /// <summary>
    /// Perro
    /// </summary>
    public class Dog : Pet
    {
        /// <summary>
        /// Edad
        /// </summary>
        public int Age { get; set; }
    }

    /// <summary>
    /// Gato
    /// </summary>
    public class Cat : Pet
    {
        /// <summary>
        /// Color
        /// </summary>
        public string Color { get; set; }
    }

And I want a yaml file like this:

Product:
  type: object
  properties:
    Id:
      description: Id
      type: integer
      format: int32
   Name:
     description: name of product
     type: string
  Pets:
     description: List of Pets
      anyOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'

Thanks in advance

RicoSuter commented 4 years ago

With this code the generator cannot know what implementations exist and there is no discriminator to deserialize. Did you read this link?

https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance

sebapala-neta commented 4 years ago

Yeap, i read your link, But i want generate documentation from c# comments in code, this is my problem.