Skip to content

Commit 05c966f

Browse files
committedApr 12, 2023
fix(core): resolve value on readonly avoid infinite loop on multi files refs
1 parent e91cb79 commit 05c966f

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed
 

‎packages/core/src/resolvers/value.ts

+33-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { getScalar } from '../getters';
33
import { ContextSpecs, ResolverValue, SchemaType } from '../types';
44
import { isReference } from '../utils';
55
import { resolveRef } from './ref';
6-
import { resolveObject } from './object';
76

87
export const resolveValue = ({
98
schema,
@@ -20,22 +19,48 @@ export const resolveValue = ({
2019
context,
2120
);
2221

23-
const resolvedObject = resolveObject({ schema: schemaObject, context });
24-
25-
const { name, specKey, schemaName } = imports[0];
22+
const resolvedImport = imports[0];
2623

2724
const importSpecKey =
28-
specKey ||
25+
resolvedImport.specKey ||
2926
(context.specKey !== context.target ? context.specKey : undefined);
3027

28+
let hasReadonlyProps = false;
29+
30+
const spec = context.specs[context.specKey];
31+
32+
// Avoid infinite loop
33+
if (
34+
name &&
35+
!name.startsWith(resolvedImport.name) &&
36+
!spec?.components?.schemas?.[name]
37+
) {
38+
const scalar = getScalar({
39+
item: schemaObject,
40+
name: resolvedImport.name,
41+
context: {
42+
...context,
43+
specKey: importSpecKey || context.specKey,
44+
},
45+
});
46+
47+
hasReadonlyProps = scalar.hasReadonlyProps;
48+
}
49+
3150
return {
32-
value: name,
33-
imports: [{ name, specKey: importSpecKey, schemaName }],
51+
value: resolvedImport.name,
52+
imports: [
53+
{
54+
name: resolvedImport.name,
55+
specKey: importSpecKey,
56+
schemaName: resolvedImport.schemaName,
57+
},
58+
],
3459
type: (schemaObject?.type as SchemaType) || 'object',
3560
schemas: [],
3661
isEnum: !!schemaObject?.enum,
3762
originalSchema: schemaObject,
38-
hasReadonlyProps: resolvedObject.hasReadonlyProps,
63+
hasReadonlyProps,
3964
isRef: true,
4065
};
4166
}

1 commit comments

Comments
 (1)

vercel[bot] commented on Apr 12, 2023

@vercel[bot]
Please sign in to comment.