Skip to content

Commit

Permalink
fix(reference): fix regression in OpenAPI 3.1.0 dereferencing (#3978)
Browse files Browse the repository at this point in the history
Refs #3974
  • Loading branch information
char0n committed Mar 28, 2024
1 parent 45d706f commit ff039fe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,17 @@ const OpenApi3_1DereferenceVisitor = stampit({
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is a Reference Object. We need to follow it to get the eventual value
* 3. We are dereferencing the fragment lazily/eagerly depending on circular mode
* 2. Fragment is from non-root document
* 3. Fragment is a Reference Object. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = reference.refSet.rootRef.uri !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
isReferenceElement(referencedElement) ||
['error', 'replace'].includes(this.options.dereference.circular)) &&
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
) {
// append referencing reference to ancestors lineage
Expand Down Expand Up @@ -425,13 +429,17 @@ const OpenApi3_1DereferenceVisitor = stampit({
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
* 3. We are dereferencing the fragment lazily/eagerly depending on circular mode
* 2. Fragment is from non-root document
* 3. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = reference.refSet.rootRef.uri !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
(isPathItemElement(referencedElement) && isStringElement(referencedElement.$ref)) ||
['error', 'replace'].includes(this.options.dereference.circular)) &&
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
) {
// append referencing reference to ancestors lineage
Expand Down Expand Up @@ -845,13 +853,17 @@ const OpenApi3_1DereferenceVisitor = stampit({
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is a Schema Object with $ref field. We need to follow it to get the eventual value
* 3. We are dereferencing the fragment lazily/eagerly depending on circular mode
* 2. Fragment is from non-root document
* 3. Fragment is a Schema Object with $ref field. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = reference.refSet.rootRef.uri !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
(isSchemaElement(referencedElement) && isStringElement(referencedElement.$ref)) ||
['error', 'replace'].includes(this.options.dereference.circular)) &&
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
) {
// append referencing reference to ancestors lineage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
"profile": {
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Date and time when the message was sent."
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"type": "object",
"$defs": {
"UserProfile": {
"schema1": {
"$ref": "#/$defs/somePayload"
},
"somePayload": {
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
"sentAt": {
"$ref": "#/$defs/sentAt"
}
}
},
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Date and time when the message was sent."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "object",
"properties": {
"profile": {
"$ref": "./ex.json#/$defs/UserProfile"
"$ref": "./ex.json#/$defs/schema1"
}
}
}
Expand Down

0 comments on commit ff039fe

Please sign in to comment.