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

Use required keyword with non-nullable types for required DTO fields. #87

Open
ejball opened this issue Aug 22, 2023 · 1 comment
Open

Comments

@ejball
Copy link
Contributor

ejball commented Aug 22, 2023

This could be a breaking change to older client code for the same API, so it might need to be opt-in.

@ejball
Copy link
Contributor Author

ejball commented Aug 23, 2023

Unfortunately, the entire HTTP mapping layer depends on the DTO having the new() generic constraint and all properties being nullable.

The new() generic constraint issue could be circumvented with Activator.CreateInstance<T>(), though not without hurting efficiency. Otherwise we'd need to overhaul the implementation to have every property value ready when the DTO is initialized.

Another difficult case is when a response supports multiple HTTP status codes. A normal body field can be required, but only if the normal status code is used. I suppose we could just skip required/non-nullable in that somewhat rare case.

One more difficulty is that we use the DTO as the JSON request/response body, even if some of the fields are set via path/query/header. Maybe we'd need to codegen an internal DTO with just the body fields.

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