jsonschema_schema/extensions/intellij.rs
1use alloc::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5/// [IntelliJ IDEA] JSON Schema extensions (`x-intellij-*`).
6///
7/// IntelliJ-based IDEs recognise these vendor extensions on any JSON Schema
8/// property to enhance editing, completion, and validation UX. Each key is a
9/// separate top-level property on the schema object, so this struct is
10/// [`#[serde(flatten)]`](https://serde.rs/attr-flatten.html)-ed into
11/// [`Schema`](crate::Schema).
12///
13/// # Keys
14///
15/// | JSON key | Rust field | Purpose |
16/// |---|---|---|
17/// | `x-intellij-html-description` | [`html_description`](Self::html_description) | Rich HTML description for hover/docs |
18/// | `x-intellij-language-injection` | [`language_injection`](Self::language_injection) | Language ID for editor injection |
19/// | `x-intellij-enum-metadata` | [`enum_metadata`](Self::enum_metadata) | Per-enum-value descriptions |
20///
21/// # Example
22///
23/// ```json
24/// {
25/// "type": "string",
26/// "x-intellij-html-description": "<b>Greeting</b> message",
27/// "x-intellij-language-injection": "Shell Script",
28/// "x-intellij-enum-metadata": {
29/// "system": { "description": "Use system default" }
30/// }
31/// }
32/// ```
33///
34/// [IntelliJ IDEA]: https://www.jetbrains.com/help/idea/json.html
35#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
36pub struct IntellijSchemaExt {
37 /// Rich HTML description shown in editor hover popups and documentation
38 /// panels.
39 ///
40 /// Analogous to the [VSCode] [`markdownDescription`] extension but uses
41 /// HTML markup instead of Markdown.
42 ///
43 /// [VSCode]: https://code.visualstudio.com/docs/languages/json
44 /// [`markdownDescription`]: https://code.visualstudio.com/docs/languages/json#_use-rich-formatting-in-hovers
45 #[serde(
46 rename = "x-intellij-html-description",
47 skip_serializing_if = "Option::is_none"
48 )]
49 pub html_description: Option<String>,
50
51 /// Language identifier for [language injection].
52 ///
53 /// When set on a string-typed property, [IntelliJ IDEA] injects syntax
54 /// highlighting and code intelligence for the named language
55 /// (e.g. `"Shell Script"`, `"RegExp"`, `"ini"`).
56 ///
57 /// [IntelliJ IDEA]: https://www.jetbrains.com/help/idea/json.html
58 /// [language injection]: https://www.jetbrains.com/help/idea/language-injections-settings.html
59 #[serde(
60 rename = "x-intellij-language-injection",
61 skip_serializing_if = "Option::is_none"
62 )]
63 pub language_injection: Option<String>,
64
65 /// Per-enum-value metadata, keyed by the enum value string.
66 ///
67 /// Provides additional descriptions for each `enum` value that
68 /// [IntelliJ IDEA](https://www.jetbrains.com/help/idea/json.html)
69 /// surfaces in completion popups and documentation panels.
70 #[serde(
71 rename = "x-intellij-enum-metadata",
72 skip_serializing_if = "Option::is_none"
73 )]
74 pub enum_metadata: Option<BTreeMap<String, EnumValueMeta>>,
75}
76
77/// Metadata for a single enum value in
78/// [`x-intellij-enum-metadata`](IntellijSchemaExt::enum_metadata).
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
80pub struct EnumValueMeta {
81 /// Human-readable description of what this enum value means.
82 #[serde(skip_serializing_if = "Option::is_none")]
83 pub description: Option<String>,
84}