json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

Resolve $ref while walking

Open alturkovic opened this issue 2 years ago • 0 comments

I am trying to find property definitions which are required but do not have a value.

My current attempt:

private class MyCustomWalker : JsonSchemaWalkListener {
    override fun onWalkStart(walkEvent: WalkEvent) = WalkFlow.CONTINUE

    override fun onWalkEnd(walkEvent: WalkEvent, validationMessages: MutableSet<ValidationMessage>) {
        val field = walkEvent.at.substringAfterLast('.') // extract the field name
        val required = walkEvent.parentSchema.schemaNode["required"]?.contains(TextNode(field)) ?: false // check if that field is required

        if (required) {
            val type = walkEvent.schemaNode["type"] // get the field type
            // TODO resolve refs?
        }
    }
}

It is working pretty well, but I am having trouble resolving references. However I try resolving it, it fails with Couldn't find URI scheme: #/properties/myDto/properties/myField.

What is the proper way to do it?

alturkovic avatar Oct 24 '23 10:10 alturkovic