Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swagger-to-C#-client] Better usability for SwaggerException<TResult> #1120

Open
piaste opened this issue Dec 29, 2017 · 0 comments
Open

[Swagger-to-C#-client] Better usability for SwaggerException<TResult> #1120

piaste opened this issue Dec 29, 2017 · 0 comments

Comments

@piaste
Copy link

piaste commented Dec 29, 2017

Issue:

Currently, if a user consumes an API which has multiple non-2xx return types, NSwag generates a generic SwaggerException<TResult> class and instantiates it for each documented return type.

The problem is that the user needs to browse the generated code in order to figure out which possible TResults he needs to catch. As best as I can tell, there is no way to discover than from the client's public interface.

Proposed solution 1

Add XML comments to the generated ExceptionClasses, listing the possible types returned by each call.

Pro: Much simpler to implement, could be as simple as adding a few lines to File.liquid

Con: No type safety. Also, since the client could be using either a single {controller}Exception class for all endpoints in the controller, or even by default a single SwaggerException class for the entire API, the XML comments would grow very unwieldy!

Proposed solution 2

Instead of generating a generic subclass of SwaggerException, generate specific subclasses for each return type. (I would make them nested classes as well, to help discoverability.)

Pro: Type safe, easier to use

Con: More complex to implement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant