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

如何在monaco-editor的JSON Schema中默认显示描述?

解决方案

针对monaco-editor v0.44.0版本,你可以通过调整编辑器的补全相关配置,让JSON Schema字段的描述默认显示在补全面板中,无需点击「查看更多」。具体配置如下:

核心配置项

初始化编辑器时,在editorOptions中添加以下配置:

const editor = monaco.editor.create(document.getElementById('editor-container'), {
  value: '{}',
  language: 'json',
  // 开启补全预览,默认显示字段描述
  suggest: {
    preview: true,
    showIcons: true
  },
  // 确保快速提示正常触发
  quickSuggestions: {
    strings: true, // JSON字段名处于字符串语境,需开启此项
    other: true
  },
  // 保留你已配置好的JSON Schema
  json: {
    schemas: [
      {
        uri: 'your-schema-uri',
        fileMatch: ['*'],
        schema: {
          type: 'object',
          properties: {
            username: {
              type: 'string',
              description: '用户登录账号,长度不超过20位'
            },
            email: {
              type: 'string',
              description: '用户绑定邮箱,需符合标准格式'
            }
          }
        }
      }
    ]
  }
});

额外优化:光标悬停显示描述

如果希望光标停在已输入的字段名上时也能弹出描述,可以开启hover功能:

hover: {
  enabled: true
}

说明

monaco-editor v0.44.0并没有专门针对JSON Schema描述默认显示的独立API,但通过上述suggest.preview和quickSuggestions的配置,可以让补全面板默认展开显示字段描述。如果配置后仍不生效,需要检查:

  • JSON Schema的description字段是否正确配置,语言服务是否能识别
  • 是否有自定义补全提供者覆盖了默认的JSON补全逻辑

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 02:45:03