Add nswag
This commit is contained in:
14
src/Managing.Nswag/Managing.Nswag.csproj
Normal file
14
src/Managing.Nswag/Managing.Nswag.csproj
Normal 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.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
56
src/Managing.Nswag/Program.cs
Normal file
56
src/Managing.Nswag/Program.cs
Normal 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);
|
||||
Reference in New Issue
Block a user