4

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please share your console application source code with us?
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.