Open fubar-coder opened 6 years ago
I have the same problem in the latest version.
I solve the problem by use custom optionprocess.
public class ConsumesSwaggerOperationProcessorAttribute : SwaggerOperationProcessorAttribute
{
/// <summary>
///
/// </summary>
/// <param name="comsues"></param>
public ConsumesSwaggerOperationProcessorAttribute(params string[] comsues)
: base(typeof(ReDocCodeSampleAppender), comsues)
{
}
internal class ReDocCodeSampleAppender : IOperationProcessor
{
private readonly string[] _comsues;
public ReDocCodeSampleAppender(params string[] comsues)
{
_comsues = comsues;
}
public Task<bool> ProcessAsync(OperationProcessorContext context)
{
var currentConsumes = context.OperationDescription.Operation.Consumes;
if (currentConsumes == null)
{
currentConsumes = new List<string>();
context.OperationDescription.Operation.Consumes = currentConsumes;
}
_comsues.ToList().ForEach(
comsue =>
{
currentConsumes.Add(comsue);
}
);
return Task.FromResult(true);
}
}
}
and use it like :
[ConsumesSwaggerOperationProcessorAttribute("application/x-www-form-urlencoded")]
public NetResponse<User> Login([FromForm]UserAuthType authType, [FromForm]string identifier, [FromForm]string credential)
{
xxx
}
But i think that if NSwag identifer the .net core 's native
[Consumes("application/x-www-form-urlencoded", "application/json")]
and automtic add to the option's comsue.It will be cool and useful.
I think the new AspNetCoreToSwaggerGenerator supports that (whereas the WebApiToSwaggerGenerator may not support this ConsumesAttribute)… Are you using the new generator?
Hmm, this looks like a processor for the new generator...
I have an API function that accepts two parameters from a content of type
application/x-www-form-urlencoded
. NSwag correctly recognizes it asformData
, but it sets the content type toapplication/json-patch+json
while still sending the properties as form data.I tried to set acceptable content type with
Consumes("application/x-www-form-urlencoded")
, but it seems that it gets ignored by NSwag.