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

redoc-cli v0.13.20中Discriminator功能失效问题求助

问题解决:redoc-cli构建OpenAPI 3.1文档时Discriminator功能不生效

可能的原因及解决方法

1. 版本兼容性问题

redoc-cli 0.13.20属于较早版本,对OpenAPI 3.1.0的多态(discriminator)支持不完善。

  • 方案1:升级redoc-cli到最新版本(目前已归为Redocly生态,新版本对OpenAPI 3.1支持更完善),执行命令:
    npm install -g redoc-cli@latest
    
  • 方案2:将OpenAPI文档版本降级到3.0.3,旧版redoc-cli对3.0规范的支持更稳定。

2. 补充Schema的枚举约束

旧版redoc-cli需要明确指定每个子Schema中鉴别器字段的固定值,才能触发选择框功能。修改你的Schema定义:

components:
  schemas:
    test1:
      title: Test
      type: object
      properties:
        testType:
          type: string
          enum: ["ONE"]  # 明确指定对应discriminator的映射值
        testOne:
          type: string
    test2:
      title: Test 2
      type: object
      properties:
        testType:
          type: string
          enum: ["TWO"]  # 明确指定对应discriminator的映射值
        testTwo:
          type: number
    test:
      title: Test Polymorph
      oneOf:
        - $ref: '#/components/schemas/test1'
        - $ref: '#/components/schemas/test2'
      discriminator:
        propertyName: testType
        mapping:
          ONE: '#/components/schemas/test1'
          TWO: '#/components/schemas/test2'

3. 验证文档合规性

检查OpenAPI文档是否存在语法问题,确保discriminator的mapping路径正确,oneOf引用的Schema无拼写错误。

内容的提问来源于stack exchange,提问作者Ondřej Navrátil

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 09:10:37