Skip to content
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

Fatal Error - $context empty in SchemaNormalizer #180

Open
Niehztog opened this issue Nov 22, 2019 · 16 comments · Fixed by #226
Open

Fatal Error - $context empty in SchemaNormalizer #180

Niehztog opened this issue Nov 22, 2019 · 16 comments · Fixed by #226
Labels

Comments

@Niehztog
Copy link

@Niehztog Niehztog commented Nov 22, 2019

When running janephp v4 for an openapi v2.0 swagger file, after about 40 minutes I get this error:

PHP Notice:  Undefined index: document-origin in /home/user/projects/janephp/vendor/jane-php/open-api/Normalizer/SchemaNormalizer.php on line 43
PHP Stack trace:
PHP   1. {main}() /home/user/projects/janephp/vendor/jane-php/open-api/bin/jane-openapi:0
PHP   2. Jane\OpenApi\Application->run() /home/user/projects/janephp/vendor/jane-php/open-api/bin/jane-openapi:22
PHP   3. Jane\OpenApi\Application->doRun() /home/user/projects/janephp/vendor/symfony/console/Application.php:148
PHP   4. Jane\OpenApi\Application->doRunCommand() /home/user/projects/janephp/vendor/symfony/console/Application.php:272
PHP   5. Jane\OpenApi\Command\GenerateCommand->run() /home/user/projects/janephp/vendor/symfony/console/Application.php:1011
PHP   6. Jane\OpenApi\Command\GenerateCommand->execute() /home/user/projects/janephp/vendor/symfony/console/Command/Command.php:255
PHP   7. Jane\OpenApi\JaneOpenApi->generate() /home/user/projects/janephp/vendor/jane-php/open-api/Command/GenerateCommand.php:69
PHP   8. Jane\OpenApi\Generator\Psr18ClientGenerator->generate() /home/user/projects/janephp/vendor/jane-php/json-schema/Generator/ChainGenerator.php:28
PHP   9. Jane\OpenApi\Generator\Psr7OperationGenerator->createOperation() /home/user/projects/janephp/vendor/jane-php/open-api/Generator/ClientGenerator.php:43
PHP  10. Jane\OpenApi\Generator\Psr7EndpointGenerator->createEndpointClass() /home/user/projects/janephp/vendor/jane-php/open-api/Generator/OperationGenerator.php:33
PHP  11. Jane\OpenApi\Generator\Psr7EndpointGenerator->getConstructor() /home/user/projects/janephp/vendor/jane-php/open-api/Generator/EndpointGenerator.php:74
PHP  12. Jane\OpenApi\Generator\Psr7EndpointGenerator->resolveParameter() /home/user/projects/janephp/vendor/jane-php/open-api/Generator/EndpointGenerator.php:145
PHP  13. Jane\JsonSchemaRuntime\Reference->resolve() /home/user/projects/janephp/vendor/jane-php/open-api/Generator/EndpointGenerator.php:647
PHP  14. Jane\OpenApi\Generator\Psr7EndpointGenerator->Jane\OpenApi\Generator\{closure:/home/user/projects/janephp/vendor/jane-php/open-api/Generator/EndpointGenerator.php:629-647}() /home/user/projects/janephp/vendor/jane-php/json-schema-runtime/Reference.php:68
PHP  15. Symfony\Component\Serializer\Serializer->denormalize() /home/user/projects/janephp/vendor/jane-php/open-api/Generator/EndpointGenerator.php:631
PHP  16. Jane\OpenApi\Normalizer\BodyParameterNormalizer->denormalize() /home/user/projects/janephp/vendor/symfony/serializer/Serializer.php:191
PHP  17. Symfony\Component\Serializer\Serializer->denormalize() /home/user/projects/janephp/vendor/jane-php/open-api/Normalizer/BodyParameterNormalizer.php:64
PHP  18. Jane\OpenApi\Normalizer\SchemaNormalizer->denormalize() /home/user/projects/janephp/vendor/symfony/serializer/Serializer.php:191
PHP Fatal error:  Uncaught TypeError: Argument 2 passed to Jane\JsonSchemaRuntime\Reference::__construct() must be of the type string, null given, called in /home/user/projects/janephp/vendor/jane-php/open-api/Normalizer/SchemaNormalizer.php on line 43 and defined in /home/user/projects/janephp/vendor/jane-php/json-schema-runtime/Reference.php:28
Stack trace:
#0 /home/user/projects/janephp/vendor/jane-php/open-api/Normalizer/SchemaNormalizer.php(43): Jane\JsonSchemaRuntime\Reference->__construct('#/definitions/S...', NULL)
#1 /home/user/projects/janephp/vendor/symfony/serializer/Serializer.php(191): Jane\OpenApi\Normalizer\SchemaNormalizer->denormalize(Object(stdClass), 'Jane\\OpenApi\\Mo...', 'json', Array)
#2 /home/user/projects/janephp/vendor/jane-php/open-api/Normalizer/BodyParameterNormalizer.php(64): Symfony\Component\Serializer\Serializer->denormalize(Object(stdClass), 'Jane\\OpenApi\\Mo...', 'jso in /home/user/projects/janephp/vendor/jane-php/json-schema-runtime/Reference.php on line 28

