-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apidom-converter): add securitySchemeTypeRefractorPlugin
- Loading branch information
1 parent
6e1fe1c
commit 13a3737
Showing
5 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ter/src/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { SecuritySchemeElement } from '@swagger-api/apidom-ns-openapi-3-1'; | ||
import { AnnotationElement } from '@swagger-api/apidom-core'; | ||
|
||
type SecuritySchemeTypePluginOptions = { | ||
annotations: AnnotationElement[]; | ||
}; | ||
|
||
const securitySchemeTypeRefractorPlugin = | ||
({ annotations }: SecuritySchemeTypePluginOptions) => | ||
() => ({ | ||
visitor: { | ||
SecuritySchemeElement(element: SecuritySchemeElement) { | ||
if (element.get('type')?.toValue() === 'mutualTLS') { | ||
const annotation = new AnnotationElement( | ||
'"mutualTLS" type is not supported in OpenAPI 3.0.3.', | ||
{ classes: ['warning'] }, | ||
{ code: 'mutualTLS' }, | ||
); | ||
|
||
annotations.push(annotation); | ||
} | ||
|
||
return element; | ||
}, | ||
}, | ||
}); | ||
|
||
export default securitySchemeTypeRefractorPlugin; |
21 changes: 21 additions & 0 deletions
21
...i-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`converter strategies openapi-3-1-to-openapi-3-0-3 security-scheme-type converted definition should remain the same 1`] = ` | ||
{ | ||
"openapi": "3.0.3", | ||
"components": { | ||
"securitySchemes": { | ||
"mutualTLS": { | ||
"type": "mutualTLS", | ||
"name": "mutualTLS", | ||
"in": "header" | ||
}, | ||
"apiKey": { | ||
"type": "apiKey", | ||
"name": "api_key", | ||
"in": "header" | ||
} | ||
} | ||
} | ||
} | ||
`; |
17 changes: 17 additions & 0 deletions
17
...o-openapi-3-0-3/refractor-plugins/security-scheme-type/fixtures/security-scheme-type.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"securitySchemes": { | ||
"mutualTLS": { | ||
"type": "mutualTLS", | ||
"name": "mutualTLS", | ||
"in": "header" | ||
}, | ||
"apiKey": { | ||
"type": "apiKey", | ||
"name": "api_key", | ||
"in": "header" | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...t/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import path from 'node:path'; | ||
import { mediaTypes as openAPI31MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1'; | ||
import { mediaTypes as openAPI30MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-0'; | ||
import { AnnotationElement, includesClasses, toJSON } from '@swagger-api/apidom-core'; | ||
import { assert, expect } from 'chai'; | ||
|
||
import convert from '../../../../../src'; | ||
|
||
describe('converter', function () { | ||
context('strategies', function () { | ||
context('openapi-3-1-to-openapi-3-0-3', function () { | ||
context('security-scheme-type', function () { | ||
specify('converted definition should remain the same', async function () { | ||
const fixturePath = path.join(__dirname, 'fixtures', 'security-scheme-type.json'); | ||
const convertedParseResult = await convert(fixturePath, { | ||
convert: { | ||
sourceMediaType: openAPI31MediaTypes.findBy('3.1.0', 'json'), | ||
targetMediaType: openAPI30MediaTypes.findBy('3.0.3', 'json'), | ||
}, | ||
}); | ||
|
||
expect(toJSON(convertedParseResult.api!, undefined, 2)).toMatchSnapshot(); | ||
}); | ||
|
||
specify('should create WARNING annotation', async function () { | ||
const fixturePath = path.join(__dirname, 'fixtures', 'security-scheme-type.json'); | ||
const convertedParseResult = await convert(fixturePath, { | ||
convert: { | ||
sourceMediaType: openAPI31MediaTypes.findBy('3.1.0', 'json'), | ||
targetMediaType: openAPI30MediaTypes.findBy('3.0.3', 'json'), | ||
}, | ||
}); | ||
const annotations = Array.from(convertedParseResult.annotations); | ||
const annotation = annotations.find((a: AnnotationElement) => | ||
a.code?.equals('mutualTLS'), | ||
); | ||
|
||
assert.isDefined(annotation); | ||
assert.lengthOf(annotations, 1); | ||
assert.isTrue(includesClasses(['warning'], annotation)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |