Skip to content

BUG - Song does not merge definitions from uploaded schemas #876

@pvanheus

Description

@pvanheus

If an uploaded schema contains a "definitions" section, this will be ignored when the schema is uploaded to Song. E.g.

{
    "name": "cholgen_sequence",
    "schema": {
        "type": "object",
        "definitions": {
            "species": {
                "type": "string",
                "enum": [
                    "Bos taurus",
                    "Homo sapiens"
                ]
            }
        },
        "properties": {
            "host": {
                "$ref": "#/definitions/species"
            }
        }
    }
}

The "definitions" section of this will be ignored, instead only the "definitions" from analysisBase.json will be included in the final rendered schema, resulting in an invalid schema.

Description

As mentioned above, the end result is an invalid schema. When this is used in production, an error occurs - see this trace. This trace was produced by trying to use this schema.

While sometimes the use of "definitions" can be avoided (e.g. in a later version of the schema mentioned above), this is often a useful features of JSON-Schema.

Expected Behaviour

The "definitions" section of schema should be merged with that of the analysisBase.json.

Actual Behaviour

As mentioned above, the contents of the "definitions" part of an uploaded schema is silently ignored.

Possible Fix

I think that the relevant code that merges schemas is in renderPayloadJsonSchema. This could be extended to merge "definitions" much as "properties" are currently merged.

Steps to Reproduce

  1. Upload the schema mentioned above in the description
  2. Try and upload a JSON document compliant with the schema

Your Environment

  • Version used: 5.2.0
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Not relevant
  • Operating System and version (desktop or mobile): Upload was done using Muse
  • Link to your project: https://github.com/african-pathogen-archive

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions