opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
567 stars 58 forks source link

[Question] Get loaded schema #129

Closed kvskkvsk closed 1 year ago

kvskkvsk commented 1 year ago

Is there any way to get the full schema with all loaded data by $ref without data validation?

For example: Loading schemaParent.json with some $ref

{ 
    "type": "object",
    "required": [
        "field1"
    ],
    "additionalProperties": false,
    "properties": {
        "field1": {
            "allOf": [
                {
                    "$ref": "./schemaChild.json"
                },
                {
                    "required": [
                        "value1"
                    ]
                }
            ]
        },
        "field2": {
            "type":"string",
            "enum":["a","b","c"]
        }
    }
}

where schemaChild.json is

{
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "value1": {
            "type": "string"
        },
        "value2": {
            "type": "string"
        }
    }
}

And output like:

stdClass Object
(
     [type] => object
     [required] => Array
         (
             [0] => field1
         )
     [additionalProperties] => 
     [properties] => stdClass Object
         (
             [field1] => stdClass Object
                 (
                     [allOf] => Array
                         (
                             [0] => stdClass Object
                                 (
                                     [type] => object
                                     [additionalProperties] => 
                                     [properties] => stdClass Object
                                         (
                                             [value1] => stdClass Object
                                                 (
                                                     [type] => string
                                                 )
                                             [value2] => stdClass Object
                                                 (
                                                     [type] => string
                                                 )
                                         )
                                 )
                             [1] => stdClass Object
                                 (
                                     [required] => Array
                                         (
                                             [0] => value1
                                         )
                                 )
                         )
                 )
             [field2] => stdClass Object
                 (
                     [type] => string
                     [enum] => Array
                         (
                             [0] => a
                             [1] => b
                             [2] => c
                         )
                 )
         )
 )
sorinsarca commented 1 year ago

Sorry, this is not possible.

deefour commented 1 year ago

@sorinsarca is it something you might consider adding?