Search code examples
openapiopenapi-generator

How to prevent models being generated with full namespace?


When I run openapi-generator-cli the Models and containing files are being output with their names containing the full namespace of the API classes. This is very awkward to read. I'd like the output to contain only the Model name, without the namespace.

E.g for class

namespace My.NameSpace.Common.V1.Models.Dto
{
    public partial class PortfolioAsset
    {
        // properties

The output looks like

my-namespace-common-v1-models-dto-portfolio-asset.ts

With the content of the file as

export interface MyNamespaceCommonV1ModelsDtoPortfolioAsset { 
    // parameters
}

I just want the file to be called portfolio-asset.ts and the content to be

export interface PortfolioAsset { 
    // parameters
}

How can I do this?


Solution

  • The fix was simply to remove the CustomSchemaIds line, which specified that I should use the full name of each type being generated.

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info { Title = AppSettingsProvider.AppSettings.ApplicationName, Version = "v1" });
                // c.CustomSchemaIds(x => x.FullName); <-- delete ftw
            });