Skip to content

Commit

Permalink
fix(core): resolve value on readonly avoid infinite loop on multi fil…
Browse files Browse the repository at this point in the history
…es refs
  • Loading branch information
anymaniax committed Apr 12, 2023
1 parent e91cb79 commit 05c966f
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions packages/core/src/resolvers/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getScalar } from '../getters';
import { ContextSpecs, ResolverValue, SchemaType } from '../types';
import { isReference } from '../utils';
import { resolveRef } from './ref';
import { resolveObject } from './object';

export const resolveValue = ({
schema,
Expand All @@ -20,22 +19,48 @@ export const resolveValue = ({
context,
);

const resolvedObject = resolveObject({ schema: schemaObject, context });

const { name, specKey, schemaName } = imports[0];
const resolvedImport = imports[0];

const importSpecKey =
specKey ||
resolvedImport.specKey ||
(context.specKey !== context.target ? context.specKey : undefined);

let hasReadonlyProps = false;

const spec = context.specs[context.specKey];

// Avoid infinite loop
if (
name &&
!name.startsWith(resolvedImport.name) &&
!spec?.components?.schemas?.[name]
) {
const scalar = getScalar({
item: schemaObject,
name: resolvedImport.name,
context: {
...context,
specKey: importSpecKey || context.specKey,
},
});

hasReadonlyProps = scalar.hasReadonlyProps;
}

return {
value: name,
imports: [{ name, specKey: importSpecKey, schemaName }],
value: resolvedImport.name,
imports: [
{
name: resolvedImport.name,
specKey: importSpecKey,
schemaName: resolvedImport.schemaName,
},
],
type: (schemaObject?.type as SchemaType) || 'object',
schemas: [],
isEnum: !!schemaObject?.enum,
originalSchema: schemaObject,
hasReadonlyProps: resolvedObject.hasReadonlyProps,
hasReadonlyProps,
isRef: true,
};
}
Expand Down

1 comment on commit 05c966f

@vercel
Copy link

@vercel vercel bot commented on 05c966f Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.