Skip to content

readFromJsonFile not working? #29

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
githubuser441 opened this issue Jun 18, 2019 · 4 comments · Fixed by #30
Closed

readFromJsonFile not working? #29

githubuser441 opened this issue Jun 18, 2019 · 4 comments · Fixed by #30
Assignees
Labels
bug Something isn't working
Milestone

Comments

@githubuser441
Copy link

I used the code from readme file but it's not working. code:
`require DIR . '/vendor/autoload.php';
use cebe\openapi\Reader;

// realpath is needed for resolving references with relative Paths or URLs
$openapi = Reader::readFromJsonFile(realpath('shootproof-studio-openapi.json'));`
Using this json file:
https://developer.shootproof.com/oas/studio.json

@cebe cebe added the bug Something isn't working label Jun 18, 2019
@cebe
Copy link
Owner

cebe commented Jun 18, 2019

Thanks for reporting, I will look into this.

Just to confirm, when I try to load the JSON file you specify I get that error:

Fatal error: Uncaught TypeError: Argument 1 passed to cebe\openapi\ReferenceContext::resolveRelativeUri() must be of the type string, null given, called in /tmp/test/vendor/cebe/php-openapi/src/spec/Reference.php on line 139 and defined in /tmp/test/vendor/cebe/php-openapi/src/ReferenceContext.php on line 77

TypeError: Argument 1 passed to cebe\openapi\ReferenceContext::resolveRelativeUri() must be of the type string, null given, called in /tmp/test/vendor/cebe/php-openapi/src/spec/Reference.php on line 139 in /tmp/test/vendor/cebe/php-openapi/src/ReferenceContext.php on line 77

Call Stack:
    0.0001     360784   1. {main}() /tmp/test/test.php:0
    0.0009     453776   2. cebe\openapi\Reader::readFromJsonFile() /tmp/test/test.php:7
    0.9087    4320888   3. cebe\openapi\spec\OpenApi->resolveReferences() /tmp/test/vendor/cebe/php-openapi/src/Reader.php:72
    0.9088    4320888   4. cebe\openapi\spec\Paths->resolveReferences() /tmp/test/vendor/cebe/php-openapi/src/SpecBaseObject.php:295
    0.9256    4183648   5. cebe\openapi\spec\PathItem->resolveReferences() /tmp/test/vendor/cebe/php-openapi/src/spec/Paths.php:228
    0.9256    4183648   6. cebe\openapi\spec\Operation->resolveReferences() /tmp/test/vendor/cebe/php-openapi/src/SpecBaseObject.php:295
    0.9256    4183648   7. cebe\openapi\spec\RequestBody->resolveReferences() /tmp/test/vendor/cebe/php-openapi/src/SpecBaseObject.php:295
    0.9256    4183648   8. cebe\openapi\spec\MediaType->resolveReferences() /tmp/test/vendor/cebe/php-openapi/src/SpecBaseObject.php:301
    0.9256    4183648   9. cebe\openapi\spec\Reference->resolve() /tmp/test/vendor/cebe/php-openapi/src/SpecBaseObject.php:293
    0.9256    4183648  10. cebe\openapi\ReferenceContext->resolveRelativeUri() /tmp/test/vendor/cebe/php-openapi/src/spec/Reference.php:139

is this the same error you are seeing?

@cebe cebe added this to the 1.0.2 milestone Jun 18, 2019
@cebe cebe self-assigned this Jun 18, 2019
@githubuser441
Copy link
Author

Yes, also I just noticed a typo in the readme:
$openapi = Reader::readFromYamlFile(realpath('openapi.json'));
You see it's loading json with yaml function.

@cebe
Copy link
Owner

cebe commented Jun 21, 2019

seems their spec has some interesting constructs.

  1. references that have additional properties
  2. recursive schema definitions

both cause multiple issues when loading and validating the spec.

@cebe
Copy link
Owner

cebe commented Jun 21, 2019

This should be fixed by #30, thanks for reporting! The spec you linked showed off a lot of issues that existed in the code. Should work much better now.

@cebe cebe modified the milestones: 1.0.2, 1.1 Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants