是否可以将System.IO.Stream作为Swagger的输入参数?

时间:2018-12-11 07:59:26

标签: asp.net stream swagger swagger-ui

我们在项目中使用了swagger(v 2.0),并且其中一个ASP.NET API控制器具有接收[FromBody] System.IO.Stream的功能。但是,当我启动swagger ui时,UI会建议某些内容,在使用和调试时,该流始终为null。在线研究时,我看到许多其他人都使用IFromFile,但这似乎是.NET Core专有的。

是我想做的可能还是应该尝试其他事情? 预先感谢。

当前使用的代码:

    /// <summary>
    /// Store the photo of the object.
    /// </summary>
    /// <remarks>Registers the given object photo that was captured through scanning. </remarks>
    /// <param name="barcode">Barcode of the scanned object </param>
    /// <param name="lang">Language in which the request should be processed, if possible (e.g., for object information retrieval and status message construction).  This is the MD Connect GUI’s language. Expressed as a LanguageCode (see Definitions). </param>
    /// <param name="photo"></param>
    /// <response code="201">The captured object photo was successfully registered.</response>
    /// <response code="400">Bad Request</response>
    /// <response code="500">Internal Server Error</response>
    [HttpPost]
    [Route("api/logistore/multiscan/scanhandler/v1/objects/{barcode}/scan/photos")]
    [SwaggerOperation("RegisterCapturedObjectPhoto")]
    [SwaggerResponse(200, type: typeof(HttpStatusCode))]
    [SwaggerResponse(201, type: typeof(HttpStatusCode))]
    [SwaggerResponse(400, type: typeof(ErrorResult))]
    [SwaggerResponse(500, type: typeof(ErrorResult))]
    public IHttpActionResult RegisterCapturedObjectPhoto([FromUri]string barcode, [FromUri]string lang, [FromBody]System.IO.Stream photo)
    {
        if (string.IsNullOrWhiteSpace(barcode))
        {
            throw new RestException(HttpStatusCode.BadRequest, "UNKNOWN_BARCODE", "Unknown barcode / Onbekende barcode: Barcode cannot be empty.");
        }

        if (photo == null)
        {
            throw new RestException(HttpStatusCode.BadRequest, "INVALID_PHOTO", "Invalid photo / Ongeldige foto: Invalid input for photo received.");
        }

        return Content(HttpStatusCode.Created, "The captured object photo was successfully registered.");
    }

Swagger UI建议:

The swagger UI suggestion

0 个答案:

没有答案