typewags
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

typewags

A typescript web API generator script.

Usage

To generate the TypeScript definitions, you need a type definition and web API information JSON.

Here is a NuGet package for ASP.NET Core projects to generate the JSON:

typewags-aspnetcore

Here is an example of usage if you followed the example of typewags-aspnetcore.

import axios from "axios";
import path from "path";
import fs from "fs/promises";
import { WebAPIInspectResult, ApiBundleGenerator } from "typewags";

async function main() {
  const response = await axios.get<WebAPIInspectResult>(
    // If you follow the example, you can get the definition json by the following request.
    "http://localhost:5000/typewags"
  );
  const json = response.data;
  // Generate all of the definitions by a simple API.
  const generator = new ApiBundleGenerator(json);
  const declarationContent = generator.generateApiInterfaceBundle();
  await fs.writeFile(
    path.resolve(process.cwd(), "bundle.ts"),
    declarationContent
  );
}

main();

Readme

Keywords

none

Package Sidebar

Install

npm i typewags

Weekly Downloads

7

Version

0.2.2

License

MIT

Unpacked Size

88.8 kB

Total Files

60

Last publish

Collaborators

  • darrendanielday