opis/json-schema

Accessing mapping discriminator from Schema

ivanwilliammd opened this issue · 1 comments

Dear all, I'm currently using schema downloaded here :

https://hl7.org/fhir/R4/fhir.schema.json.zip

Suppose that I would like to validate against Encounter
Is this the correct code for that

    public function validation($request)
    {
        $validator = new Validator();
        $validator->resolver()->registerFile(
            'http://hl7.org/fhir/json-schema/4.0#/definitions/' . $this->resourceType,
            base_path('schema/fhir.schema.json')
        );

        $result = $validator->validate(
            $request->all(),
            'http://hl7.org/fhir/json-schema/4.0#/definitions/' . $this->resourceType
        );

        if ($result->isValid()) {
           return null;
        } else {
            // Print errors
            return (new ErrorFormatter())->format($result->error());
        }
    }

Since up until now it keep showing an error like this

{
    "message": "Method Illuminate\\Http\\Request::validated does not exist.",
    "exception": "BadMethodCallException",

Really appreciate and thankful for any help. Thanks

After some tweaking, there are no further error... However, it seems to be not validated.

The newer code

public function validation($request)
    {
        $validator = new Validator();

        // $schema = file_get_contents(base_path('schema\fhir.schema.json'));
        // print_r($schema);

        $validator->resolver()->registerFile(
            'http://hl7.org/fhir/json-schema/4.0',
            base_path('schema\fhir.schema.json')
        );

        $result = $validator->validate(
            $request->all(),
            'http://hl7.org/fhir/json-schema/4.0#/definitions/' . $this->resourceType
        );

        print_r($result);

        if ($result->isValid()) {
           return null;
        } else {
            // Print errors
            print_r ($result->error());
        }
    }

Is it correct that to access the schema discriminators we must add it to the path?