Remove references to Managing.Aspire.AppHost and Managing.Aspire.ServiceDefaults from solution and project files; update API project to eliminate unused references and adjust JWT token handling in Program.cs; enhance NSwag generation for Axios and Fetch clients, including new import handling.

This commit is contained in:
2025-12-14 00:18:02 +07:00
parent 0126377486
commit 2157d1f2c9
5 changed files with 72 additions and 49 deletions

View File

@@ -29,6 +29,9 @@ Directory.CreateDirectory(targetWebAppDirectory); // Ensure the directory exists
var targetWeb3ProxyDirectory = Path.Combine(solutionDirectory, "src", "Managing.Web3Proxy", "src", "generated");
Directory.CreateDirectory(targetWeb3ProxyDirectory);
var targetKaigenWebDirectory = "/Users/oda/Desktop/Projects/kaigen-web/webapp/src/generated";
Directory.CreateDirectory(targetKaigenWebDirectory);
var settings = new TypeScriptClientGeneratorSettings
{
ClassName = "{controller}Client",
@@ -53,13 +56,38 @@ var settings = new TypeScriptClientGeneratorSettings
var generatorApiClient = new TypeScriptClientGenerator(document, settings);
var codeApiClient = generatorApiClient.GenerateFile();
// Add the necessary imports after the auto-generated comment
// Settings for Kaigen web project using Axios
var settingsAxios = new TypeScriptClientGeneratorSettings
{
ClassName = "{controller}Client",
ClientBaseClass = "AuthorizedApiBase",
ConfigurationClass = "IConfig",
GenerateDtoTypes = true,
UseTransformOptionsMethod = true,
TypeScriptGeneratorSettings =
{
EnumStyle = TypeScriptEnumStyle.Enum,
DateTimeType = TypeScriptDateTimeType.Date,
NullValue = TypeScriptNullValue.Null,
TypeStyle = TypeScriptTypeStyle.Interface,
GenerateDefaultValues = true,
MarkOptionalProperties = true,
TypeScriptVersion = 4.3m
},
OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator(),
Template = TypeScriptTemplate.Axios,
};
var generatorApiClientAxios = new TypeScriptClientGenerator(document, settingsAxios);
var codeApiClientAxios = generatorApiClientAxios.GenerateFile();
// Add the necessary imports after the auto-generated comment for Fetch version
var requiredImports = @"
import AuthorizedApiBase from ""./AuthorizedApiBase"";
import IConfig from ""./IConfig"";
";
// Find the end of the auto-generated comment and insert imports
// Find the end of the auto-generated comment and insert imports for Fetch version
var autoGeneratedEndIndex = codeApiClient.IndexOf("//----------------------");
if (autoGeneratedEndIndex != -1)
{
@@ -72,7 +100,21 @@ if (autoGeneratedEndIndex != -1)
}
}
// Add the necessary imports for Axios version as well
var autoGeneratedEndIndexAxios = codeApiClientAxios.IndexOf("//----------------------");
if (autoGeneratedEndIndexAxios != -1)
{
// Find the second occurrence (end of the comment block)
autoGeneratedEndIndexAxios = codeApiClientAxios.IndexOf("//----------------------", autoGeneratedEndIndexAxios + 1);
if (autoGeneratedEndIndexAxios != -1)
{
autoGeneratedEndIndexAxios = codeApiClientAxios.IndexOf("\n", autoGeneratedEndIndexAxios) + 1;
codeApiClientAxios = codeApiClientAxios.Insert(autoGeneratedEndIndexAxios, requiredImports);
}
}
File.WriteAllText(Path.Combine(targetWebAppDirectory, "ManagingApi.ts"), codeApiClient);
File.WriteAllText(Path.Combine(targetKaigenWebDirectory, "ManagingApi.ts"), codeApiClientAxios);
var settingsTypes = new TypeScriptClientGeneratorSettings
{
@@ -97,4 +139,5 @@ var generatorTypes = new TypeScriptClientGenerator(document, settingsTypes);
var codeTypes = generatorTypes.GenerateFile();
File.WriteAllText(Path.Combine(targetWebAppDirectory, "ManagingApiTypes.ts"), codeTypes);
File.WriteAllText(Path.Combine(targetWeb3ProxyDirectory, "ManagingApiTypes.ts"), codeTypes);
File.WriteAllText(Path.Combine(targetWeb3ProxyDirectory, "ManagingApiTypes.ts"), codeTypes);
File.WriteAllText(Path.Combine(targetKaigenWebDirectory, "ManagingApiTypes.ts"), codeTypes);