Open hauntingEcho opened 2 years ago
Is there any update?
@hauntingEcho @maglini
You can try to implement a custom IOperationProcessor
public class OctetStreamProcessor(string parameterName) : IOperationProcessor
{
private const string ApplicationOctetStream = "application/octet-stream";
private const string Format = "byte";
public bool Process(OperationProcessorContext context)
{
ArgumentNullException.ThrowIfNull(context);
context.OperationDescription.Operation.RequestBody = new OpenApiRequestBody
{
Name = parameterName,
Content =
{
[ApplicationOctetStream] = new OpenApiMediaType
{
Schema = new JsonSchema
{
Type = JsonObjectType.String,
Format = Format
}
}
}
};
return true;
}
}
And then use it in your Controller Method:
[OpenApiOperationProcessor(typeof(OctetStreamProcessor), "saveDocumentInput")]
public async Task<IActionResult> Save([FromBody] byte[] saveDocumentInput, [FromQuery] Guid id)
{
// impl...
Then you dont need ConsumeAttribute
or OpenApiBodyParameterAttribute
I'm using the MSBuild & CLI option to generate a static OpenAPI file as part of my build pipeline. For an OAuth2 token endpoint, I need to support an
application/x-www-form-urlencoded
POST body (while the rest of my application usesapplication/json
).My endpoint signature:
The generated requestBody:
The expected requestBody:
Additional info:
Startup.cs
includes anAddNewtonsoftJson