Skip to content

...PropertyProxy::getProperty(): Return value must be of type ...PropertyInterface, null returned in #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
uuf6429 opened this issue Jan 20, 2023 · 4 comments · Fixed by #68

Comments

@uuf6429
Copy link

uuf6429 commented Jan 20, 2023

image

Note that the function return type was defined as non-null and, as you can see in the debugger, the specific key being looked up points to a null.

My suspicion (without digging deep into the code) is that the recursive declaration (line 530 of the schema) might be causing the null?

Describe the bug
Attempt to return null on a non-null return during generation.

Expected behavior
Generation should have succeeded.

Schema
https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json

Version:
0.23 (generator) / 0.18 (interfaces)


Additionally, the patternProperties regex check in BaseProcessor line 171 is triggering a failure for pattern ^/(html|css|js)/[^/\n\r]+$, which to me looks fine, but maybe I'm missing the purpose of the check.

@uuf6429 uuf6429 changed the title PHPModelGenerator\Model\Property\PropertyProxy::getProperty(): Return value must be of type PHPModelGenerator\Model\Property\PropertyInterface, null returned in ...PropertyProxy::getProperty(): Return value must be of type ...PropertyInterface, null returned in Jan 20, 2023
@wol-soft
Copy link
Owner

Hi, thanks for the report.

The patternProperties issue can be fixed relatively easy (it's an escaping issue). The purpose of the check is to throw an exception on patternProperties which provide an invalid pattern to avoid crashes inside the generated code.

The main issue is caused by the combination of recursion and the oneOf composition due to the way how compositions are resolved in the library. Each branch of the composition is internally resolved and the result is used to set up correct properties for the compsition (that's the place where the generation process is crashing). Due to the recursion the branch with $ref name-pattern-template is not resolved at that point and returns null (compare https://github.com/wol-soft/php-json-schema-model-generator/blob/master/src/Model/SchemaDefinition/SchemaDefinition.php#L92).

This will actually not be an easy fix. I've to think about a solution on how to change the resolving.

@uuf6429
Copy link
Author

uuf6429 commented Jan 25, 2023

For the pattern match, you're right, you only need to escape one character, @preg_match('/' . addcslashes($pattern, '/') . '/', '') should work well.

About the recursion, I don't know if this helps, but I solved similar problems in the past by first registering entries and then actually processing them - very similar to what you did in the comment you provided. Unfortunately I don't know enough about this scenario to suggest a more specific approach, sorry.

@wol-soft
Copy link
Owner

Exactly, the fix for pattern properties is identical to string properties with a pattern (https://github.com/wol-soft/php-json-schema-model-generator/blob/master/src/PropertyProcessor/Property/StringProcessor.php#L61).

Registering things and resolving them later is also used in this library (eg. the rendering of the code is executed after setting up all internal structures). The mechanic to resolve the issue will be similar. But as mentioned above, I've to think about the exact implementation approach.

wol-soft added a commit that referenced this issue Jan 26, 2023
wol-soft added a commit that referenced this issue Mar 13, 2023
Add onResolved callback to properties to execute further post-processing of the property only after the property has been created completely. Otherwise, the property might redirect to null causing the generation process to crash.

Compositions for example use generated properties to enrich the base model the composition belongs to. This process must be delayed until the properties are completely set up (an incomplete property might occur due to recursion). Consequently now the composition uses a callback mechanism to delay the process until all recursions are resolved.
@wol-soft
Copy link
Owner

Hi @uuf6429,

I've managed to (hopefully 😄) locate all places where the nested recursion causes issues like the original null-issue or out of memory errors related to infinite loops etc.

I've set up a branch https://github.com/wol-soft/php-json-schema-model-generator/tree/65-recursive-reference-resolving with the current state. I need to add a lot of tests in this section of recursions (the provided schema seems to be like a final boss for the library). Currently with the branch all existing tests are passing and the provided web-types schema is generated.

Do you have any data matching the schema for some manual testing? For the automated tests I'll strip the schema down to the cases causing the issues.

Sorry for the long response delay.

wol-soft added a commit that referenced this issue Mar 30, 2023
Add onResolved callback to validators to execute further post-processing of the validator and properties holding the validator only after the validator has been created completely. This is required as a validator might hold a nested property to execute the validation. This nested property might be a PropertyProxy due to recursion which might cause a crash of the generation process if the property hasn't been created completely before post-processing the property and the validator.
@wol-soft wol-soft linked a pull request Mar 30, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants