Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ class OpenAPI3_0DereferenceVisitor {
return undefined;
}

// ignore already dereferenced ExampleElement; value field was transcluded from externalValue field
if (exampleElement.value?.meta.hasKey('ref-origin')) {
return undefined;
}

// value and externalValue fields are mutually exclusive
if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) {
const error = new ApiDOMError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,11 @@ class OpenAPI3_1DereferenceVisitor {
return undefined;
}

// ignore already dereferenced ExampleElement; value field was transcluded from externalValue field
if (exampleElement.value?.meta.hasKey('ref-origin')) {
return undefined;
}

// value and externalValue fields are mutually exclusive
if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) {
const error = new ApiDOMError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,11 @@ class OpenAPI3_2DereferenceVisitor {
return undefined;
}

// ignore already dereferenced ExampleElement; value field was transcluded from externalValue field
if (exampleElement.value?.meta.hasKey('ref-origin')) {
return undefined;
}

// value and externalValue fields are mutually exclusive
if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) {
const error = new ApiDOMError(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"openapi": "3.0.4",
"paths": {
"/path1": {
"post": {
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"example1": {
"description": "example1 description",
"externalValue": "./ex.json",
"value": {
"prop1": "value1",
"prop2": "value2"
}
}
}
}
}
}
}
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"openapi": "3.0.4",
"paths": {
"/path1": {
"$ref": "./path-item.json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prop1": "value1",
"prop2": "value2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"post": {
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"example1": {
"description": "example1 description",
"externalValue": "./ex.json"
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ describe('dereference', function () {
});
});

context(
'given Example Object is inside externally referenced Path Item Object',
function () {
const fixturePath = path.join(entryFixturePath, 'external-value-path-item-ref');

specify('should dereference', async function () {
const entryFilePath = path.join(fixturePath, 'entry.json');
const actual = await dereference(entryFilePath, {
parse: { mediaType: mediaTypes.latest('json') },
});
const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json'));

assert.deepEqual(toValue(actual), expected);
});
},
);

context('given both value and externalValue fields are defined', function () {
const fixturePath = path.join(entryFixturePath, 'external-value-value-both-defined');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"openapi": "3.1.0",
"paths": {
"/path1": {
"post": {
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"example1": {
"description": "example1 description",
"externalValue": "./ex.json",
"value": {
"prop1": "value1",
"prop2": "value2"
}
}
}
}
}
}
}
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prop1": "value1",
"prop2": "value2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"post": {
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"example1": {
"description": "example1 description",
"externalValue": "./ex.json"
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"openapi": "3.1.0",
"paths": {
"/path1": {
"$ref": "./path-item.json"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ describe('dereference', function () {
});
});

context(
'given Example Object is inside externally referenced Path Item Object',
function () {
const fixturePath = path.join(rootFixturePath, 'external-value-path-item-ref');

specify('should dereference', async function () {
const rootFilePath = path.join(fixturePath, 'root.json');
const actual = await dereference(rootFilePath, {
parse: { mediaType: mediaTypes.latest('json') },
});
const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json'));

assert.deepEqual(toValue(actual), expected);
});
},
);

context('given both value and externalValue fields are defined', function () {
const fixturePath = path.join(rootFixturePath, 'external-value-value-both-defined');

Expand Down