首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swashbuckle.AspNetCore必填查询字符串参数

Swashbuckle.AspNetCore必填查询字符串参数
EN

Stack Overflow用户
提问于 2019-05-17 20:39:20
回答 2查看 2.9K关注 0票数 7

我有一个带有Swashbuckle.AspNetCore包的ASP.NET Corev2.1项目。我的代码是:

代码语言:javascript
复制
    /// <summary>
    /// Set new android token for the current driver
    /// </summary>
    /// <remarks>
    /// Sample request:
    ///
    ///     PUT /SetToken?token=new_token
    ///
    /// </remarks>
    /// <param name="token">can't be null or empty</param>
    /// <returns></returns>
    /// <response code="204">If executed successfully</response>
    /// <response code="400">if token is null or empty</response>  
    /// <response code="404">if user is not a driver; if driver is not found (removed etc); if user does not have a profile</response>  
    [ProducesResponseType(204)]
    [ProducesResponseType(400)]
    [ProducesResponseType(404)]
    [HttpPut]
    [Route("SetToken")]
    [UserIsNotDriverException]
    [NullReferenceException]
    [DriverWithoutProfileException]
    public async Task<IActionResult> SetToken([FromQuery]string token)
    {

我想根据需要标记查询参数。我该怎么做呢?请注意,我在查询字符串中传递参数,而不是在主体中传递参数等

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-17 20:49:34

您可以将BindRequired属性添加到参数中。

代码语言:javascript
复制
public async Task<IActionResult> SetToken([FromQuery, BindRequired]string token)
票数 17
EN

Stack Overflow用户

发布于 2019-10-30 01:48:04

你可以这样做。

代码语言:javascript
复制
public async Task<IActionResult> SetToken([FromQuery, SwaggerParameter("Token Description", Required = True)]string token)

使用这个库Swashbuckle.AspNetCore.Annotations会有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56186603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档