Support multipartformdata mimetype
#819
I am unsure if we want to do this. The original issue is concerned by just the mime type multipart/form-data, but by calling AddFhir() it also affects the mime types application/json and application/xml since we have our own FHIR-specific formatters for these.
The only way I can accept this would be to have it opt-in through an extension method on IServiceCollection. This would also require us to be opt-in on non-FHIR APIs for the mime types application/json and application/xml, and I haven't found a good way for that since you would hit our FHIR formatters for those. Previously my suggestion has been that non-FHIR APIs need to live in a separate web service / application.
If you can find a way for this be opt-in and be able to handle non-FHIR APIs for xml and json I would consider pulling it in.
I'm sorry, I'm not quite sure about your concerns. asp.net Core MVC supports multiple formaters, and the built-in formaters do not affect the FHIR related APIs because they have already been type filtered during formatting. Why not integrate them together? https://github.com/FirelyTeam/spark/blob/1aba3de204f473dc0c67d9088dd43e8fe423fb1d/src/Spark.Engine/Formatters/AsyncResourceJsonInputFormatter.cs#L36-L39 Can you explain in detail the purpose of this design?
There was this issue as well previously: #523
I might be wrong on this and that we can support non-FHIR APIs. We do though need some tests for the support to prove that this works.
multipart/form-dataWe have this as well in the Spark.Web example project which I do not exactly remember why anymore:
https://github.com/FirelyTeam/spark/blob/1aba3de204f473dc0c67d9088dd43e8fe423fb1d/src/Spark.Web/Startup.cs#L115-L116
oh,I saw it,if we need support other model with application/json type,we need keep the origin formatter,and insert our custom formatter on previous,
such as:
if (settings.UseAsynchronousIO)
{
options.InputFormatters.Insert(0, new AsyncResourceJsonInputFormatter(new FhirJsonParser(settings.ParserSettings)));
options.InputFormatters.Insert(1, new AsyncResourceXmlInputFormatter(new FhirXmlParser(settings.ParserSettings)));
options.InputFormatters.Insert(2, new BinaryInputFormatter());
options.OutputFormatters.Insert(0, new AsyncResourceJsonOutputFormatter());
options.OutputFormatters.Insert(1, new AsyncResourceXmlOutputFormatter());
options.OutputFormatters.Insert(2, new BinaryOutputFormatter());
}
else
{
options.InputFormatters.Insert(0, new ResourceJsonInputFormatter(new FhirJsonParser(settings.ParserSettings), ArrayPool<char>.Shared));
options.InputFormatters.Insert(1, new ResourceXmlInputFormatter(new FhirXmlParser(settings.ParserSettings)));
options.InputFormatters.Insert(2, new BinaryInputFormatter());
options.OutputFormatters.Insert(0, new ResourceJsonOutputFormatter());
options.OutputFormatters.Insert(1, new ResourceXmlOutputFormatter());
options.OutputFormatters.Insert(2, new BinaryOutputFormatter());
}
services.AddMvc(options =>
{
// options.InputFormatters.RemoveType<SystemTextJsonInputFormatter>();
// options.OutputFormatters.RemoveType<SystemTextJsonOutputFormatter>();
// We remove StringOutputFormatter to make Swagger happy by not
// showing text/plain in the list of available media types.
// options.OutputFormatters.RemoveType<StringOutputFormatter>();
options.EnableEndpointRouting = false;
});
(...) We do though need some tests for the multipart/form-data support to prove that this works.
@whyfate We need some tests (or proofs) that this works before I will merge it.
like this?
Yes, this is good. I reformatted some of the code,removed the code that was commented out, and added licensing to the new files. Will merge it as soon as CI is finished
Thanks for this! I think you need to recreate your fork, there was a bunch of conflicts that needed to be resolve for this to be merged. You are also deviating on commits in your r4/master branch so your personal fork and this repo is no longer aligned