TSCodegen.WebAPI 1.4.0

dotnet add package TSCodegen.WebAPI --version 1.4.0
NuGet\Install-Package TSCodegen.WebAPI -Version 1.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TSCodegen.WebAPI" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TSCodegen.WebAPI --version 1.4.0
#r "nuget: TSCodegen.WebAPI, 1.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TSCodegen.WebAPI as a Cake Addin
#addin nuget:?package=TSCodegen.WebAPI&version=1.4.0

// Install TSCodegen.WebAPI as a Cake Tool
#tool nuget:?package=TSCodegen.WebAPI&version=1.4.0

TSCodegen.WebAPI

Library for C# ASP.NET controllers conversion to TypeScript axios services. Available as NuGet package.

Based on TSCodegen library.

Compatible with .NET Standard 2.0 and higher!

How it works

Codegen will examine calling assembly for all classes with the ApiController attribute. Then for each matching class Codegen will iterate over all methods with any attribute that starts with "Http" prefix (e.g. HttpGet).

Codegen will also handle methods with first argument having attribute FromBody for GET, DELETE, HEAD, OPTIONS methods and FromForm for POST, PUT, PATCH methods, though such methods must contain only one argument.

Prerequisites

Install axios and qs (querystring) to your frontend project.

npm i axios
npm i qs

Usage

Add to the start of the Main function:

#if DEBUG
Codegen.Run(new Codegen.Config
{
    OutputPath = @"\ui\api",
    AxiosImportPath = @"axios",
    Indentation = 4,
    AllowDots = true,
    SkipNulls = true,
    ForbiddenNamespaces = new()
    {
        "Project.Database.Core.Entities",
    }
});
#endif

To controllers or methods you would like to omit apply CodegenIgnore attribute.

To delay refactoring restricted return models namespaces apply CodegenSuppressErrors attribute to endpoint method.

Codegen.Config properties

OutputPath

Output path that is relative to the .sln file.

AxiosImportPath

Path for import expression, e.g. with axios value will emit import axios from "axios";. Can be used to specify custom file with axios instance default export.

Indentation

Space indentation size for generated code.

ForbiddenNamespaces

List of namespaces that entities of will throw exception.

DateTime conversion

C# DateTime class will be converted to Date | DateTimeString. You need to declare DateTimeString in any of your *.d.ts files. Example:

declare type DateString = "YYYY-MM-DD";
declare type TimeString = "HH:mm:ss";
declare type DateTimeString = `${DateString}T${TimeString}`;

Generated files

Library will generate file structure:

api\
├ myController\
│  ├ myMethod1.ts
│  ├ myMethod2.ts
│  ├ types.ts
│  └ index.ts
└ index.ts

Where api\index.ts will contain default export with all APIs as objects with functions (e.g. api.myController.myMethod).

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 211 4/5/2024
1.3.1 844 1/18/2024
1.3.0 735 11/16/2023
1.2.10 156 11/6/2023
1.2.9 194 11/1/2023
1.2.8 88 10/27/2023
1.2.7 99 10/27/2023
1.2.6 393 8/30/2023
1.2.5 185 8/22/2023
1.2.4 112 8/22/2023
1.2.3 112 8/22/2023
1.2.2 229 8/11/2023
1.2.1 183 8/4/2023
1.2.0 167 8/3/2023
1.1.2 142 8/3/2023
1.1.1 146 8/3/2023
1.1.0 137 8/3/2023
1.0.0 128 8/1/2023