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

ProblemDetails Title #126

Open
buti1021 opened this issue Mar 28, 2023 · 1 comment
Open

ProblemDetails Title #126

buti1021 opened this issue Mar 28, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@buti1021
Copy link
Contributor

Currently, the title of the ProblemDetails Result, is hardcoded.
e.g.,

Title = "Resource not found.",

This does not allow internationalization and makes the content pretty generic. However, according to the RFC standard, localization is intended and the message provided in the example is pretty specific.
https://www.rfc-editor.org/rfc/rfc7807
First, I thought of having titles in multiple languages in ardalis.result, but now I think the best approach would be to allow the developer using ardalis.result to set the title. Any thoughts?

@ardalis
Copy link
Owner

ardalis commented May 16, 2024

I agree with your intention. The trick is, how to implement it. The methods in question are private and don't accept a title argument. If they did, it would break their usage in ResultStatusMap because currently it needs a Func<ControllerBase, IResult, object> type:

        public ResultStatusOptions With(Type responseType, Func<ControllerBase, IResult, object> getResponseObject)
        {
            ResponseType = responseType;
            GetResponseObject = getResponseObject;
            return this;
        }

Even if it accepted a title, there's not currently a way to pass one into the AddDefaultMap method:

        public ResultStatusMap AddDefaultMap()
        {
            return For(ResultStatus.Ok, HttpStatusCode.OK)
                .For(ResultStatus.Error, (HttpStatusCode)422, resultStatusOptions => resultStatusOptions
                    .With(UnprocessableEntity))
                .For(ResultStatus.Forbidden, HttpStatusCode.Forbidden)
                .For(ResultStatus.Unauthorized, HttpStatusCode.Unauthorized)
                .For(ResultStatus.Invalid, HttpStatusCode.BadRequest, resultStatusOptions => resultStatusOptions
                    .With(BadRequest))
                .For(ResultStatus.NotFound, HttpStatusCode.NotFound, resultStatusOptions => resultStatusOptions
                    .With(NotFoundEntity))
                .For(ResultStatus.Conflict, HttpStatusCode.Conflict, resultStatusOptions => resultStatusOptions
                    .With(ConflictEntity))
                .For(ResultStatus.CriticalError, HttpStatusCode.InternalServerError, resultStatusOptions =>
                    resultStatusOptions
                        .With(CriticalEntity))
                .For(ResultStatus.Unavailable, HttpStatusCode.ServiceUnavailable, resultStatusOptions =>
                    resultStatusOptions
                        .With(UnavailableEntity))
                .For(ResultStatus.NoContent, HttpStatusCode.NoContent);
        }

I could parameterize With so that it uses the new signature and takes in a title argument, so then AddDefaultMap would look like this:

            return For(ResultStatus.Ok, HttpStatusCode.OK)
                .For(ResultStatus.Error, (HttpStatusCode)422, resultStatusOptions => resultStatusOptions
                    .With(UnprocessableEntity, "Not processable"))
...

But that doesn't really help anything because it's still a hard-coded string inside my library.

Maybe my library could look for something in configuration, and use that if it's present?

I'm open to implementation suggestions.

@ardalis ardalis added enhancement New feature or request help wanted Extra attention is needed labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants