wol-soft / php-json-schema-model-generator

Creates (immutable) PHP model classes from JSON-Schema files including all validation rules as PHP code
MIT License
61 stars 13 forks source link

Crash on `"type": ["object"]` on object properties #51

Closed dktapps closed 3 years ago

dktapps commented 3 years ago

Describe the bug The below schema causes the following error on code generation:

Fatal error: Uncaught Error: Call to a member function getClassPath() on null in C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\Property
Processor\Property\ObjectProcessor.php:51
Stack trace:
#0 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\Property\MultiTypeProcessor.php(165): PHPModelGenerator\PropertyProc
essor\Property\ObjectProcessor->process('aliases', Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema))
#1 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\Property\MultiTypeProcessor.php(84): PHPModelGenerator\PropertyProce
ssor\Property\MultiTypeProcessor->processSubProperties('aliases', Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema), Object(PHPModelGenerator\Model\Property\Property))
#2 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\PropertyFactory.php(72): PHPModelGenerator\PropertyProcessor\Propert
y\MultiTypeProcessor->process('aliases', Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema))
#3 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\Property\BaseProcessor.php(279): PHPModelGenerator\PropertyProcessor
\PropertyFactory->create(Object(PHPModelGenerator\PropertyProcessor\PropertyMetaDataCollection), Object(PHPModelGenerator\SchemaProcessor\SchemaProcessor), Object(PHPModelGenerator\Model\Schema), 'aliases', Obj
ect(PHPModelGenerator\Model\SchemaDefinition\JsonSchema))
#4 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\Property\BaseProcessor.php(75): PHPModelGenerator\PropertyProcessor\
Property\BaseProcessor->addPropertiesToSchema(Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema))
#5 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\PropertyFactory.php(72): PHPModelGenerator\PropertyProcessor\Propert
y\BaseProcessor->process('Crash', Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema))
#6 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\SchemaProcessor\SchemaProcessor.php(191): PHPModelGenerator\PropertyProcessor\Property
Factory->create(Object(PHPModelGenerator\PropertyProcessor\PropertyMetaDataCollection), Object(PHPModelGenerator\SchemaProcessor\SchemaProcessor), Object(PHPModelGenerator\Model\Schema), 'Crash', Object(PHPMode
lGenerator\Model\SchemaDefinition\JsonSchema))
#7 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\SchemaProcessor\SchemaProcessor.php(137): PHPModelGenerator\SchemaProcessor\SchemaProc
essor->generateModel('', 'Crash', Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema), Object(PHPModelGenerator\Model\SchemaDefinition\SchemaDefinitionDictionary), true)
#8 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\SchemaProcessor\SchemaProcessor.php(104): PHPModelGenerator\SchemaProcessor\SchemaProc
essor->processSchema(Object(PHPModelGenerator\Model\SchemaDefinition\JsonSchema), '', 'Crash', Object(PHPModelGenerator\Model\SchemaDefinition\SchemaDefinitionDictionary), true)
#9 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\ModelGenerator.php(125): PHPModelGenerator\SchemaProcessor\SchemaProcessor->process(Ob
ject(PHPModelGenerator\Model\SchemaDefinition\JsonSchema))
#10 C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\generate-schemas.php(74): PHPModelGenerator\ModelGenerator->generateModels(Object(PHPModelGenerator\SchemaProvider\RecursiveDirectoryProv
ider), 'C:\\Users\\dylan-...')
#11 {main}
  thrown in C:\Users\dylan-work\Documents\projects\pocketmine-mp\deps\DataModels\vendor\wol-soft\php-json-schema-model-generator\src\PropertyProcessor\Property\ObjectProcessor.php on line 51

Expected behavior The model should be generated exactly as if I'd used type: object.

Schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "aliases": {
            "type": ["object"]
        }
    }
}

Generator config: https://github.com/pmmp/DataModels/blob/d91723d5cccb8879532430ba4aff80949c440034/generate-schemas.php

Version: 0.21.5

Additional context I was trying to use type arrays to create explicitly nullable object fields.