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

Fix 3.1 Path Item schema #3355

Merged
merged 1 commit into from
Feb 1, 2024
Merged

Fix 3.1 Path Item schema #3355

merged 1 commit into from
Feb 1, 2024

Conversation

handrews
Copy link
Member

Fixes #2635 (schema aspects, not spec aspects); fixes #3298

Path Item Objects allow "$ref", and despite the syntactic overlap, it is neither accurate nor semantically meaningful to parse a Path Item Object as a Reference Object, even if such parsing would be successful.

Path Item Objects allow "$ref", and despite the syntactic overlap,
it is neither accurate nor semantically meaningful to parse
a Path Item Object as a Reference Object, even if such parsing
would be successful.
@karenetheridge
Copy link
Member

Thank you for this.

But is this really the first actual PR we've seen for this? (sincere question) It's been talked about as an issue for years.

@handrews
Copy link
Member Author

@karenetheridge I didn't notice another one ¯\(ツ)

@skryukov
Copy link
Contributor

I noticed that path-item doesn't include the $ref property in schema.json, should we update schema.json in this PR as well?

@handrews
Copy link
Member Author

handrews commented Aug 23, 2023

@skryukov I believe the JSON version is generated from the YAML version, so the PR only targets YAML directly. @webron would probably know for sure.

@webron
Copy link
Member

webron commented Aug 23, 2023

That's correct. Before publishing a new version of the Schema we generate the json from the yaml version.

@TristanSpeakEasy
Copy link

Okay just ran into a customer using $ref in a path-item which currently according to the documentation here: https://spec.openapis.org/oas/v3.1.0#pathItemRef seems to be perfectly valid.

Its just the json schema here: https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.1/schema.json#L294 being #/$defs/path-item instead of #/$defs/path-item-or-reference that seems to be the problem, as json-schema validators are complaining about it.

But this PR and the discussion around it seems to be removing the ability to use references for path items, is that correct? Should I go back to the customer and tell them what they are doing isn't valid even though the documentation states otherwise?

Will the documentation be updated as part of this PR?

The use-case the customer has seems totally valid (individual teams manage different endpoints that are documented in different documents and they are trying to pull it all together into one document via the references), what would someone do to organize their document in this distributed manner if this feature goes away?

@handrews
Copy link
Member Author

@TristanSpeakEasy apologies for the delay in replying, I lost track of stuff during the holiday season.

This is not changing anything about the specification. The schema is not normative (meaning it does not have the force of the spec itself), so nothing changed in the schema impacts the spec.

This PR is confusing because Path Item's $ref is not a normal Reference Object for Historical Reasons™. Instead, there's a "$ref" property in the Path Item Object schema, and it is not combined with the Reference Object schema the way it is for other Objects that can be referenced.

@earth2marsh earth2marsh merged commit 54a7c9f into OAI:main Feb 1, 2024
2 checks passed
@handrews handrews deleted the path-item-ref branch March 5, 2024 21:31
Stranger6667 pushed a commit to schemathesis/schemathesis that referenced this pull request Oct 5, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants