Ich habe einen Endpunkt, der mediatype als application/octet-stream erzeugt. Jedoch, wenn ich den swagger json generierte, spezifiziert es "produziert" als "application/json" Ich habe keine speziellen Konfigurationen in swagger getan. Alles, was ich tat, war Swagger-nugget zu importieren und behielt nur die Standardkonfiguration wie sie ist. finden Sie unter dem Endpunkt:swashbuckle mediatype application/octetstream
[HttpPost]
[Route("document/method1")]
public HttpResponseMessage method1([FromBody]SomeModel SomeModelValue)
{
// code that generates the file
if (File.Exists(outputFilePath))
{
byte[] resultFile = File.ReadAllBytes(outputFilePath);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created);
response.Content = new ByteArrayContent(ResultFile);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(ContentDispositionHeaderValue);
response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeHeaderValue);
response.Content.Headers.ContentLength = ResultFile.Length;
File.Delete(inputFilePath);
File.Delete(outputFilePath);
return response;
}
else
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}
Und die jsonSchema von Prahlerei:
"/document/method1": {
"post": {
"tags": ["Document"],
"operationId": "Document_Method1",
"consumes": ["application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"],
"produces": ["application/json", "text/json", "application/xml", "text/xml"],
"parameters": [{
"name": "SomeModelValue",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SomeModel"
}
}],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
}
}
Es könnte sein [hilfreich] (https://stackoverflow.com/questions/34990291/swashbuckle-swagger- How-to-Annotate-Content-Typen) –
Vielen Dank Ivan für mich auf den richtigen Beitrag. Tut mir leid, ich habe es verpasst und möglicherweise die Frage dupliziert. Danke trotzdem. Es half. – Rajagopal