schemars icon indicating copy to clipboard operation
schemars copied to clipboard

The deprecated_enum validates incorrect behavior

Open ahl opened this issue 3 years ago • 0 comments

Here's the rust type checked by the deprecated_enum test:

#[derive(JsonSchema)]
#[deprecated]
enum DeprecatedEnum {
    Unit,
    #[deprecated]
    DeprecatedUnitVariant,
    #[deprecated]
    DeprecatedStructVariant {
        foo: i32,
        #[deprecated]
        deprecated_field: bool,
    },
}

And here's the json output:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "DeprecatedEnum",
  "deprecated": true,
  "oneOf": [
    {
      "type": "string",
      "enum": [
        "Unit",
        "DeprecatedUnitVariant"
      ]
    },
    {
      "deprecated": true,
      "type": "object",
      "required": [
        "DeprecatedStructVariant"
      ],
      "properties": {
        "DeprecatedStructVariant": {
          "type": "object",
          "required": [
            "deprecated_field",
            "foo"
          ],
          "properties": {
            "deprecated_field": {
              "deprecated": true,
              "type": "boolean"
            },
            "foo": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    }
  ]
}

Note that DeprecatedUnitVariant is not marked as deprecated. Here's what we'd expect and the diff:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "DeprecatedEnum",
  "deprecated": true,
  "oneOf": [
    {
      "type": "string",
      "enum": [
        "Unit"
      ]
    },
    {
      "deprecated": true,
      "type": "string",
      "enum": [
        "DeprecatedUnitVariant"
      ]
    },
    {
      "deprecated": true,
      "type": "object",
      "required": [
        "DeprecatedStructVariant"
      ],
      "properties": {
        "DeprecatedStructVariant": {
          "type": "object",
          "required": [
            "deprecated_field",
            "foo"
          ],
          "properties": {
            "deprecated_field": {
              "deprecated": true,
              "type": "boolean"
            },
            "foo": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    }
  ]
@@ -6,7 +6,13 @@
     {
       "type": "string",
       "enum": [
-        "Unit",
+        "Unit"
+      ]
+    },
+    {
+      "deprecated": true,
+      "type": "string",
+      "enum": [
         "DeprecatedUnitVariant"
       ]
     },

ahl avatar Jun 15 '22 17:06 ahl