Verified Commit 84b9750e authored by Dan Jones's avatar Dan Jones
Browse files

feat: downgrade geojson to 3.0.x compatible schema

This allows us to include Feature and FeatureCollection
We probably don't need FeatureCollection for now at least
We do need Feature since the primitive list will
contain a list of features of varied geometries
parent 8e9a8b4c
1 merge request!31Resolve "Test validating messages with references to GeoJson schema in both JS and python"
Pipeline #229881 passed with stages
in 1 minute and 31 seconds
......@@ -162,6 +162,35 @@ def nested_replace(source, key, value, replace_with):
nested_replace(v, key, value, replace_with)
def downgrade_schema_30x_compatible(schema):
"""
The published GeoJSON schemas are OpenAPI v3.1
Moving to v3.1 is not trivial
There isn't a CommonJS validator for v3.1
There isn't a python source of the v3.0.x defs
Remove $id and $schema
Remove oneOf: [{type:null}]
Iterate over oneOf and items child schemas
"""
if "$id" in schema:
del schema["$id"]
if "$schema" in schema:
del schema["$schema"]
if "properties" in schema:
for propConfig in schema["properties"].values():
if "oneOf" in propConfig:
try:
propConfig["oneOf"].remove({"type": "null"})
except ValueError:
pass
for child_schema in propConfig["oneOf"]:
downgrade_schema_30x_compatible(child_schema)
if "items" in propConfig:
downgrade_schema_30x_compatible(propConfig["items"])
def inject_schema(schema, remote_ref):
"""
Given a parent schema and a remote ref
......@@ -171,14 +200,12 @@ def inject_schema(schema, remote_ref):
3. insert into components.schemas
4. replace remote references with local references
returns True if resolved and injected
"""
local_name = rename_ref(remote_ref)
local_ref = f"#/components/schemas/{local_name}"
ref_schema = resolve_ref(remote_ref)
del ref_schema["$id"]
del ref_schema["$schema"]
downgrade_schema_30x_compatible(ref_schema)
if ref_schema is not None:
nested_replace(schema, "$ref", remote_ref, local_ref)
schema["components"]["schemas"][local_name] = ref_schema
......@@ -198,8 +225,8 @@ def import_remote_refs(swagger_config):
# makes the schema fail to validate
ref_imports = [
# "https://geojson.org/schema/Feature.json",
# "https://geojson.org/schema/FeatureCollection.json",
"https://geojson.org/schema/FeatureCollection.json",
"https://geojson.org/schema/Feature.json",
"https://geojson.org/schema/LineString.json",
"https://geojson.org/schema/MultiLineString.json",
"https://geojson.org/schema/MultiPoint.json",
......@@ -316,7 +343,7 @@ def get_options():
args = parser.parse_args()
config = vars(args)
# If no flag is specified default to running the flask server
if not (config['run_flask'] or config['output_file']):
if not (config["run_flask"] or config["output_file"]):
config["run_flask"] = True
return config
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment