首页 > 解决方案 > 当输入是原始Json时,C#如何让大摇大摆地工作?

问题描述

在 C# 中,当 API 读取原始 JSON 时,我如何让 swagger 文档工作?目前正如预期的那样,它认为 API 不接受任何输入。

我正在使用 Swashbuckle.AspNetCore nuget 包。有没有办法添加注释以显示带有类型的参数,以便生成的文件具有正确的信息?

    [HttpPost]

    public async Task<ActionResult<int>> Process()
    {
        string jsonString = await GetRequestBody();
         ...
    }

    private async Task<string> GetRequestBody()
    {
        string jsonString;
        using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
        {
            jsonString = await reader.ReadToEndAsync();
        }

        return jsonString;
    }

标签: c#swagger

解决方案


推荐阅读