I've just started looking into using NSwag to auto-generate typescript clients for a WebAPI project. I've naively started with this simple build step:
nswag webapi2swagger /assembly:bin\MyProject.WebAPI.dll /output:Swagger.json
nswag swagger2tsclient /input:Swagger.json /output:WebAPIs.ts
This works great... maybe too great. I've now got a 17000 line typescript file full of clients for every endpoint in the API.
I know I could specify individual classes or controllers for nswag to generate, but I'd like it to be automatic for new controllers as we continue to build the system. Ideally, I'd probably be best served with a set of typescript files where each file represented a single controller.
Does anyone know how I might use the command line tools to break up the output that way?
I don't think this is possible with the current CLI tools, so I wrote a small console application which uses reflection to gather controllers from the webapi assembly, then calls the WebApiToSwaggerGenerator and SwaggerToTypeScriptClientGenerator for each controller individually.
This is not possible yet but you can follow this feature's progress on: https://github.com/RicoSuter/NSwag/issues/1398
The page contains some suggested workarounds. One is to use this tool: https://github.com/hemiaoio/nswag-ts-splitter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With