sourcemeta/alterschema

Seems to lose `enum` values going from `Draft 7` to `2020-12`

Closed this issue · 7 comments

It seems to me that enum values get lost in translation. Did a quick test with one of our more simple schemas, and every enum gets converted to a const.

This is the schema I've tested with:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://schema.kickstartds.com/base/headline.schema.json",
  "title": "Headline",
  "description": "Headline",
  "type": "object",
  "properties": {
    "level": {
      "title": "Level",
      "description": "Select the headline level to use, or p alternatively",
      "type": "string",
      "enum": ["h1", "h2", "h3", "h4", "h5", "p"],
      "default": "h2"
    },
    "styleAs": {
      "title": "Style",
      "description": "Select the headline style to use",
      "type": "string",
      "enum": ["none", "h1", "h2", "h3", "h4", "h5", "p"],
      "default": "none"
    },
    "align": {
      "title": "Alignment",
      "description": "Choose an alignment for the headline",
      "type": "string",
      "enum": ["left", "center", "right"],
      "default": "center"
    },
    "content": {
      "title": "Text",
      "description": "Text content for the headline",
      "type": "string",
      "default": "Headline"
    },
    "subheadline": {
      "title": "Subheadline",
      "description": "Text content for the optional subheadline",
      "type": "string"
    },
    "spaceAfter": {
      "title": "Bottom spacing",
      "description": "Add additional spacing to the bottom of the headline",
      "type": "string",
      "enum": ["none", "small", "large"],
      "default": "none"
    },
    "pageHeader": {
      "title": "Page header",
      "description": "Set the headline as a page header, triggering special css treatment",
      "type": "boolean",
      "default": false
    },
    "className": {
      "type": "string",
      "title": "Additional Classes",
      "description": "Add additional css classes that should be applied to the headline"
    }
  },
  "required": ["level", "align", "spaceAfter"]
}

Or is there something missing about enum usage, or corresponding schema changes of it?

Hi @julrich ,

Thanks for reporting this. There does indeed seem to be a bug with one of the enum-related transformation rules. Getting into it now!

Found it! Some of the rules were using maxitems instead of maxItems. I'll merge it and issue a release on NPM in a bit

In the mean-time, I'll go through every rule definition to see if I made a similar mistake somewhere else

Done! v1.0.3 should be now on NPM and the web playground will get re-deployed in a bit. Thanks a lot!

I tested your example schema again and its fine now. That schema doesn't hit any breaking change between 2019-09 and 2020-12, so only changing the $schema is enough in this case

Wow, that was quick 🚀. Thanks a lot, will test further and report anything I'll find :)
This will be super useful to us, as we're still sitting on a load of Draft 07 schemas.

Awesome! Happy to help any time!