Default `#[schemars(deny_unknown_fields)] for json-language-server schemas (#33883)

Followup to #33678, doing the same thing for all JSON Schema files
provided to json-language-server

Release Notes:

* Added warnings for unknown fields when editing `tasks.json` /
`snippets.json`.
This commit is contained in:
Michael Sloan 2025-07-03 18:57:43 -06:00 committed by GitHub
parent 38544e514a
commit ed7552d3e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 136 additions and 149 deletions

View file

@ -1,10 +1,8 @@
use anyhow::Result;
use gpui::SharedString;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::json;
/// Represents a schema for a specific adapter
/// JSON schema for a specific adapter
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
pub struct AdapterSchema {
/// The adapter name identifier
@ -16,47 +14,3 @@ pub struct AdapterSchema {
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(transparent)]
pub struct AdapterSchemas(pub Vec<AdapterSchema>);
impl AdapterSchemas {
pub fn generate_json_schema(&self) -> Result<serde_json_lenient::Value> {
let adapter_conditions = self
.0
.iter()
.map(|adapter_schema| {
let adapter_name = adapter_schema.adapter.to_string();
json!({
"if": {
"properties": {
"adapter": { "const": adapter_name }
}
},
"then": adapter_schema.schema
})
})
.collect::<Vec<_>>();
let schema = serde_json_lenient::json!({
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Debug Adapter Configurations",
"description": "Configuration for debug adapters. Schema changes based on the selected adapter.",
"type": "array",
"items": {
"type": "object",
"required": ["adapter", "label"],
"properties": {
"adapter": {
"type": "string",
"description": "The name of the debug adapter"
},
"label": {
"type": "string",
"description": "The name of the debug configuration"
},
},
"allOf": adapter_conditions
}
});
Ok(serde_json_lenient::to_value(schema)?)
}
}