elixir-europe / biovalidator

JSON validator derived from AJV supporting ontology and taxonomy validation.
Apache License 2.0
20 stars 6 forks source link

[BUG]: Biovalidator can't detect local schema ID - "Empty schema `$id`" #74

Open M-casado opened 4 months ago

M-casado commented 4 months ago

Bug summary

Biovalidator complains about an empty $id in a local schema with a proper $id

Technical details

To reproduce

  1. Create a simple JSON Schema with a $id field as follows:
    {
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "$id": "https://raw.githubusercontent.com/EbiEga/ega-metadata-schema/main/schemas/test.json",
    "type": "object",
    "$async": true,
    "required": ["test" ],
    "additionalProperties": false,
    "properties": {
      "test": {
        "type": "string",
        "enum": ["test"]
      }
    }      
    }
  2. Try to compile the schema using -r at launch of a Biovalidator server:
    $ node biovalidator -r "schema_test/test.json"
    2024-06-24T16:29:42.041Z [info] Custom keywords successfully added. Number of custom keywords: 5
    2024-06-24T16:29:42.042Z [info] Compiling local schema from: schema_test/test.json
    2024-06-24T16:29:42.048Z [info] Adding compiled local schema to cache: https://raw.githubusercontent.com/EbiEga/ega-metadata-schema/main/schemas/test.json
    2024-06-24T16:29:42.090Z [info] ---------------------------------------------
    2024-06-24T16:29:42.090Z [info] ------------ ELIXIR biovalidator ------------
    2024-06-24T16:29:42.091Z [info] ---------------------------------------------
    2024-06-24T16:29:42.091Z [info] Started server on port 3020 with base URL /
    2024-06-24T16:29:42.091Z [info] Server available at http://localhost:3020/
    2024-06-24T16:29:42.091Z [info] PID file is available at /mnt/c/Users/mcasado/Documents/GitHub/biovalidator/src/server.pid
    2024-06-24T16:29:42.092Z [info] Writing logs to: /mnt/c/Users/mcasado/Documents/GitHub/biovalidator/src/logs/
  3. Create a simple JSON document as follows. Notice how the referenced $id is the same as the one in the schema file.
    {
    "data": {
        "test": "test"
    },
    "schema": {
        "$ref": "https://raw.githubusercontent.com/EbiEga/ega-metadata-schema/main/schemas/test.json"
    }
    }
  4. Execute the validation request:
    $ curl --data @test_doc.json -H "Content-Type: application/json" -X POST "http://localhost:3020/validate"
  5. Observe the logs from Biovalidator, displaying a warning about an empty schema $id and that it won't be cached.
    2024-06-24T16:29:48.622Z [warn] Compiling schema with empty schema $id. Schema will not be cached.
    2024-06-24T16:29:48.646Z [info] Returning referenced schema from cache: https://raw.githubusercontent.com/EbiEga/ega-metadata-schema/main/schemas/test.json
    2024-06-24T16:29:48.649Z [info] New validation request: Processed successfully in 28ms.

Observed behaviour

Biovalidator complains about an empty schema $id. Error message sources from: https://github.com/elixir-europe/biovalidator/blob/d8fd80517f1df7621a3b7a4d0deada2a8ed4a186/src/core/biovalidator-core.js#L145

Expected behaviour

The schema's $id should be identified without a warning. It is retrieved successfully from cache and used for validation, but the warning seems misleading.

Additional context

No response