The code that adds media types in MvcCoreBuilderExtensions.cs mean the response for JSON will ALWAYS will return application/vnd.restful+json
#333
Replies: 24 comments
-
The reason I think it should not be this way is that if you removed the second output formatter and just left I also tried setting Content-Type to no avail. |
Beta Was this translation helpful? Give feedback.
-
I'm not actually certain what the correct behaviour should be. If you request json and we send a specific subset of json, I'm not certain that is incorrect. Do you have some references detailing the correct behaviour?
Kind Regards,
Muhammad Rehan Saeed
RehanSaeed.com
From: Victorio Berra <[email protected]>
Sent: Wednesday, June 12, 2019 10:51:55 PM
To: Dotnet-Boxed/Templates
Cc: Subscribed
Subject: [Dotnet-Boxed/Templates] The code that addfs media types mean they ALWAYS will return `application/vnd.restful+json` (#333)
Which project template is the issue about?
API
...
Which version of the project template is the issue about?
...
Which version of Visual Studio or the dotnet SDK were you using?
2.2.203
...
If you call the API with a client and you set Accept to application/json it is completely ignored and you will ALWAYS get application/vnd.restful+json back.
Is this desired? This does not seem like it should be that way.
https://github.com/Dotnet-Boxed/Templates/blob/master/Source/Content/ApiTemplate/Source/ApiTemplate/MvcCoreBuilderExtensions.cs#L94
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<https://github.com/Dotnet-Boxed/Templates/issues/333?email_source=notifications&email_token=AARKJHAEAVVDH6JAIEMCMYTP2FVXXA5CNFSM4HXS3DB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GZFPD6Q>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AARKJHF4FKHC5B6V6D37SL3P2FVXXANCNFSM4HXS3DBQ>.
|
Beta Was this translation helpful? Give feedback.
-
@RehanSaeed I am not sure exactly I need to study "content negotiation" a little better. I assumed you should always get back what you said you accept. Getting problem json for a 200ok seems wrong. |
Beta Was this translation helpful? Give feedback.
-
Also, I think that since those are content subtypes (+json) you do not need to actually add them. khellang/Middleware#54 (comment) |
Beta Was this translation helpful? Give feedback.
-
I read @khellang's comment in khellang/Middleware#54 (comment). If I've understood correctly, there isn't much else we can do. If so, can we close? |
Beta Was this translation helpful? Give feedback.
-
I vote that we remove all of this |
Beta Was this translation helpful? Give feedback.
-
Yeah, maybe. I feel like I should write a few unit tests for each scenario. Here is what I think currently happens or should happen. Not sure if any of this is correct. I'd love to find some time to find documentation or maybe we should ask a StackOverflow question and farm out that work.
|
Beta Was this translation helpful? Give feedback.
-
Yes that is what I would expect, maybe: Accept: application/json - Success returns: application/json I say that because i think we should be writing the least amount of extra boilerplate as possible. I would like to use whatever MVC Core uses out of the box. |
Beta Was this translation helpful? Give feedback.
-
That is the one I'm just not sure about and would need to see some evidence to back up. Agree on writing the minimum boilerplate. |
Beta Was this translation helpful? Give feedback.
-
I messed with input and output formatters and wrote more integration tests for the ASP.NET Core 3.0 update. Please check out the netcore3 branch and comment. |
Beta Was this translation helpful? Give feedback.
-
The input/output formatters still look roughly the same right? They will still always return whatever you insert at the 0 index. I do like the test assertions for the problem details, I think that is helpful. |
Beta Was this translation helpful? Give feedback.
-
@VictorioBerra Did you manage to take a look at the tests? One solution to the Swagger UI selecting an incorrect MIME type in the drop down is to add the following to the controllers. However, it's annoying to have to add this to all controllers. You could add it globally but sometimes you might want to use other MIME types, so I don't think thats a good idea. [Produces("application/application/vnd.restful+json")]
[Produces("application/problem+json")] This has been on my mind for a while. I need to experiment with it to see what to do. Feel free to do so yourself. |
Beta Was this translation helpful? Give feedback.
-
@RehanSaeed You just mean these content type checks you made on the tests right? https://github.com/Dotnet-Boxed/Templates/blob/master/Source/ApiTemplate/Tests/ApiTemplate.IntegrationTest/Controllers/CarsControllerTest.cs#L107 I think the way this works is fine for now. Id leave the For the Swagger UI thing, that is definitely annoying. I would also agree not to add those to every single controller, if you add globally is there a way to make that configurable in appsettings maybe? It seems like Swagger with force us to manually put it somewhere. |
Beta Was this translation helpful? Give feedback.
-
I wouldn't want to put it in globally as an MVC filter. That will cause problems when someone wants to respond with some other MIME type. Only place is on the |
Beta Was this translation helpful? Give feedback.
-
I suppose its necessary then. Its too bad we cant add them to something like the new API conventions feature. |
Beta Was this translation helpful? Give feedback.
-
Yes, that might be one way to do it. |
Beta Was this translation helpful? Give feedback.
-
The MIME types in Swashbuckle are all over the place. Adding I think the ideal scenario is if [SwaggerResponse(StatusCodes.Status201Created, "The car was created.", typeof(Car), "application/vnd.restful+json")]
[SwaggerResponse(StatusCodes.Status400BadRequest, "The car is invalid.", typeof(ProblemDetails), "application/problem+json")] Raised domaindrivendev/Swashbuckle.AspNetCore#1691 to propose this. |
Beta Was this translation helpful? Give feedback.
-
Also wondering if I should stop using comments on controllers and switch completely to attributes. |
Beta Was this translation helpful? Give feedback.
-
I think the comments can provide more info than the attributes. Also, read this domaindrivendev/Swashbuckle.AspNetCore#816 (comment) |
Beta Was this translation helpful? Give feedback.
-
Nice. You're one step ahead of me. |
Beta Was this translation helpful? Give feedback.
-
Still no answer in domaindrivendev/Swashbuckle.AspNetCore#1691 |
Beta Was this translation helpful? Give feedback.
-
I bet the change is a ton of work for them, especially since the UI stuff
is by a different team I think.
…On Wed, Nov 4, 2020, 10:51 AM Muhammad Rehan Saeed ***@***.***> wrote:
Still no answer in domaindrivendev/Swashbuckle.AspNetCore#1691
<domaindrivendev/Swashbuckle.AspNetCore#1691>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/Dotnet-Boxed/Templates/issues/333#issuecomment-721813077>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWMN26YRJ7QY4EGD55JGT3SOF2ARANCNFSM4HXS3DBQ>
.
|
Beta Was this translation helpful? Give feedback.
-
I'm not sure we're going to get an answer any time soon. On the other hand, I don't want to add |
Beta Was this translation helpful? Give feedback.
-
Yeah, you could leverage the new API conventions but your point still stands. There would be exceptions. https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/conventions?view=aspnetcore-3.1 |
Beta Was this translation helpful? Give feedback.
-
Which project template is the issue about?
API
...
Which version of the project template is the issue about?
...
Which version of Visual Studio or the dotnet SDK were you using?
2.2.203
...
If you call the API with a client and you set Accept to
application/json
it is completely ignored and you will ALWAYS getapplication/vnd.restful+json
back.Is this desired? This does not seem like it should be that way.
https://github.com/Dotnet-Boxed/Templates/blob/master/Source/Content/ApiTemplate/Source/ApiTemplate/MvcCoreBuilderExtensions.cs#L94
Beta Was this translation helpful? Give feedback.
All reactions