iptc / newsinjson

Home of the IPTC ninjs standard
https://iptc.org/standards/ninjs/
Other
35 stars 9 forks source link

Handling geojson validation issue in 2.0 #124

Closed bquinn closed 2 years ago

bquinn commented 2 years ago

We have a problem with ninjs 2.0 whereby the geojson validation doesn't work properly.

Currently we set additionalProperties in the wrong place here:

        "places": {
            "title": "Places",
            "description": "An array of named locations. nar:subject",
            "additionalProperties": false,   # this doesn't do anything
            "type": "array",
            "items": {
                "type": "object",
                "anyOf": [
                    {
                        "properties": {
                            "name": {
                                "title": "Name",
                                "description": "The name of the place",
                                "type": "string"
                            },
                            "rel": {
                                "title": "Relationship",
                                "description": "The relationship of the content of the news object to the place",
                                "type": "string"
                            },
                            "uri": {
                                "title": "URI",
                                "description": "The identifier for the place as a complete uri",
                                "type": "string",
                                "format": "uri"
                            },
                            "literal": {
                                "title": "Literal",
                                "description": "The code for the place as a literal",
                                "type": "string"
                            }
                        }
                       # we should be setting additionalProperties: true here to make it work
                    },
                    {"$ref": "https://json.schemastore.org/geojson"} 
                ]
            }
        },

Because this additionalProperties line is set in the wrong place, it means that any property is allowed in a "places" object.

We have two options:

Option 1: We can add additionalProperties: true in the place indicated above, which would allow geoJSON properties to be inter-mixed with the defined name, rel, uri and literal properties that we define in the schema.

So a valid instance would look like this:

"places": [
  {
     "name": "London, UK",
     "rel": "mentioned",
    "type": "Point",
    "coordinates": [ 51.509865, -0.118092 ]
 },
 {
    "name": "Paris, France",
    "rel": "describes",
    "type": "Polygon",
    "coordinates": [0.0, 0.1, 0.2, 0.3]
  }
]

Pros:

Option 2: Add a new property as a child in the places array object

So the schema would look like this:

        "places": {
            "title": "Places",
            "description": "An array of named locations. nar:subject", 
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "title": "Name",
                        "description": "The name of the place",
                        "type": "string"
                    },
                    "rel": {
                        "title": "Relationship",
                        "description": "The relationship of the content of the news object to the place",
                        "type": "string"
                    },
                    "uri": {
                        "title": "URI",
                        "description": "The identifier for the place as a complete uri",
                        "type": "string",
                        "format": "uri"
                    },
                    "literal": {
                        "title": "Literal",
                        "description": "An identifier for the place as a free-text string.",
                        "type": "string"
                    },
                    "geojson": {
                        "$ref": "https://json.schemastore.org/geojson"
                    }
                },
                "additionalProperties": false
            }

Pros:

Cons:

Related issues that don't directly affect the decision above:

  1. The geojson schema that we point to is not the latest version. But the new version at https://geojson.org/schema/GeoJSON.json uses JSON Schema draft-07 format, and a draft-04 schema can't include a draft-07 schema, so we can't change the reference without updating our schema to dfraft-07. We can do this in a future version but it will require at least a minor version update, it can't be pushed through as an errata change..
  2. the examples for "places" are incorrect but passed validation due to this bug. So whichever approach we choose, we need to fix the examples accordingly.)
bquinn commented 2 years ago

@iyoung @jolla56 please check and see if this accurately reflects our discussion today...?

jolla56 commented 2 years ago

Yes it does, I did some more testing today because I was afraid that adding geojson as in alternative 1 would force the mandatory properties in geojson, but it seems to be ok. You could further show that, even if we do not suggest such usage, the construction in alt 1 could lead to instances like this:

"places": [ { "name": "London, UK", "rel": "mentioned" }, { "name": "Paris, France", "rel": "describes", "type": "Polygon", "coordinates": [0.0, 0.1, 0.2, 0.3] }, { "type": "Point", "coordinates": [1.45,3.67] } ]

But it then become unclear what the last point refers to.

jolla56 commented 2 years ago

Alternative 2 could be as confusing if not used properly because we do not require any of the first four properties in the place object:

"places": [ { "name": "London, UK", "rel": "mentioned" }, { "name": "Paris, France", "rel": "describes", "geojson": { "type": "Polygon", "coordinates": [0.0, 0.1, 0.2, 0.3] } }, { "geojson": { "type": "Point", "coordinates": [1.45,3.67] } } ]

bquinn commented 2 years ago

fixed in #128