inveniosoftware / domapping

Package generating elasticsearch mapping from jsonschemas
https://domapping.readthedocs.io
GNU General Public License v2.0
14 stars 8 forks source link

`enum` type support #4

Closed tiborsimko closed 8 years ago

tiborsimko commented 8 years ago

Running domapping on our example MARC21 JSON Schema leads to an error due to unsupported enum:

$ workon domapping
$ cd dojson/contrib/marc21/schemas
$ domapping schema_to_mapping ./bd20x24x.json
[...]
domapping.errors.JsonSchemaSupportError: ERROR Schema has no "type" field 
   IN ./bd20x24x.json/former_title/items/title_added_entry

The corresponding JSON Schema bit:

        "former_title": {
            "description": "Former Title",
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "title_added_entry": {
                        "enum": ["Added entry", "No added entry"]
                    },

Possible techniques on how we could solve this:

nharraud commented 8 years ago

I think providing support for string and numbers without type field is easy enough. Maybe we can add null support as well, I have to check how elasticsearch handles a null on a typed field. However we should force failure for anything else than string and number without specifying the type. Json-schema allows combination of number and strings, and it would be too complicated to guess which type is the valid one (especially with string containing numbers).