feat: open-api default response for dart #9709
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows the nestjs controllers to be annotated with the status code specific responses, like
@ApiCreatedResponse
and@ApiOkResponse
- and allows the use of different return types for each response. This works perfectly fine with the typescript client, however, the dart2 open-api generator will pick the type of the first 2xx response as the return type of the the operation - which is not correct if there are divergent types for each response code. To allow the the use of typescript to make use of the additional type information, and also support Dart as best we can - you can make use of the@ApiResponse{status: 'default', ... }
annotation - this PR patches theapi.mustasch
dart template to use the default response's return type instead of the first 2xx response. The coding guidelines would be - if you are planning to different types for different response codes, also include a default response with a type that is the logical union of all the properties each type has. This doesn't give you as nice a type in the the response, but its the best that can be done for the Dart language, as it does not support union return types like typescript and other languages can.Note - the Dart api generator will generate Dart methods for each operation - one that is typed, and one that uses a generic
Response
object that has the format<operation>WithHttpInfo
. A dart client would ALWAYS be able to use the generically typed form of this method.This has been split from: #8480