You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swashbuckle.AspNetCore 6.5.0中Swagger UI路径参数viewtype未替换问题

问题诊断与解决

核心原因

路径模板中的参数名{viewtype}和OpenAPI参数定义里的name: "viewType"大小写不匹配,Swagger UI无法关联这两个参数,导致输入的viewtype值无法替换路径占位符。

解决步骤

  1. 统一参数名大小写:将路径模板中的{viewtype}改为{viewType},保持和参数定义里的name一致。修改后的完整路径定义如下:
"/api/widget/{viewType}/{widgetGuid}": {
    "get": {
        "tags": [
            "widget"
        ],
        "parameters": [
            {
                "name": "viewType",
                "in": "path",
                "required": true,
                "schema": {
                    "type": "string"
                }
            },
            {
                "name": "widgetGuid",
                "in": "path",
                "required": true,
                "schema": {
                    "type": "string",
                    "format": "uuid"
                }
            }
        ],
        "responses": {
            "200": {
                "description": "Success",
                "content": {
                    "text/plain": {
                        "schema": {
                            "$ref": "#/components/schemas/widgetDtoFull"
                        }
                    },
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/widgetDtoFull"
                        }
                    },
                    "text/json": {
                        "schema": {
                            "$ref": "#/components/schemas/widgetDtoFull"
                        }
                    }
                }
            }
        }
    }
}
  1. 同步后端路由配置:确保ASP.NET Core后端的路由模板也使用viewType(例如[Route("api/widget/{viewType}/{widgetGuid}")]),保持前后端参数名大小写完全一致。
  2. 验证修复效果:重启应用后重新打开Swagger UI,输入viewType=full和widgetGuid=940FFD66-A7C2-42F5-AAA2-153CBF9136EE,确认生成的请求URL为https://localhost:7168/api/widget/full/940FFD66-A7C2-42F5-AAA2-153CBF9136EE。

内容的提问来源于stack exchange,提问作者user195166

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 21:57:09