NSwag - Separate file generation
Asked Answered
O

3

6

I'm using NSwag to generate my TypeScript client (Angular format), but I'm having problems with implementing Bearer token authentication because of circular dependencies.

My user service needs to import the TS client to use the token DTOs and my TS client needs to import the user service to inject the token.

As such, I was wondering if it was possible to split the generated file into two (or more) client and model files.

Another option is to implement an interceptor on the HTTP requests, but I find that abhorrent since it could cause problems if I use another API.

Osteen answered 18/2, 2019 at 11:26 Comment(1)
Not implemented yet, see github.com/RSuter/NSwag/issues/1398Isidroisinglass
D
2

We've run into this problem but we're planning on doing this the other way around.

  1. curl the swagger document
  2. rummage through it and split it based on tags
  3. create local swagger documents for each tag
  4. run nswag cli against each newly created swagger document

That way we don't have to alter the server just because the client needs something else.

I've successfully broken down the schema to multiple schemas, one per controller, and generated new files through nswag. Not the prettiest code but it works.. Could publish it on github if any one is interested

Doorpost answered 23/2, 2021 at 9:23 Comment(0)
C
1

You can create separate NSwag configurations and run each one. This is the only way to achieve what you are looking for as of right now.

This will not work during build using the normal convention and will need to be modified in the proj file as maybe a powershell script to run Pre or Post process.

Contumacious answered 20/1, 2021 at 20:0 Comment(0)
A
0

I found you can do this using Swashbuckle.AspNetCore.Swagger instead of NSwag.

Americana answered 5/9, 2022 at 8:54 Comment(1)
Do you happen to have an example using Swashbuckle.AspNetCore.Swagger?Contumacious

© 2022 - 2024 — McMap. All rights reserved.