Skip to content

Commit 92d53f0

Browse files
feat(apidom-converter): add infoSummaryRefractorPlugin
This plugin removes the summary fixed field of Info Object. Refs #3697
1 parent 3334c6b commit 92d53f0

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

packages/apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import securitySchemeTypeRefractorPlugin from './refractor-plugins/security-sche
2222
import securityRequirementsEmptyRolesRefractorPlugin from './refractor-plugins/security-requirements-empty-roles';
2323
import type { ConverterOptions } from '../../options';
2424
import createToolbox from './toolbox';
25+
import infoSummaryRefractorPlugin from './refractor-plugins/info-summary';
2526

2627
// eslint-disable-next-line @typescript-eslint/naming-convention
2728
const openAPI3_0_3MediaTypes = [
@@ -63,6 +64,7 @@ class OpenAPI31ToOpenAPI30ConvertStrategy extends ConvertStrategy {
6364
webhooksRefractorPlugin({ annotations }),
6465
securitySchemeTypeRefractorPlugin({ annotations }),
6566
securityRequirementsEmptyRolesRefractorPlugin({ annotations }),
67+
infoSummaryRefractorPlugin({ annotations }),
6668
],
6769
{
6870
toolboxCreator: createToolbox,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { InfoElement } from '@swagger-api/apidom-ns-openapi-3-1';
2+
import { AnnotationElement } from '@swagger-api/apidom-core';
3+
4+
type InfoSummaryPluginOptions = {
5+
annotations: AnnotationElement[];
6+
};
7+
8+
const infoSummaryRefractorPlugin =
9+
({ annotations }: InfoSummaryPluginOptions) =>
10+
() => {
11+
const annotation = new AnnotationElement(
12+
'The "summary" field of Info Object is not supported in OpenAPI 3.0.3. It has been removed from the converted document.',
13+
{ classes: ['warning'] },
14+
{ code: 'info-summary' },
15+
);
16+
17+
return {
18+
visitor: {
19+
InfoElement(element: InfoElement) {
20+
if (!element.hasKey('summary')) return undefined;
21+
22+
annotations.push(annotation);
23+
element.remove('summary');
24+
25+
return undefined;
26+
},
27+
},
28+
};
29+
};
30+
31+
export default infoSummaryRefractorPlugin;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`converter strategies openapi-3-1-to-openapi-3-0-3 info-summary should remove Info.summary field 1`] = `
4+
{
5+
"openapi": "3.0.3",
6+
"info": {
7+
"version": "1.0.0",
8+
"title": "A title"
9+
}
10+
}
11+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "A title",
6+
"summary": "A short summary"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import path from 'node:path';
2+
import { expect, assert } from 'chai';
3+
import { mediaTypes as openAPI31MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1';
4+
import { mediaTypes as openAPI30MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-0';
5+
import {
6+
AnnotationElement,
7+
ParseResultElement,
8+
toJSON,
9+
includesClasses,
10+
} from '@swagger-api/apidom-core';
11+
12+
import convert from '../../../../../src';
13+
14+
describe('converter', function () {
15+
context('strategies', function () {
16+
context('openapi-3-1-to-openapi-3-0-3', function () {
17+
context('info-summary', function () {
18+
const fixturePath = path.join(__dirname, 'fixtures', 'info-summary.json');
19+
let convertedParseResult: ParseResultElement;
20+
21+
beforeEach(async function () {
22+
convertedParseResult = await convert(fixturePath, {
23+
convert: {
24+
sourceMediaType: openAPI31MediaTypes.findBy('3.1.0', 'json'),
25+
targetMediaType: openAPI30MediaTypes.findBy('3.0.3', 'json'),
26+
},
27+
});
28+
});
29+
30+
specify('should remove Info.summary field', async function () {
31+
expect(toJSON(convertedParseResult.api!, undefined, 2)).toMatchSnapshot();
32+
});
33+
34+
specify('should create WARNING annotation', async function () {
35+
const annotations = Array.from(convertedParseResult.annotations);
36+
const annotation = annotations.find((a: AnnotationElement) =>
37+
a.code?.equals('info-summary'),
38+
);
39+
40+
assert.isDefined(annotation);
41+
assert.isTrue(includesClasses(['warning'], annotation));
42+
});
43+
});
44+
});
45+
});
46+
});

0 commit comments

Comments
 (0)