If necessary I can provide the swagger file on request, but it looks more like a general issue to me (missing validation if $context['document-origin'] is present).

@Korbeil Korbeil added the 4.x label Nov 22, 2019
@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Nov 22, 2019

Hi @Niehztog, could you provide your OpenApi schema to see where the error could come from / reproduce your bug ?

@Korbeil Korbeil added the bug label Nov 22, 2019
@Niehztog

This comment has been minimized.

Copy link
Author

@Niehztog Niehztog commented Nov 22, 2019

Hello @Korbeil and thank you for your quick reply. I uploaded the swagger file (35 MB) on my google drive here:
https://drive.google.com/file/d/1Ko3LAMO6BzhXrUEnqPu8SMkXoogPqfWn/view?usp=sharing

@atymic

This comment has been minimized.

Copy link

@atymic atymic commented Jan 12, 2020

Also having this issue, tried with the offical twitter openapi v3 spec:
https://api.twitter.com/labs/1/openapi.json

@Korbeil let me know if there's any other info you need. Tried with both PHP 7.2 & 7.3

@atymic

This comment has been minimized.

Copy link

@atymic atymic commented Jan 12, 2020

Here's a screenshot of the debugger when it crashes
image

@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 12, 2020

Thanks for sharing, your file is way easier to evaluate since it's only 10kb (vs 36mb for the other one), I'll try to look at this bug tomorrow 😉

@atymic

This comment has been minimized.

Copy link

@atymic atymic commented Jan 12, 2020

No worries :)
I tried a hacky fix of force setting the $context but it didn't work (just caused other errors).

@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 13, 2020

And I fixed it 😉 See #226, I'll try with @Niehztog file later to see it does work for him aswell !

@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 13, 2020

@Niehztog I moved a bit forward for your issue. Your file is no longuer blocked while generating and takes only ~20min now. But, when generating, some Normalizer, our Naming class output related Normalizer file name and this occur:
image

I have to see how I can shorten this filename 😄

@Korbeil Korbeil closed this in #226 Jan 13, 2020
@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 13, 2020

Ok, everything is solved:

  • Our main issue was the time needed to generate your file, quite a pain to wait ~20min to see if my script is broken, so thanks to @bastnic (see #227) we got a nice improvement that make your file need ~2min to generate now 👌
  • We got a small issue on a missing context, but this was not something hard to solve, just needed to reproduce some stuff we already do in other places
  • And the best for the end, the filesystem error when having filenames with a length greather than 255 characters ! To fix this, I take last 218 characters then I add a MD5 hash of the original filename at the begining (32 chars) and we add the file extension, which make 254 characters 😉

Quite a nice issue we got there, thanks again to report it, all theses related contributions will help the library a lot !

@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 13, 2020

And I'm back, the solution for filename with more than 255 was not working, I need to find something better ! (see c846904)

@Korbeil Korbeil reopened this Jan 13, 2020
@Niehztog

This comment has been minimized.

Copy link
Author

@Niehztog Niehztog commented Jan 13, 2020

@Korbeil , thank you so much for fixing this. Your merge request looks as if it was a lots of work to do (many changed lines and files).
Will this be merged into the v4.x branch aswell?

@atymic

This comment has been minimized.

Copy link

@atymic atymic commented Jan 14, 2020

Tried to give it a go but I can't seem to run dev-master. Will give it a go once tagged :)

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for jane-php/open-api dev-master -> satisfiable by jane-php/open-api[dev-master].
    - jane-php/open-api dev-master requires jane-php/open-api-common ^5.0 -> no matching package found.
@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 14, 2020

@Niehztog many files were added because I took twitter OpenApi spec into our fixtures, to be sure we won't have same issue again 😉
For 4.x branch, no I won't merge this fix in 4.x since we now have an OpenApi2 component on master branch aswell 😉 Keeping 4.x branch up-to-date is very hard so I moved it onto master with some improvements 😉

@atymic This should work actually, what's your PHP version ? We do require PHP 7.2 minimum actually, probably your issue here ?

@atymic

This comment has been minimized.

Copy link

@atymic atymic commented Jan 16, 2020

@Korbeil that's not the issue 🤔

PHP 7.3.12 (cli) (built: Nov 29 2019 20:07:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
    with Zend OPcache v7.3.12, Copyright (c) 1999-2018, by Zend Technologies
@Korbeil

This comment has been minimized.

Copy link
Member

@Korbeil Korbeil commented Jan 16, 2020

Oh, I see, you have to use jane-php/jane-php package if you want to require dev-master 😉 Not the component.

@atymic

This comment has been minimized.

Copy link

@atymic atymic commented Jan 17, 2020

Perfect, that worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.