nswagjs

JavaScript API for NSwag

Usage no npm install needed!

<script type="module">
  import nswagjs from 'https://cdn.skypack.dev/nswagjs';
</script>

README

NSwag.JS

JavaScript API for NSwag - The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.

Example

JavaScript Import
const NSwag = require('nswagjs').NSwag

const nswag = new NSwag(NSwag.getCoreVersion())

Importing NSwag

import NSwag from 'nswagjs'

const nswag = new NSwag('./node_modules/nswag', NSwag.getCoreVersion())

Executing a .nswag configuration document by using the run method

// path to *.nswag or nswag.json file
await nswag.run(path.join(__dirname, 'main.nswag'), {
    input: {
        path: path.join(__dirname, 'main.openapi.json'), // same as url, can be undefined
        json: data // optional string, required if path/url is undefined
    },
    outputs: {
        // path to generated file
        'openApiToTypeScriptClient': path.join(__dirname, 'generated/run.test.ts')
    }
})

Using openapi2tsclient generator

await nswag.openapi2tsclient(path.join(__dirname, 'main.openapi.json'), path.join(__dirname, 'generated/run.test.ts'))

Useful tools

@accility/protoc-swagger-plugin — Protocol Buffer to Swagger/OpenAPI plguin for @accility/protoc-tools.

Upcoming updates

  • Support for the openapi2csclient, .NET Swagger Generator, and JSON Schema Converters will be implemented in v2.0.

Support for swagger generators is not going to be implemented due to the deprication.

License

This project is licensed under MIT.