RicoSuter / NSwag

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

Exclude type from code generation #705

Open Yavor81 opened 7 years ago

Yavor81 commented 7 years ago

Hi, I want to implement file upload in a Web API endpoint that accepts IEnumerable in my ASP.NET core application. Since this is an built-in type, how can I prevent from generating a proxy for the IFormFile. I am using NSwagStudio but the option "Excluded type names" seems not working.

I am using the C# generator.

RicoSuter commented 7 years ago

ExcludedTypeNames only works for DTO classes, are you trying to exclude a client class?

Yavor81 commented 7 years ago

Te endpoint receives IFormFile as an input parameter. My generated client should be able to pass such objects. The problem is that the generator generates another type named 'FileParameter', which is something I want to prevent. I just want to preserve the IFormFile type to be references in the generated client.

Yavor81 commented 7 years ago

Actually, what I need is a form data generator for CSharp to be able to generate upload file method in the client.

RicoSuter commented 7 years ago

Can you post a sample controller?

Yavor81 commented 7 years ago

In general, what I want is to prevent NSwag from generating class for existing types. For example: Telerik Kendo UI has couple of types for support paging and sorting. The input class is DataSourceRequest and the result class is DataSourceResult. Currently, NSwag generates client classes that are similar to these two. I have to create map methods between the two which is a cumbersome and error prone process. My idea is if NSwag can re-use the existing types by specifying the fully qualified name of the class for example. Is this possible now?

RicoSuter commented 7 years ago

You can exclude the types with ExcludedTypeNames and add usings with AdditionalNamespaceUsages

RicoSuter commented 7 years ago

Related: https://github.com/RSuter/NJsonSchema/issues/414

bhaidar commented 6 years ago

@YavorTelerik @RSuter Hello, I am facing the same issue with objects related to DataSource. Did you find a solution around with NSWAG?

Thanks

RicoSuter commented 6 years ago

Isnt ExcludedTypeNames working for you?

bhaidar commented 6 years ago

Hi @RSuter I posted this before you told me about the ignore attribute. Now, i am ignoring those methods that make use of the Telerik complex objects and extending the generated class with methods specific for those Telerik objects, etc.

Thanks

reggiepangilinan-s5 commented 6 years ago

Hi @RSuter i want to only exclude the "base class" in the model list of swagger ui.

For example i have a base type of

   public abstract class BaseEntity
    {
        public BaseEntity() 
        {
            CreatedTS = DateTime.Now;
            UpdatedTS = DateTime.Now;
        }
        public int Id { get; set; }
        public DateTime CreatedTS { get; set; }
        public string CreatedBy { get; set; }
        public DateTime UpdatedTS { get; set; }
        public string UpdatedBy { get; set; }
    }

and the deriving type is

    public class FieldAgency : BaseEntity
    {
        public string FieldAgencyNbr { get; set; }
        public string Name { get; set; }
    }

In the generated model i want to see all the properties of the BaseEntity in the derived type but i dont want the BaseEntity in the model list.

Is this possible>

wrende commented 4 years ago

Hi, is there any solution for this yet ? I want to exclude the derived class FileParameters/FileResponse that is created due IFormFile and create my own class on another namespace

RicoSuter commented 4 years ago

Use https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema/Annotations/JsonSchemaFlattenAttribute.cs to hide/merge base class

oliverw commented 10 months ago

ExcludedTypeNames only works for DTO classes, are you trying to exclude a client class?

Is there a way to ignore entire namespaces?