Ambiguity between Reference Object and PathItem Object
See original GitHub issueHi everybody, not sure if this is the right place to ask this, but I’ve intercepted an ambiguity while building tooling for OAS 3.1
{
"openapi": "3.1.0",
"components": {
"pathItems": {
"pathItem1": {
"$ref": "#/components/pathItems/pathItem2",
},
"pathItem2": {
"summary": "path item summary",
"description": "path item description",
"get": {}
}
}
}
}
Given following document, pathItem1 can be interpreted either as Reference Object or Path Item Object. It’s hard to tell what the author intended. He could have intended for pathItem1 to be a Reference Object. Or he may have intended pathItem1 to be a Path Item Object. As Path Item Object can have exactly the same shape as Reference Object the intention of the author is lost.
Can you please advice how to approach that?
Instead of having this ambiguity and $ref
field in Path Item Object, wouldn’t it be cleaner to use Reference Object explicitly in every place where Path Item Object is allowed?
Current workaround could be assert the presence of $ref
field and one of the other fixed fields from Path Item Object (like get
, post
, etc…). If assertion like that passes, we can say with limited certainty that author intended to define a Path Item Object.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (12 by maintainers)
Top GitHub Comments
@darrelmiller IMHO
3.1.1 - 1
and3.1.1 - 3
contradict each other. If our aim is to remove$ref
field field fromPath Item Object
in next breaking change release following steps seems like more appropriate:3.1.1
The aim here is provide clarification to limit ambiguity
Reference Object | Path Item Object
in all places within spec toPath Item Object
$ref
fixed field inPath Item Object
3.2.0
The aim here is to have only one referencing mechanism iwithing OAS 3.2 spec (reducing complexity) -
Referece Object
(JSON Schema spec has it’s own $ref mechanism)Path Item Object
fixed fieldsPath Item Object
in all places within spec toReference Object | Path Item Object
So this technically means that if Object looks like a Reference Object, it will always be considered a Reference Object.
As @webron mentioned it’s a remnant from older specifications, where
components/pathItems
fields did not exist andPaths Object
only allowsPath Item Object
as a value of it’s pattern fields. So including$ref
field inPath Item Object
was the only way to reference anotherPath Item Object
fromPaths Object
.As the merging rules as
undefined
by the specification, tooling authors have to come up with something that makes sense. I’ve chosen the same merging rules asReference Object
andSchema Object
follows. Fields from referencing object will shallowly override fields from referenced object.Acoording to this:
Allows for a referenced definition of this path item. The referenced structure MUST be in the form of a Path Item Object. In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving Relative References.
the Reference Oject behaviors don’t apply and the behavior is undefined.This would contradict the current schema validation. IMHO better way and possibly more forward compatible one would be to stay with the current validation and consider everything that looks like a Reference Object a Reference Object.
So if I understand this correctly, whenever there there is a choice between
Reference Object | Path Item Object
and the Object defines a$ref
field, we should always consider it aPath Item Object
. This will have an implication on fields merging as Path Item Object doesn’t define it and every tooling author can choose how to define the merging. It is also not aligned with current schema validation.I still think that this is problematic and opens door for unnecessary interpretations. In order to reduce the complexity and eliminate the ambiguity I propose following:
$ref
field fromPath Item Object
Type
forPaths Object
field pattern as this:Path Item Object | Reference Object
This small change will make things right in backward compatible manner.