CenterEdge / Yardarm

OpenAPI 3 SDK Generator for C#
Apache License 2.0
46 stars 6 forks source link

Add `IOperationResponse<TBody>` to responses with a body #164

Closed brantburnett closed 1 year ago

brantburnett commented 1 year ago

Motivation

When dealing with abstraction layers wrapping multiple different API calls it is very difficult to gain access to the body as each different response object as a different GetBodyAsync method returning a different type.

Modifications

Add a common IOperationResponse<TBody> interface, inherited from IOperationResponse, which includes the GetBodyAsync method. Include this interface on all response classes which include a body.

Results

Abstraction layers in consumers can use type checking to find the interface they want. This is particularly useful for error handling if the API in question returns all errors with an Error schema or similar. You can simply response as IOperationResponse<Error> to test and then get the Error object from the GetBodyAsync method.

brantburnett commented 1 year ago

@astrid-eai

This change may interest you as well. We'll probably be adding it to a 0.3.1 point release.

brantburnett commented 1 year ago

/merge