Remora / Remora.Rest

Reusable tooling for interacting with JSON-driven REST APIs
GNU Lesser General Public License v3.0
7 stars 10 forks source link

Fix DTO Converter when using implementation type directly #14

Closed DPlayer234 closed 2 years ago

DPlayer234 commented 2 years ago

Turns out I introduced a subtle bug in https://github.com/Remora/Remora.Rest/pull/13.

The DTO converter factory claims it can convert the implementation type, but trying to do so directly will fail on STJ's level. (Seems like converters returned by factories are expected to exactly match the type provided.)

By "directly", I mean situations like JsonSerializer.Deserialize<TImplementation>(...) or simply specifying the implementation type instead of the interface in a DTO otherwise.

This is definitely not the intended pattern, but it used to work and the factory still claims it's supported through its CanConvert method.

That said, this PR makes the DTOConverter return a converter for the correct type and adds tests to assert doing the above works.

(Regarding the change in ExpressionFactoryUtilities, the previous check used to fail if typeof(T) == DeclaringType.)