Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit c2d00ec

Browse files
committed
feat(oas3): added cookie support for apiKey security scheme
1 parent 3872ffa commit c2d00ec

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/fury-adapter-oas3-parser/lib/parser/oas/parseSecuritySchemeObject.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const isHttpScheme = securityScheme => securityScheme.getValue('type') === 'http
2424
const isValidTypeValue = R.anyPass(R.map(hasValue, ['apiKey', 'http', 'oauth2', 'openIdConnect']));
2525
const isSupportedType = R.anyPass(R.map(hasValue, ['apiKey', 'http', 'oauth2']));
2626
const isValidInValue = R.anyPass(R.map(hasValue, ['query', 'header', 'cookie']));
27-
const isSupportedIn = R.anyPass(R.map(hasValue, ['query', 'header']));
2827

2928
function validateApiKeyScheme(context, securityScheme) {
3029
const { namespace } = context;
@@ -35,14 +34,9 @@ function validateApiKeyScheme(context, securityScheme) {
3534
);
3635
const validateIn = R.unless(isValidInValue, createInvalidInWarning);
3736

38-
const createUnsupportedInWarning = member => createWarning(namespace,
39-
`'${name}' 'in' '${member.value.toValue()}' is unsupported`, member.value);
40-
const ensureSupportedIn = R.unless(isSupportedIn, createUnsupportedInWarning);
41-
4237
const parseIn = pipeParseResult(namespace,
4338
parseString(context, name, false),
44-
validateIn,
45-
ensureSupportedIn);
39+
validateIn);
4640

4741
const parseMember = R.cond([
4842
[hasKey('name'), parseString(context, name, false)],
@@ -136,6 +130,8 @@ function parseSecuritySchemeObject(context, object) {
136130
key = 'httpHeaderName';
137131
} else if (inValue === 'query') {
138132
key = 'queryParameterName';
133+
} else if (inValue === 'cookie') {
134+
key = 'cookieName';
139135
}
140136

141137
authScheme.push(new namespace.elements.Member(key, securityScheme.get('name')));

packages/fury-adapter-oas3-parser/test/unit/parser/oas/parseSecuritySchemeObject-test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ describe('Security Scheme Object', () => {
221221
expect(members.get(0).value.toValue()).to.equal('example');
222222
});
223223

224-
it('provides warning about unsupported cookie', () => {
224+
it('parses correctly when in a cookie', () => {
225225
const securityScheme = new namespace.elements.Object({
226226
type: 'apiKey',
227227
name: 'example',
@@ -231,7 +231,14 @@ describe('Security Scheme Object', () => {
231231
const parseResult = parse(context, securityScheme);
232232

233233
expect(parseResult.length).to.equal(1);
234-
expect(parseResult).to.contain.warning("'Security Scheme Object' 'in' 'cookie' is unsupported");
234+
expect(parseResult.get(0)).to.be.instanceof(namespace.elements.AuthScheme);
235+
expect(parseResult.get(0).element).to.equal('Token Authentication Scheme');
236+
237+
const { members } = parseResult.get(0);
238+
239+
expect(members.length).to.equal(1);
240+
expect(members.get(0).key.toValue()).to.equal('cookieName');
241+
expect(members.get(0).value.toValue()).to.equal('example');
235242
});
236243

237244
it('does not complain about scheme', () => {

0 commit comments

Comments
 (0)