add nswag

This commit is contained in:
2025-04-23 13:03:33 +07:00
parent df5f7185c8
commit eeecb188c7
7 changed files with 86 additions and 0 deletions

BIN
src/.DS_Store vendored

Binary file not shown.

BIN
src/Nswag/.DS_Store vendored Normal file

Binary file not shown.

16
src/Nswag/Nswag.sln Normal file
View File

@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nswag", "Nswag\Nswag.csproj", "{275DEC50-FB97-45FC-A9B4-D4707017F889}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{275DEC50-FB97-45FC-A9B4-D4707017F889}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{275DEC50-FB97-45FC-A9B4-D4707017F889}.Debug|Any CPU.Build.0 = Debug|Any CPU
{275DEC50-FB97-45FC-A9B4-D4707017F889}.Release|Any CPU.ActiveCfg = Release|Any CPU
{275DEC50-FB97-45FC-A9B4-D4707017F889}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

BIN
src/Nswag/Nswag/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NSwag.CodeGeneration.TypeScript" Version="14.2.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,56 @@
// See https://aka.ms/new-console-template for more information
using NJsonSchema.CodeGeneration.TypeScript;
using NSwag;
using NSwag.CodeGeneration.OperationNameGenerators;
using NSwag.CodeGeneration.TypeScript;
var document = OpenApiDocument.FromUrlAsync(("http://localhost:5000/swagger/v1/swagger.json")).Result;
var settings = 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.Fetch,
};
var generatorApiClient = new TypeScriptClientGenerator(document, settings);
var codeApiClient = generatorApiClient.GenerateFile();
File.WriteAllText("ManagingApi.ts", codeApiClient);
var settingsTypes = new TypeScriptClientGeneratorSettings
{
GenerateDtoTypes = true,
TypeScriptGeneratorSettings =
{
EnumStyle = TypeScriptEnumStyle.Enum,
DateTimeType = TypeScriptDateTimeType.Date,
NullValue = TypeScriptNullValue.Null,
TypeStyle = TypeScriptTypeStyle.Interface,
GenerateDefaultValues = true,
MarkOptionalProperties = true,
TypeScriptVersion = 4.3m
},
GenerateClientClasses = false,
GenerateClientInterfaces = false,
GenerateOptionalParameters = false,
GenerateResponseClasses = false,
};
var generatorTypes = new TypeScriptClientGenerator(document, settingsTypes);
var codeTypes = generatorTypes.GenerateFile();
File.WriteAllText("ManagingApiTypes.ts", codeTypes);