Skip to content

Allow referencing Path Item only via Reference Object (#2635) #2657

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

Merged

Conversation

char0n
Copy link
Contributor

@char0n char0n commented Jul 23, 2021

Signed-off-by: Vladimir Gorej [email protected]

@gimbimloki
Copy link

gimbimloki commented Sep 23, 2022

@char0n @MikeRalphson
Hello. When OAS 3.2.0 is released, could I use Reference Objects in Paths Object like below?

paths:
  $ref: foo.yaml
  $ref: bar.yaml

@handrews
Copy link
Member

handrews commented Mar 6, 2023

@gimbimloki YAML does not allow for duplicate keys, so no (and that's not something OAS can change).

Duplicate keys in JSON are a more complex topic, but the TL;DR is that most JSON implementations don't support them in a usable way.

@gimbimloki
Copy link

@handrews Thank you for your reply.
So, Only one '$ref' can be in Paths Object, is it right?

@gimbimloki gimbimloki mentioned this pull request Mar 7, 2023
@handrews
Copy link
Member

handrews commented Mar 9, 2023

@gimbimloki Keys must be unique in YAML. Non-unique keys in JSON do not have consistent behavior (usually one is discarded). Therefore it is impossible to have two $refs in the same object in YAML, and in JSON the result is unpredictable. It has nothing to do with the Paths Object, specifically, but the effect is that yes, you can only have one $ref in the Paths Object (or in any other object in this or any other YAML/JSON specification, no matter what).

@karenetheridge
Copy link
Member

karenetheridge commented Mar 23, 2024

This change feels incomplete, as it's now allowing a path-item entry to be a regular reference, but then not changing the definition of a path-item itself to disallow $ref from being present adjacent to other path-item properties like summary, description, parameters, get etc.

So now (in 3.2.0), this is still legal:

paths:
  /pets/{petId}:
    $ref: "#/components/pathItems/one_pet"
components:
  pathItems:
    one_pet:
      $ref: "#/components/pathItems/more_pet_things"
      summary: a single pet
      get:
        ... operation things here
    more_pet_things:
      $ref: "#/components/pathItems/even_more_pet_things"
      description: ...
      post:
        ... operation things here
    even_more_pet_things:
      put:
        ...

...which means that when processing a request for PUT /pets/123 we end up getting bits of the request description from all of /components/path-items/*, which is the mess that we had in 3.1.0.

To fix this, I think we need to remove the $ref property from /$defs/path-item (which is a schema change). That way we can still have a chain of multiple $refs (just as we allow for other entity types like response, header etc) but no non-$ref fields can appear anywhere along the chain, only at the leaf.

Additionally, the reference under /paths/{path} (/$defs/paths/patternProperties/^~1/$ref) should be changed from #/$defs/path-item to #/$defs/path-item-or-reference.

(I can submit a PR to make this change for 3.2.)


addendum:

I misread the schema in the 3.2 branch -- it did not get the $ref property added to path-item (it was never in 3.1 until it was added in #3355, which did not propagate to the 3.2 branch). So most of my complaint above is moot -- there is just one small correction to make for 3.2, to allow for /paths/<some path>/$ref or to exist, so I'll submit that as a PR now.

karenetheridge added a commit to karenetheridge/OpenAPI-Specification that referenced this pull request Mar 23, 2024
See OAI#2657 - this was added to the specification but not the schema.
karenetheridge added a commit to karenetheridge/OpenAPI-Specification that referenced this pull request Mar 23, 2024
See OAI#2657 - this was added to the specification but not the schema.
karenetheridge added a commit to karenetheridge/OpenAPI-Specification that referenced this pull request Mar 23, 2024
See OAI#2657 - this was added to the specification but not the schema.
@handrews handrews added this to the v3.2.0 milestone May 17, 2024
@handrews handrews added the re-use: traits/merges Selective or modified re-use label May 17, 2024
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
re-use: traits/merges Selective or modified re-use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants