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

Add OAS 3.0 support #3

Open
zeroimpl opened this issue May 11, 2018 · 5 comments
Open

Add OAS 3.0 support #3

zeroimpl opened this issue May 11, 2018 · 5 comments

Comments

@zeroimpl
Copy link

Any plans to add an OAS 3.0 version?
I tried running Gendarme with the spec from https://github.com/googleapis/gnostic/blob/master/OpenAPIv3/openapi-3.0.json and it didn't quite work - there were a few syntax errors (classes named "2" and "4") and I think a few other quirks.

@calcinai
Copy link
Owner

Hey, I just had a look at this and seems to be a simple fix. It's just an issue with numeric keys, but because PHP's loose types, it's not handled by default.

I'd say that by testing if the key is all numeric would be enough. Feel free to make a PR, otherwise I'll have a look at it when I get a chance.

@zeroimpl
Copy link
Author

Thanks. I had worked around that issue (I think), but it seemed like there were a few other issues as well.

For example, I had been trying to figure out how to set the content of a Response object - in OAS 3.0 it seems for each status code you need to create a map from content type (eg 'application/json') to the actual object. I couldn't figure out how to get the MediaTypes class working for that, which is needed by the setContent method of Response. So I decided to try just initializing an instance from an existing OAS 3.0 spec and dump the PHP object for that, but this failed as well:

$schema = json_decode(file_get_contents('https://raw.githubusercontent.com/googleapis/gnostic/master/examples/v3.0/json/petstore.json'));
$swagger = \Calcinai\Strut3\Swagger::create($schema);
var_export( $swagger );

The above fails with:

PHP Fatal error:  Uncaught exception 'InvalidArgumentException' in Calcinai\Strut3\BaseSchema.php:201
Stack trace:
#0 BaseSchema.php(172): Calcinai\Strut3\BaseSchema::tryToCast(Array, Array)
#1 BaseSchema.php(29): Calcinai\Strut3\BaseSchema->parseData(Array)
#2 BaseSchema.php(219): Calcinai\Strut3\BaseSchema->__construct(Array)
#3 swagger-gen3test.php(53): Calcinai\Strut3\BaseSchema::create(Array)

So at the moment I'll probably stick with doing 2.0 then since it works well enough and I don't have enough time to spend on experimenting with 3.0 right now. Anyways thanks for taking a look at this.

@calcinai
Copy link
Owner

calcinai commented Mar 1, 2019

@zeroimpl did you get a chance to test this? Sorry it took me so long to get working!

@zeroimpl
Copy link
Author

zeroimpl commented Mar 4, 2019

@calcinai Taking a look now. Looks like will be quite a few things to tweak to get my code working with the new version.
I did run into one issue so far though - calling setExample('blah') on Schema fails with:

exception 'InvalidArgumentException' with message '[Calcinai\Strut\Definitions\Schema] does not accept property [example]'

I think in Schema.php you need to replace

'example' => ['mixed']

with

'example' => []

There are a few other places with reference to 'mixed' as well.

@calcinai
Copy link
Owner

calcinai commented Mar 4, 2019

Oh man, it's so close! I'll take a look at it soon

@calcinai calcinai reopened this Mar 4, 2019
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

No branches or pull requests

2 participants