davishmcclurg/json_schemer

i18n custom error messages are not resolved

Closed this issue ยท 3 comments

Hello ๐Ÿ‘‹,

i have the following schema:

{
  "definitions": {
    "GeolocationDto": {
      "$id": "geolocation_dto",
      "type": "object",
      "properties": {
        "latitude": {
          "type": "number"
        },
        "longitude": {
          "type": "number"
        }
      },
      "required": ["latitude", "longitude"]
    }
  },
  "oneOf": [
    {
      "$id": "geofence_circle",
      "type": "object",
      "properties": {
        "center": {
          "$ref": "geolocation_dto"
        },
        "radius": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "required": ["radius", "center"]
    },
    ...
  ]
}

As documented in the readme, the i18n definition should be the following:

en:
  json_schemer:
    errors:
      'geolocation_dto#/required': 'You must provide a valid geolocation having a longitude and latitude.'
      'geofence_circle#/properties/center/required': 'You must provide a valid geolocation having a longitude and latitude.'

But both does not work. I already get the default error "missing_keys: latitude, longitude", if i pass eg. a json having a geofence_circle with an empty center.

Can you please help me and tell me what i am doing wrong? Could this be a problem with the "oneOf" keyword here?

Thank you ๐Ÿ™‚

Try prefixing your schema IDs with json-schemer:// eg: json-schemer://geolocation_dto#/required. $id values are meant to be absolute and are prefixed like that when they're not.

I'll double check when I'm at a computer, but if that doesn't work try: json-schemer://schema/geolocation_dto#/required.

I think you want json-schemer://schema/geolocation_dto#/required

Thank you very much ๐Ÿ™.

Prefixing the schemas with json-schemer:// works.

I would recommend to explain this in the readme, hence other users may not have the same Problem ๐Ÿ™‚.