jiro4989 / nimjson

nimjson generates nim object definitions from json documents.
https://jiro4989.github.io/nimjson/nimjson.html
MIT License
52 stars 5 forks source link

does not honor definitions spec #42

Open vetsin opened 8 months ago

vetsin commented 8 months ago

reference: https://opis.io/json-schema/2.x/definitions.html

currently #/$defs is expected, as literal, when the spec states $defs or definitions is valid. But even more specifically it states any name is valid, ergo it should be looked up instead.

jiro4989 commented 8 months ago

Thank you. Maybe this part?

In drafts 06 and 07 $defs keyword was named definitions, this has changed starting with draft 2019-09. Don’t worry, definitions can still be used (you can use any name, it doesn’t really matter).

I will think about how to fix it.

jiro4989 commented 8 months ago

Certainly other JSON Schema Validators behave that way too. https://www.jsonschemavalidator.net/

image

{
  "type": "object",
  "properties": {
    "username": {"$ref": "#/foobar/custom-username"},
    "aliases": {
      "type": "array",
      "items": {"$ref": "#/foobar/custom-username"}
    },
    "primary_email": {"$ref": "#/foobar/custom-email"},
    "other_emails": {
      "type": "array",
      "items": {"$ref": "#/foobar/custom-email"}
    }
  },

  "foobar": {
    "custom-username": {
      "type": "string",
      "minLength":3
    },
    "custom-email": {
      "type": "string",
      "format": "email",
      "pattern": "\\.com$"
    }
  }
}