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

SwaggerHub Mock Server使用externalValue返回406错误,咨询问题原因

在SwaggerHub模拟服务器使用example的externalValue属性时收到406 Not Acceptable响应

我在SwaggerHub模拟服务器中尝试使用example对象的externalValue属性时,收到了406 Not Acceptable响应。请问是我的操作存在错误,还是该功能在SwaggerHub模拟服务器中尚未实现?

API代码片段

paths:
  /test:
    get:
      responses:
        "200":
          description: OK!
          content:
            application/json:
              schema:
                type: string
                format: binary
              examples:
                example:
                  externalValue: "https://jsonplaceholder.typicode.com/todos/1"
            application/pdf:
              schema:
                type: string
                format: binary
              examples:
                sampleFile:
                  externalValue: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"

Postman调用请求截图

Postman调用请求截图

OpenAPI文档参考

参考了OpenAPI规范中关于examples的externalValue属性相关内容


你的OpenAPI语法本身符合规范,externalValue的使用方式没问题,也针对JSON和PDF格式的响应正确指定了外部资源URL。从Postman截图来看,请求的Accept头包含application/json,和API定义的响应格式匹配,操作上没有语法错误。

核心问题是:SwaggerHub自带的模拟服务器(Auto Mocking)目前不支持examples对象的externalValue属性。

SwaggerHub模拟服务器仅能处理内联的example值(直接在example字段写入具体内容),不会主动抓取externalValue指向的外部URL资源并返回给请求方。当配置externalValue后,模拟服务器无法正确处理这个外部引用,导致无法生成符合Accept头要求的响应,最终返回406 Not Acceptable错误。

如果需要模拟返回外部资源的内容,可以用这两种方式替代:

  • 把externalValue对应的资源内容直接复制到example字段中(改用内联示例)
  • 使用自定义Mock服务器(比如WireMock、Postman Mock Server等),自行实现抓取外部URL并返回的逻辑

内容的提问来源于stack exchange,提问作者Martin Šimeček

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 08:15:43