Skip to content

fix(oas3.1): correctly validate paths using $ref#2485

Merged
Stranger6667 merged 1 commit intoschemathesis:masterfrom
BronzeDeer:update-oas-3.1-spec
Oct 5, 2024
Merged

fix(oas3.1): correctly validate paths using $ref#2485
Stranger6667 merged 1 commit intoschemathesis:masterfrom
BronzeDeer:update-oas-3.1-spec

Conversation

@BronzeDeer
Copy link
Contributor

@BronzeDeer BronzeDeer commented Oct 4, 2024

Fixes #2484

Description

Schemathesis uses static version of the current published version of the OpenApi 3.1 spec metaschema
(https://spec.openapis.org/oas/3.1/schema/2022-10-07) to validate openapi 3.1 spec documents. Unfortunately, the published version has at least one known bug in which the schema for paths references the definition of a concrete path-item instead of path-item-or-reference, which might still be technically incorrect when it comes handling the case of ref and sibling fields, but is correct according to the documented definition of a pathItemObject.

This oversight has been noticed multiple times
OAI/OpenAPI-Specification#3298 OAI/OpenAPI-Specification#2635 (comment) OAI/OpenAPI-Specification#2635 (comment) OAI/OpenAPI-Specification#3513 OAI/OpenAPI-Specification#2657 (comment)

And finally fixed in Feb 2024
OAI/OpenAPI-Specification#3355 with a slightly bigger rework of the pathItem schema.

Sadly, due to confusion about how to release fixes in schemas OAI/OpenAPI-Specification#151 (comment) this change has not been published anywhere except schema.yaml in the git repo, not even in schema.json, which appearantly only gets refreshed once per release of the metaschema
OAI/OpenAPI-Specification#3355 (comment)

This commit updates the stored schema from the most up-to-date 3.1.0 schema.yaml from 0035208 to close the bug and make spec-valid openapi spec files that use $ref under path finally validate correctly in schemathesis. It also adds a corresponding regression test

Checklist

  • Added failing tests for the change
  • All new and existing tests pass
  • Added changelog entry (follow guidelines in CONTRIBUTING.rst)
  • Updated README/documentation, if necessary

Schemathesis uses static version of the current published version
of the OpenApi 3.1 spec metaschema
(https://spec.openapis.org/oas/3.1/schema/2022-10-07)
to validate openapi 3.1 spec documents. Unfortunately, the published
version has at least one known bug in which the schema for `paths`
references the definition of a concrete `path-item` instead of
`path-item-or-reference`, which might still be technically incorrect
when it comes handling the case of ref and sibling fields, but is
correct according to the documented definition of a pathItemObject.

This oversight has been noticed multiple times
OAI/OpenAPI-Specification#3298
OAI/OpenAPI-Specification#2635 (comment)
OAI/OpenAPI-Specification#2635 (comment)
OAI/OpenAPI-Specification#3513
OAI/OpenAPI-Specification#2657 (comment)

And finally fixed in Feb 2024
OAI/OpenAPI-Specification#3355
with a slightly bigger rework of the pathItem schema.

Sadly, due to confusion about how to release fixes in schemas
OAI/OpenAPI-Specification#151 (comment)
this change has not been published anywhere except schema.yaml in the
git repo, not even in schema.json, which appearantly only gets refreshed
once per release of the metaschema
OAI/OpenAPI-Specification#3355 (comment)

This commit updates the stored schema from the most up-to-date 3.1.0
schema.yaml from 0035208 to close the bug and make spec-valid openapi
spec files that use $ref under path finally validate correctly in
schemathesis. It also adds a corresponding regression test
@BronzeDeer
Copy link
Contributor Author

I get a very small handful of test failures in local runs:

FAILED test/loaders/test_common.py::test_port_override_with_ipv6[from_uri-openapi3_schema_url-requests.get-http://[2002:7f00:1::]:8081/schema.yaml] - ValueError: Host '[2002:7f00:0001::]' cannot contain '[' (at position 0)
FAILED test/loaders/test_common.py::test_port_override_with_ipv6[from_url-graphql_url-requests.post-http://[2002:7f00:1::]:8081/graphql] - ValueError: Host '[2002:7f00:0001::]' cannot contain '[' (at position 0)
FAILED test/hooks/test_hooks.py::test_global_body_hook[Open API 2.0] - AssertionError: assert 0 == 5
FAILED test/hooks/test_hooks.py::test_global_body_hook[Open API 3.0] - AssertionError: assert 0 == 5
FAILED test/cli/test_cassettes.py::test_replay[Open API 2.0-plain-True] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/test_app.py::test_app[flask] - AssertionError: assert 'Schemathesis test server is running!' in ''
FAILED test/test_app.py::test_app[aiohttp] - AssertionError: assert 'Schemathesis test server is running!' in ''
FAILED test/cli/test_cassettes.py::test_replay[Open API 2.0-plain-False] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/cli/test_cassettes.py::test_replay[Open API 2.0-base64-True] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/cli/test_cassettes.py::test_replay[Open API 2.0-base64-False] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/cli/test_cassettes.py::test_replay[Open API 3.0-plain-True] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/cli/test_cassettes.py::test_replay[Open API 3.0-plain-False] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/cli/test_cassettes.py::test_replay[Open API 3.0-base64-True] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/cli/test_cassettes.py::test_replay[Open API 3.0-base64-False] - ValueError: Host '127.0.0.1:56515' cannot contain ':' (at position 9)
FAILED test/hooks/test_hooks.py::test_after_load_schema - AssertionError: assert {'errors': 1,...pped': 0, ...} == {'errors': 0,...pp...

Since they look unrelated to OAS3.1 and they occur both on master and on my fix, I'll assume that these are either pre-existing or my (admittedly hasty and hacky) build and test setup is slightly wonky

@codecov
Copy link

codecov bot commented Oct 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.10%. Comparing base (51289c0) to head (4eac10f).
Report is 146 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2485      +/-   ##
==========================================
+ Coverage   98.09%   98.10%   +0.01%     
==========================================
  Files         150      150              
  Lines       13582    13596      +14     
  Branches     2913     2914       +1     
==========================================
+ Hits        13323    13339      +16     
+ Misses        144      143       -1     
+ Partials      115      114       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 5, 2024

CodSpeed Performance Report

Merging #2485 will not alter performance

Comparing BronzeDeer:update-oas-3.1-spec (4eac10f) with master (8324b9c)

Summary

✅ 52 untouched benchmarks

@Stranger6667
Copy link
Member

Awesome! Thank you for the report and the fix :)

P.S. Test failures are indeed unrelated and happened before due to yarl upgrade

@Stranger6667 Stranger6667 merged commit 38f32aa into schemathesis:master Oct 5, 2024
@BronzeDeer BronzeDeer deleted the update-oas-3.1-spec branch October 5, 2024 16:06
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 this pull request may close these issues.

[BUG] schemathesis fails to validate schemas with paths using $ref

2 participants