Not able to understand ajv validation output for a FHIR resources

I am validating a FHIR resource using ajv.

ajv -s fhir.schema.json -d SampleOperationOutCome.json

This is the SampleOperationOutCome.json file

{
"resourceType": "OperationOutcome",
"id": "101",
"text": {
    "status": "additional",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p>text.<\/p><\/div>"
},
"issue": [
    {
        "severity": "error",
        "codeerror": "invalid",
        "details": {
            "coding": [
                {
                    "system": "http://hl7.org/fhir/operation-outcome",
                    "code": "MSG_CANT_PARSE_CONTENT"
                }
            ],
            "text": "text"
        }
    }
]

}

You can get the json schema from FHIR build 3.4 json schemas

My main challenge when validating is to understand which is really the source issue. For example, in this case I've change de "code" field to "codeerror", but when validating I get mainly a list of the following error:

{ keyword: 'additionalProperties',
dataPath: '',
schemaPath: '#/additionalProperties',
params: { additionalProperty: 'issue' },
message: 'should NOT have additional properties' },

I do know if it is the normal output, or if the source of this behaviour is the json schema or ajv, but I would expect some message like "invalid field codeerror, one of code expected".

Any suggestion in order to be able do analyse the full output and get the real source?

Thanks.

Upvotes: 0

Views: 472

Answers (1)

Relequestual
Relequestual

Reputation: 12315

JSON Schema does not define an output format as of draft-7, so this output (error or otherwise) is defined by the library, in this case ajv.

We (JSON Schema) are currently looking at if we should define a standard output format, currently tracking on a github issue.

In the instance of your error, additional properties false prevents additional properties, so you'll have to check your JSON Schema and the instance for which additional properties you've added. Although in this case, you already know because you're testing.

If you're looking for a way to get this information programatically, there's no standard for doing so.

ajv may provide some additional error information if you ask using it's documented API. It LOOKS like it should be giving you some more information that you've presented, although an empty dataPath may be referencing the root of the JSON instance.

Upvotes: 1

Related Questions