启动后如何使用 NSwag 生成代码?

How to do code generation with NSwag after Startup?

我想要生成打字稿文件。在 Startup.cs 中有以下代码。

Configure:
    services.AddSwaggerDocument();
ConfigureServices: 
    app.UseOpenApi();
    app.UseSwaggerUi3();

所以我需要这样的东西:

var document = OpenApiDocument.FromUrlAsync("http://localhost:5005/swagger/v1/swagger.json").Result;
var clientSettings = new TypeScriptClientGeneratorSettings
{
   ClassName = "MyClass",
   TypeScriptGeneratorSettings = { Namespace = "MyNamespace" }
};
var clientGenerator = new TypeScriptClientGenerator(document, clientSettings);
var code = clientGenerator.GenerateFile();
File.WriteAllText(Path.Join(Directory.GetCurrentDirectory(), "generated"), code);

我应该为这个代码选择什么地方?

我已经做到了:

// Configure(...)
            app.UseOpenApi();
            app.UseSwaggerUi3();
            new Thread(() =>
            {
                Thread.Sleep(800);
                GenerateClientCode();
            }).Start();