2017-09-13 73 views
0

我有一個終端產生媒體類型作爲application/octet-stream。然而,當我生成了swagger json時,它將「produce」指定爲「application/json」 我沒有在swagger中做任何特殊的配置。我所做的只是導入swagger nuget,並保持默認配置。 請找到端點以下: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); 
    } 

而且jsonSchema從招搖:

"/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" 
      } 
     } 
    } 
} 

}

+0

這可能是[有益](https://stackoverflow.com/questions/34990291/swashbuckle-swagger- how-to-annotate-content-types) –

+0

非常感謝Ivan爲我指出了正確的職位。對不起,我錯過了,可能重複了這個問題。不管怎麼說,還是要謝謝你。它有幫助。 – Rajagopal

回答

相關問題