Skip to content

Add v3.1 schema and validation based on it - #117

Closed
WyriHaximus wants to merge 1 commit into
cebe:masterfrom
WyriHaximus-labs:add-v3.1-schemas
Closed

Add v3.1 schema and validation based on it#117
WyriHaximus wants to merge 1 commit into
cebe:masterfrom
WyriHaximus-labs:add-v3.1-schemas

Conversation

@WyriHaximus

Copy link
Copy Markdown

No description provided.

@WyriHaximusWyriHaximus mentioned this pull request Jun 10, 2021
@mariosimao

Copy link
Copy Markdown

Hi @cebe, any plans regarding this PR? Is there something missing that I could help?

@WyriHaximus

Copy link
Copy Markdown
Author

Hey @cebe I hate to ping, but ping?

@Mark-H

Mark-H commented Sep 21, 2021

Copy link
Copy Markdown

Had a quick play with this, validate seems to do the trick validating a 3.1 schema. Compared it with Spectral's validation for a spec written in the Stoplight editor.

With a valid schema:

➜ vendor/bin/php-openapi validate api-schema/openapi.yaml
The supplied API Description validates against the OpenAPI v3.1 schema.
➜ spectral lint api-schema/openapi.yaml
No results with a severity of 'error' or higher found!

And when breaking some random stuff in the schema to see it catches the issues it's also flagging what I'd expect:

➜ vendor/bin/php-openapi validate api-schema/openapi.yaml
Errors found while reading the API description from api-schema/openapi.yaml:
- [/info] Info is missing required property: version
- [/paths/~1recipes/get/parameters/1] Parameter is missing required property: name
- [/paths/~1recipes/get/parameters/1] Parameter is missing required property: in
OpenAPI v3.1 schema violations:
- [info.version] The property version is required
➜ spectral lint api-schema/openapi.yaml
/path/to/api-schema/openapi.yaml
1:1 warning oas3-api-servers OpenAPI "servers" must be present and non-empty array.
2:6 error oas3-schema "info" property must have required property "version". info
115:11 error oas3-schema "1" property must have required property "in". paths./recipes.get.parameters[1]
✖ 3 problems (2 errors, 1 warning, 0 infos, 0 hints)

convert is also working as expected on the schema and I can also walk through the schema with the PHP API, e.g.:

<?php
require __DIR__ . "/vendor/autoload.php";
$openapi = \cebe\openapi\Reader::readFromYamlFile(realpath(__DIR__ . '/api-schema/openapi.yaml'));
$recipe = $openapi->paths['/recipes/{recipeId}'];
var_dump($recipe->get->responses->getResponse(200)->content['application/json']->schema->properties);

I'm not too well-versed in the openapi 3.0/3.1 spec differences to say if this might need more work to complete the 3.1 integration but so far this seems to be working well.

@Jean85

Copy link
Copy Markdown

Other differences that we need to implement to fully support 3.1 are listed in #101

@WyriHaximus

Copy link
Copy Markdown
Author

Got a bunch of that ready to be PRed once this PR is in.

@cebecebe added this to the 1.6.0 milestone Oct 13, 2021
@@ -0,0 +1,1347 @@
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cebe you provide a make file script schemas/openapi-v3.0.json and schemas/openapi-v3.0.yaml.
Both scripts use the composer virtual dependency oai/openapi-specification which also needs to be updated.

This Pull Request didn't update these files. Should it be removed, or would you prefer an update of the package and make file?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelthole Can look at that if desired, don't recall how I got the 3.1 files but probably just downloaded them.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did that in #128

@cebecebe mentioned this pull request Oct 18, 2021
3 tasks
@cebe

cebe commented Oct 18, 2021

Copy link
Copy Markdown
Owner

@WyriHaximus thanks for starting this, I made a slightly different implementation in #128, which replaces this PR but includes most of your changes.

@cebecebe closed this Oct 18, 2021
@WyriHaximus

Copy link
Copy Markdown
Author

@cebe Sweet!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@WyriHaximus@mariosimao@Mark-H@Jean85@cebe@marcelthole