I am attempting to create a webpack loader that converts a file containing a description of API data structures into a set of TypeScript interfaces.
In my concrete case,
If your API follows the swagger spec, you can use the npm package swagger-ts-generator to generate TypeScript files from it:
Swagger TypeScript code generator
Node module to generate TypeScript code for Angular (2 and above) based on Webapi meta data in Swagger v2 format.
Basically, you give it the swagger URL and it generates TypeScript. The examples are for Gulp, but they should port over to WebPack fairly well:
var swagger = {
url: 'http://petstore.swagger.io/v2/swagger.json',
//url: 'http://127.0.0.1/ZIB.WebApi.v2/swagger/docs/v1',
swaggerFile: folders.swaggerFolder + files.swaggerJson,
swaggerFolder: folders.swaggerFolder,
swaggerTSGeneratorOptions: {
modelFolder: folders.srcWebapiFolder,
enumTSFile: folders.srcWebapiFolder + 'enums.ts',
enumLanguageFiles: [
folders.srcLanguagesFolder + 'nl.json',
folders.srcLanguagesFolder + 'en.json',
],
modelModuleName: 'webapi.models',
enumModuleName: 'webapi.enums',
enumRef: './enums',
namespacePrefixesToRemove: [
],
typeNameSuffixesToRemove: [
]
}
}