GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - greymind/WebApiToTypeScript: A tool for code generating TypeScript endpoints for your ASP.NET Web API controllers

BranchesTags
Open more actions menu

Latest commit

 

History

358 Commits
358 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
PackAndPush.ps1
PackAndPush.ps1
 
 
README.md
README.md
 
 
Watts.nuspec
Watts.nuspec
 
 

Repository files navigation

Web API To TypeScript

Join the chat at https://gitter.im/WebApiToTypeScript/Lobby

A tool for code generating TypeScript endpoints for your ASP.NET Web API controllers and their actions. No more need for dumb repositories!

  • Generates typed endpoints with required and optional parameters for GET, PUT, POST and DELETE verbs
    • Generates cached endpoints for GET verb actions
  • Generates enumerations and interfaces for DTOs used in all controller actions
    • Generates enum descriptions based on the [Description] attribute
  • Generates Angular service to expose typed call() function to fetch response from server
  • Generates typed views to use on front-end
  • Generates resources files based on .resx files

Examples

Take a look at the generated files and sample test files here

Getting the tool from NuGet

https://www.nuget.org/packages/WebApiToTypeScript/

Install-Package WebApiToTypeScript

Using as standalone tool

Just run the executable with the config file as the argument

watts.exe "Path/To/Config/File.json"

Using as MSBuild Target

I haven't tested this in a while, so if you find any inconsistencies with working directory and such, feel free to file an issue or better yet, submit a pull request!

Ensure the DLL is part of the build process, so you have access to it. Easiest way is to reference it in your project.

<UsingTask TaskName="WebApiToTypeScript.WebApiToTypeScript" AssemblyFile="$(ProjectDir)..\WebApiToTypeScript\bin\Debug\WebApiToTypeScript.dll" />
<Target Name="AfterBuild">
    <WebApiToTypeScript ConfigFilePath="$(ProjectDir)Watts.config.json" />
</Target>

T4 Template

If you wish to integrate the executable as part of your workflow from within Visual Studio, you may consider wiring it up to a T4 template. Here is a sample.

Protip

You can build just the C# parts of the solution by adding a condition to the TypeScript target in the csproj file. This way you can ensure that before you run WebApiToTypeScript, you have a hassle-free build of the backend code.

  <PropertyGroup>
    <SkipTypeScript Condition="'$(SkipTypeScript)'==''">False</SkipTypeScript>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets') AND '$(SkipTypeScript)'=='False'" />
Path\To\msbuild.exe /t:build /p:SkipTypeScript=True Path\To\Project.csproj

Using Angular Endpoints Service

You'll need to register the Endpoints service to your app and inject it as is typical in Angular

angular.module('framework').service('AngularEndpointsService', Framework.Endpoints.AngularEndpointsService);

Config

{
  "WebApiModuleFileName": "string",
  "WebApiModuleFileNames": [ "string" ]
  
  "GenerateEndpointsReturnTypes": "boolean",
  "GenerateEndpoints": "boolean",  
  "EndpointsOutputDirectory": "string",
  "EndpointsSupportCaching": "boolean",
  "EndpointsFileName": "string",
  "EndpointsNamespace": "string",
  
  "GenerateMobileEndpoints": "boolean",
  "MobileEndpointsOutputDirectory": "string",
  "MobileEndpointsFileName": "string",
  "MobileEndpointsNamespace": "string",
  "MobileEndpointAttributeName": "string",

  "GenerateService": "boolean",
  "ServiceOutputDirectory": "string",
  "ServiceFileName": "string",
  "ServiceNamespace": "string",
  "ServicesName": "string",

  "GenerateEnums": "boolean",
  "GenerateEnumDescriptions": "boolean",
  "EnumsOutputDirectory": "string",
  "EnumsFileName": "string",
  "EnumsNamespace": "string",

  "GenerateInterfaces": "boolean",
  "InterfacesOutputDirectory": "string",
  "InterfacesFileName": "string",
  "InterfacesNamespace": "string",
  "InterfaceMembersInCamelCase": "boolean",
  "InterfaceCamelCaseCustomAttribute": "string",
  "InterfaceMatches": [
    "Match": "string",
    "ExcludeMatch": "string",
    "BaseTypeName": "string"
  ],

  "GenerateViews": "boolean",
  "ViewConfigs": [
    {
      "SourceDirectory": "string",
      "Namespace": "string",
      "OutputFilename": "string",
      "Prefix": "string",
      "UrlEncodePath": "boolean"
    }
  ],
  "ViewsPattern": "string",
  "ViewsOutputDirectory": "string",
  "UseViewsGroupingNamespace": "boolean",
  "ViewsIgnoredExtensions": [
      "string"
  ]

  "ScanOtherModules": "boolean",
  "WriteNamespaceAsModule": "boolean",

  "TypeMappings": [
    {
      "WebApiTypeName": "string",
      "TypeScriptTypeName": "string",
      "AutoInitialize": "boolean",
      "TreatAsAttribute": "boolean"
      "TreatAsConstraint": "boolean",
      "Match": "string"
    }
  ]
}

License

MIT

About

A tool for code generating TypeScript endpoints for your ASP.NET Web API controllers

Topics

angularasp-netc-sharpcode-generationcode-generatorcsharptypescriptwebapiwebapi-2

Resources

Readme
MIT license
Activity

Stars

25 stars

Watchers

9 watching

Forks

9 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.