Search code examples
c#asp.net-corenswag

Generating client code with NSwag - problem with nested classes


So I have ASP.NET Core webservice which uses MediatR to pass request from controllers to appropriate handlers. So in turn I have nested classes:

public class SomeCommand
{
    public class Request : IRequest<Response> {}

    public class Response {}

    public class Handler : IRequestHandler<Request, Response> {}
}

So, in turn, Request and Response are my DTOs.

Now I am trying to generate client package with NSwag, which ignores external classes (SomeCommand) and produces DTOs with names Request, Request1, etc., same for Response.

I use NSwag.MSBuild package to automatically generate code when building the API.

Ideally, I would like to get generated names as SomeCommand_Request or SomeCommandRequest.

I tried "AllowReferencesWithProperties": true in nswag.json configuration file, but it did not work.

Other than that, I could not find anything.


Solution

  • I downloaded source code for every nuget package involved in NSwag and analyzed down to the root.

    If I am not mistaken, at the very core, only class name is taken into account, so there does not exist any option to achieve what I am trying to do.

    So answer is: this is not possible and one should use another tool if possible or create own :(

    It seems like someone tried to add similair functionality, but pull request is stuck since 2 years now:

    AppendSchema method will receive the type information

    More Flexible Type Name Generation