immich icon indicating copy to clipboard operation
immich copied to clipboard

feat: open-api default response for dart

Open midzelis opened this issue 1 year ago • 1 comments
trafficstars

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 the api.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: https://github.com/immich-app/immich/pull/8480

midzelis avatar May 23 '24 22:05 midzelis

Since we have found a way to patch the generated client, I think the PR will not applied anymore, correct?

alextran1502 avatar Oct 09 '24 16:10 alextran1502