Skip to content

Commit 9c651ea

Browse files
committed
changed format of options
1 parent d7bb66c commit 9c651ea

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@typescript-eslint/parser": "^5.31.0",
4444
"c8": "^7.12.0",
4545
"coveralls": "^3.1.1",
46-
"eslint": "^8.20.0",
46+
"eslint": "^8.21.0",
4747
"eslint-config-prettier": "^8.5.0",
4848
"eslint-plugin-prettier": "^4.2.1",
4949
"eslint-plugin-unused-imports": "^2.0.0",

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const convert = async <T = JSONSchema>(
5858
const {
5959
cloneSchema = true,
6060
dereference = false,
61-
useRefIfCycleFound = true,
61+
dereferenceOptions,
6262
} = options || {};
6363
let schemaToUse = schema as SchemaType;
6464

@@ -69,11 +69,7 @@ const convert = async <T = JSONSchema>(
6969
const parser = new RefParser();
7070
if (dereference) {
7171
// We run the risk of circular references here
72-
const res = await parser.dereference(schema, {
73-
dereference: {
74-
circular: useRefIfCycleFound ? 'ignore' : true,
75-
},
76-
});
72+
const res = await parser.dereference(schema, dereferenceOptions || {});
7773
schemaToUse = res as SchemaType;
7874
}
7975

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { JSONSchema } from '@apidevtools/json-schema-ref-parser';
2+
import type $RefParser from '@apidevtools/json-schema-ref-parser';
23

34
export type addPrefixToObject<T> = {
45
[K in keyof JSONSchema as `x-${K}`]: JSONSchema[K];
@@ -7,7 +8,7 @@ export type addPrefixToObject<T> = {
78
export interface Options {
89
cloneSchema?: boolean;
910
dereference?: boolean;
10-
useRefIfCycleFound?: boolean;
11+
dereferenceOptions?: $RefParser.Options;
1112
}
1213
type ExtendedJSONSchema = addPrefixToObject<JSONSchema> & JSONSchema;
1314
export type SchemaType = ExtendedJSONSchema & {

test/circular_schema.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ it(`converts ${test}/openapi.json`, async ({ expect }) => {
66
const schema = getSchema(test + '/json-schema.json');
77
const result = await convert(schema, {
88
dereference: true,
9+
dereferenceOptions: { dereference: { circular: 'ignore' } },
910
});
1011
const expected = getSchema(test + '/openapi.json');
1112
expect(result).toEqual(expected);
@@ -16,6 +17,7 @@ it(`converting ${test}/openapi.json in place`, async ({ expect }) => {
1617
const result = await convert(schema, {
1718
cloneSchema: false,
1819
dereference: true,
20+
dereferenceOptions: { dereference: { circular: 'ignore' } },
1921
});
2022
const expected = getSchema(test + '/openapi.json');
2123
expect(schema).toEqual(result);
@@ -28,7 +30,6 @@ it(`converting ${test}/openapi.json without circular references turned off `, as
2830
const schema = getSchema(test + '/json-schema.json');
2931
const result = await convert(schema, {
3032
cloneSchema: false,
31-
useRefIfCycleFound: false,
3233
dereference: true,
3334
});
3435
expect(result).toMatchSnapshot();

0 commit comments

Comments
 (0)