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 @@ -30,7 +30,7 @@ class SecurityVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) {

if (isReferenceLikeElement(item)) {
element = this.toRefractedElement(['document', 'objects', 'Reference'], item);
element.setMetaProperty('referenced-element', 'operationSecurity');
element.setMetaProperty('referenced-element', 'securityScheme');
} else {
element = this.toRefractedElement(['document', 'objects', 'SecurityScheme'], item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SecurityVisitor extends Mixin(SpecificationVisitor, FallbackVisitor) {

if (isReferenceLikeElement(item)) {
element = this.toRefractedElement(['document', 'objects', 'Reference'], item);
element.setMetaProperty('referenced-element', 'serverSecurity');
element.setMetaProperty('referenced-element', 'securityScheme');
} else {
element = this.toRefractedElement(['document', 'objects', 'SecurityScheme'], item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"asyncapi": "3.0.0",
"components": {
"securitySchemes": {
"scheme1": {
"type": "apiKey"
},
"scheme2": {
"type": "apiKey"
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"asyncapi": "3.0.0",
"components": {
"securitySchemes": {
"scheme1": {
"type": "apiKey"
},
"scheme2": {
"$ref": "#/components/securitySchemes/scheme1"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[{
"asyncapi": "3.0.0",
"components": {
"operations": {
"operation1": {
"security": [{
"type": "string"
}]
},
"operation2": {
"security": [{
"type": "string"
}]
}
}
}
}]

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"asyncapi": "3.0.0",
"components": {
"operations": {
"operation1": {
"security": [{
"type": "string"
}]
},
"operation2": {
"security": [{
"$ref": "#/components/operations/operation1/security/0"
}]
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[{
"asyncapi": "3.0.0",
"components": {
"operationTraits": {
"operationTrait1": {
"security": [{
"type": "apiKey"
}]
},
"operationTrait2": {
"security": [{
"type": "apiKey"
}]
}
}
}
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"asyncapi": "3.0.0",
"components": {
"operationTraits": {
"operationTrait1": {
"security": [{
"type": "apiKey"
}]
},
"operationTrait2": {
"security": [{
"$ref": "#/components/operationTraits/operationTrait1/security/0"
}]
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[{
"asyncapi": "3.0.0",
"servers": {
"server1": {
"security": [{ "type": "apiKey"}]
},
"server2": {
"security": [{ "type": "apiKey"}]
}
}
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"asyncapi": "3.0.0",
"servers": {
"server1": {
"security": [{ "$ref": "#/servers/server2/security/0" }]
},
"server2": {
"security": [{ "type": "apiKey" }]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import path from 'node:path';
import { assert } from 'chai';
import { toValue } from '@swagger-api/apidom-core';
import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-3';
import { fileURLToPath } from 'node:url';

import { loadJsonFile } from '../../../../helpers.ts';
import { dereference } from '../../../../../src/index.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootFixturePath = path.join(__dirname, 'fixtures');

describe('dereference', function () {
context('strategies', function () {
context('asyncapi-3', function () {
context('Security Scheme Object', function () {
context('given in components/securitySchemes field', function () {
const fixturePath = path.join(rootFixturePath, 'components-security-schemes');

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 in servers/security field', function () {
const fixturePath = path.join(rootFixturePath, 'server-object');

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 in operation/security field', function () {
const fixturePath = path.join(rootFixturePath, 'operation-object');

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 in operationTraits/security field', function () {
const fixturePath = path.join(rootFixturePath, 'operation-trait-object');

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);
});
});
});
});
});
});