Skip to content

Commit a314eb5

Browse files
committed
feat(adapters): make adapters understand refractorOpts
Refs swagger-api/oss-planning#133
1 parent dc311e9 commit a314eb5

File tree

11 files changed

+54
-34
lines changed

11 files changed

+54
-34
lines changed

apidom/package-lock.json

+20-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('refractor', function () {
2525

2626
beforeEach(function () {
2727
plugin1Spec = {
28+
name: 'plugin1',
2829
pre() {},
2930
visitor: {
3031
AsyncApiVersion(element: AsyncApiVersionElement) {
@@ -35,6 +36,7 @@ describe('refractor', function () {
3536
post() {},
3637
};
3738
plugin2Spec = {
39+
name: 'plugin2',
3840
pre() {},
3941
visitor: {
4042
AsyncApiVersion(element: AsyncApiVersionElement) {

apidom/packages/apidom-ns-openapi-3-1/test/refractor/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('refractor', function () {
2525

2626
beforeEach(function () {
2727
plugin1Spec = {
28+
name: 'plugin1',
2829
pre() {},
2930
visitor: {
3031
Openapi(element: OpenapiElement) {
@@ -35,6 +36,7 @@ describe('refractor', function () {
3536
post() {},
3637
};
3738
plugin2Spec = {
39+
name: 'plugin2',
3840
pre() {},
3941
visitor: {
4042
Openapi(element: OpenapiElement) {

apidom/packages/apidom-parser-adapter-asyncapi-json-2-0/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"license": "Apache-2.0",
2121
"dependencies": {
2222
"@babel/runtime-corejs3": "=7.12.5",
23+
"ramda": "=0.27.0",
24+
"@types/ramda": "=0.27.6",
2325
"apidom": "file:../apidom",
2426
"apidom-ns-asyncapi-2-0": "file:../apidom-ns-asyncapi-2-0",
2527
"apidom-parser-adapter-json": "file:../apidom-parser-adapter-json"

apidom/packages/apidom-parser-adapter-asyncapi-json-2-0/src/adapter.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { propOr, omit } from 'ramda';
12
import { isObjectElement, ParseResultElement, createNamespace } from 'apidom';
23
// @ts-ignore
34
import { parse as parseJson } from 'apidom-parser-adapter-json';
@@ -15,11 +16,13 @@ export const parse = async (
1516
source: string,
1617
options: Record<string, unknown> = {},
1718
): Promise<ParseResultElement> => {
18-
const parseResultElement = await parseJson(source, options);
19+
const refractorOpts = propOr({}, 'refractorOpts');
20+
const parserOpts = omit(['refractorOpts'], options);
21+
const parseResultElement = await parseJson(source, parserOpts);
1922

2023
// refract first element in parse result into OpenApi3_1 element
2124
if (isObjectElement(parseResultElement.get(0))) {
22-
const asyncApiElement = AsyncApi2_0Element.refract(parseResultElement.get(0));
25+
const asyncApiElement = AsyncApi2_0Element.refract(parseResultElement.get(0), refractorOpts);
2326
parseResultElement.set(0, asyncApiElement);
2427
}
2528

apidom/packages/apidom-parser-adapter-asyncapi-yaml-2-0/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"license": "Apache-2.0",
2121
"dependencies": {
2222
"@babel/runtime-corejs3": "=7.12.5",
23-
"@apidevtools/json-schema-ref-parser": "=9.0.3",
23+
"ramda": "=0.27.0",
24+
"@types/ramda": "=0.27.6",
2425
"apidom": "file:../apidom",
2526
"apidom-ns-asyncapi-2-0": "file:../apidom-ns-asyncapi-2-0",
2627
"apidom-parser-adapter-yaml-1-2": "file:../apidom-parser-adapter-yaml-1-2"

apidom/packages/apidom-parser-adapter-asyncapi-yaml-2-0/src/adapter.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { omit, propOr } from 'ramda';
12
import { Element, NumberElement, ParseResultElement, createNamespace } from 'apidom';
23
// @ts-ignore
34
import { parse as parseYaml } from 'apidom-parser-adapter-yaml-1-2';
@@ -18,14 +19,16 @@ export const parse = async (
1819
source: string,
1920
options: Record<string, unknown> = {},
2021
): Promise<ParseResultElement> => {
21-
const parseResultElement = await parseYaml(source, options);
22+
const refractorOpts = propOr({}, 'refractorOpts');
23+
const parserOpts = omit(['refractorOpts'], options);
24+
const parseResultElement = await parseYaml(source, parserOpts);
2225
const results = parseResultElement.findElements(isAsyncApi2_0LikeElement, {
2326
recursive: false,
2427
});
2528

2629
if (results.length > 0) {
2730
const asyncApiLikeElement = results[0];
28-
const asyncApiElement = AsyncApi2_0Element.refract(asyncApiLikeElement);
31+
const asyncApiElement = AsyncApi2_0Element.refract(asyncApiLikeElement, refractorOpts);
2932
let index = 0;
3033

3134
parseResultElement.forEach((element: Element, indexElement: NumberElement) => {

apidom/packages/apidom-parser-adapter-openapi-json-3-1/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"license": "Apache-2.0",
2121
"dependencies": {
2222
"@babel/runtime-corejs3": "=7.12.5",
23+
"ramda": "=0.27.0",
24+
"@types/ramda": "=0.27.6",
2325
"apidom": "file:../apidom",
2426
"apidom-ns-openapi-3-1": "file:../apidom-ns-openapi-3-1",
2527
"apidom-parser-adapter-json": "file:../apidom-parser-adapter-json"

apidom/packages/apidom-parser-adapter-openapi-json-3-1/src/adapter.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import openApiNamespace, { OpenApi3_1Element } from 'apidom-ns-openapi-3-1';
1+
import { propOr, omit } from 'ramda';
2+
import { ParseResultElement, isObjectElement, createNamespace } from 'apidom';
23
// @ts-ignore
34
import { parse as parseJson } from 'apidom-parser-adapter-json';
4-
import { ParseResultElement, isObjectElement, createNamespace } from 'apidom';
5+
import openApiNamespace, { OpenApi3_1Element } from 'apidom-ns-openapi-3-1';
56

67
export const mediaTypes = [
78
'application/vnd.oai.openapi;version=3.1.0',
@@ -15,11 +16,13 @@ export const parse = async (
1516
source: string,
1617
options: Record<string, unknown> = {},
1718
): Promise<ParseResultElement> => {
18-
const parseResultElement = await parseJson(source, options);
19+
const refractorOpts = propOr({}, 'refractorOpts');
20+
const parserOpts = omit(['refractorOpts'], options);
21+
const parseResultElement = await parseJson(source, parserOpts);
1922

2023
// refract first element in parse result into OpenApi3_1 element
2124
if (isObjectElement(parseResultElement.get(0))) {
22-
const openApiElement = OpenApi3_1Element.refract(parseResultElement.get(0));
25+
const openApiElement = OpenApi3_1Element.refract(parseResultElement.get(0), refractorOpts);
2326
parseResultElement.set(0, openApiElement);
2427
}
2528

apidom/packages/apidom-parser-adapter-openapi-yaml-3-1/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"license": "Apache-2.0",
2121
"dependencies": {
2222
"@babel/runtime-corejs3": "=7.12.5",
23+
"ramda": "=0.27.0",
24+
"@types/ramda": "=0.27.6",
2325
"apidom": "file:../apidom",
2426
"apidom-ns-openapi-3-1": "file:../apidom-ns-openapi-3-1",
2527
"apidom-parser-adapter-yaml-1-2": "file:../apidom-parser-adapter-yaml-1-2"

apidom/packages/apidom-parser-adapter-openapi-yaml-3-1/src/adapter.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { propOr, omit } from 'ramda';
12
import { Element, NumberElement, ParseResultElement, createNamespace } from 'apidom';
23
// @ts-ignore
34
import { parse as parseYaml } from 'apidom-parser-adapter-yaml-1-2';
@@ -18,14 +19,16 @@ export const parse = async (
1819
source: string,
1920
options: Record<string, unknown> = {},
2021
): Promise<ParseResultElement> => {
21-
const parseResultElement = await parseYaml(source, options);
22+
const refractorOpts = propOr({}, 'refractorOpts');
23+
const parserOpts = omit(['refractorOpts'], options);
24+
const parseResultElement = await parseYaml(source, parserOpts);
2225
const results = parseResultElement.findElements(isOpenApi3_1LikeElement, {
2326
recursive: false,
2427
});
2528

2629
if (results.length > 0) {
2730
const openApiLikeElement = results[0];
28-
const openApiElement = OpenApi3_1Element.refract(openApiLikeElement);
31+
const openApiElement = OpenApi3_1Element.refract(openApiLikeElement, refractorOpts);
2932
let index = 0;
3033

3134
parseResultElement.forEach((element: Element, indexElement: NumberElement) => {

0 commit comments

Comments
 (0)