2017-09-13 9 views
0

私はapplication/octet-streamとしてmediatypeを生成するエンドポイントを持っています。しかし、私がswagger jsonを生成したとき、それは "produce/json"として "produce"を指定します。 私はswaggerで特別な設定をしませんでした。私がしたのは、スウェーガー・ナゲットの輸入でした。 エンドポイントの下に見つけてください:闊歩からswashbuckle mediatypeアプリケーション/オクテットストリーム

[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

私は正しい投稿を指してくれてありがとうございます。申し訳ありませんが、私はそれを逃して、おそらく質問を複製しました。とにかくありがとう。それは助けになった。 – Rajagopal

答えて

関連する問題