Skip to content

How can I add a title and description to an enum's tag key? #492

@ya7010

Description

@ya7010

Thanks for the great crate!

I have the following code.

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(tag = "key")]
#[serde(rename_all = "kebab-case")]
#[derive(schemars::JsonSchema)]
pub enum DataSource {
    /// Format Key?
    Format(FormatInfo),

    /// Lint Key?
    Lint(LintInfo),
}

/// Format Information
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(schemars::JsonSchema)]
pub struct FormatInfo {
    includes: Vec<String>,
    excludes: Vec<String>,
}

/// Lint Information
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(schemars::JsonSchema)]
pub struct LintInfo {
    includes: Vec<String>,
    excludes: Vec<String>,
}

Output Schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "DataSource",
  "oneOf": [
    {
      "description": "Format Key?",
      "type": "object",
      "properties": {
        "key": {
          // I want to "title" and "description" here
          "type": "string",
          "const": "format"
        }
      },
      "$ref": "#/$defs/FormatInfo",
      "required": [
        "key"
      ]
    },
    {
      "description": "Lint Key?",
      "type": "object",
      "properties": {
        "key": {
          // I want to "title" and "description" here
          "type": "string",
          "const": "lint"
        }
      },
      "$ref": "#/$defs/LintInfo",
      "required": [
        "key"
      ]
    }
  ],
  "$defs": {
    "FormatInfo": {
      "description": "Format Information",
      "type": "object",
      "properties": {
        "excludes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "includes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "includes",
        "excludes"
      ]
    },
    "LintInfo": {
      "description": "Lint Information",
      "type": "object",
      "properties": {
        "excludes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "includes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "includes",
        "excludes"
      ]
    }
  }
}

Is there a way to add title and description properties to the "key" property?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions