{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/5173","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/5173/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/5173/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/5173/events","html_url":"https://github.com/aspnet/Mvc/issues/5173","id":172547909,"number":5173,"title":"InputFormatter, OutputFormatter, and IApiRequestMetadata","user":{"login":"tuespetre","id":4853540,"avatar_url":"https://avatars.githubusercontent.com/u/4853540?v=3","gravatar_id":"","url":"https://api.github.com/users/tuespetre","html_url":"https://github.com/tuespetre","followers_url":"https://api.github.com/users/tuespetre/followers","following_url":"https://api.github.com/users/tuespetre/following{/other_user}","gists_url":"https://api.github.com/users/tuespetre/gists{/gist_id}","starred_url":"https://api.github.com/users/tuespetre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tuespetre/subscriptions","organizations_url":"https://api.github.com/users/tuespetre/orgs","repos_url":"https://api.github.com/users/tuespetre/repos","events_url":"https://api.github.com/users/tuespetre/events{/privacy}","received_events_url":"https://api.github.com/users/tuespetre/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-22T20:33:29Z","updated_at":"2016-08-23T17:58:11Z","closed_at":null,"body":"I've been having some difficulty with these APIs when trying to use some custom media types.\r\n\r\nHere's a recap:\r\n\r\n- **InputFormatter**\r\n  - **CanRead**\r\n    `if (parsedContentType.IsSubsetOf(supportedMediaType))` (https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Formatters/InputFormatter.cs#L78)\r\n  - **GetSupportedContentTypes**\r\n    `if (parsedMediaType.IsSubsetOf(parsedContentType))` (https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Formatters/InputFormatter.cs#L153)\r\n- **OutputFormatter**\r\n  - **GetSupportedContentTypes**\r\n    `if (parsedMediaType.IsSubsetOf(parsedContentType))` (https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Formatters/OutputFormatter.cs#L69)\r\n  - **CanWriteResult**\r\n    `if (supportedMediaType.IsSubsetOf(parsedContentType))` (https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Formatters/OutputFormatter.cs#L122)\r\n\r\nBasically, the `InputFormatter` is liberal in what in can read because of `CanRead`, but when the time comes to use Api Explorer, the custom media type from the `Consumes` attribute does not show up because of `GetSupportedContentTypes`. Meanwhile, the `OutputFormatter` is very conservative and requires developers to either add every possible permutation of a custom media type to `SupportedMediaTypes` in order for it to allow it, or re-implement each formatter (XML, JSON) they wish to use with the custom media type (of course by inheriting and overriding the relevant methods.)\r\n\r\nSince the `InputFormatter` will say it `CanRead` _subsets_, I propose that `GetSupportedContentTypes` be modified to include the supplied content type in the `results` list when the supplied content type is a subset of a supported media type. I'm not sure about the `OutputFormatter`, I feel like there may be a good reason I'm not seeing for its current behavior. But for reference, to get around it, I've had to create a custom `OutputFormatter` that extends `JsonOutputFormatter`, which needs an `ArrayPool<char>` and `IOptions<MvcJsonOptions>`, and because formatters are registered on `MvcOptions`, I've also had to declare an `IConfigureOptions<MvcOptions>` class in order to get it all registered... kind of clunky.\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/241819083","html_url":"https://github.com/aspnet/Mvc/issues/5173#issuecomment-241819083","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/5173","id":241819083,"user":{"login":"dougbu","id":6431421,"avatar_url":"https://avatars.githubusercontent.com/u/6431421?v=3","gravatar_id":"","url":"https://api.github.com/users/dougbu","html_url":"https://github.com/dougbu","followers_url":"https://api.github.com/users/dougbu/followers","following_url":"https://api.github.com/users/dougbu/following{/other_user}","gists_url":"https://api.github.com/users/dougbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dougbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougbu/subscriptions","organizations_url":"https://api.github.com/users/dougbu/orgs","repos_url":"https://api.github.com/users/dougbu/repos","events_url":"https://api.github.com/users/dougbu/events{/privacy}","received_events_url":"https://api.github.com/users/dougbu/received_events","type":"User","site_admin":false},"created_at":"2016-08-23T17:58:11Z","updated_at":"2016-08-23T17:58:11Z","body":"The `InputFormatter` logic should amount to \"can this formatter read this media type i.e. is the given media type a subset of something the formatter can handle?\" And the `OutputFormatter` should check \"can this formatter write this media type i.e. can the formatter handle something that's a subset of the given media type?\"\r\n\r\nI haven't looked at the current code that closely but I suspect `InputFormatter.GetSupportedContentTypes()` contains a bug. Would of course be easier to see if `parsedMediaType` were named `supportedMediaType` in both `GetSupportedContentTypes()` methods :smiley_cat:.\r\n\r\n/cc @rynowak "}}
{"actor":{"display_login":"dougbu"}}