Skip to content

Commit

Permalink
fix(core): fix ref import file (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiev-anton authored Oct 19, 2023
1 parent a4cca88 commit 69280a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions packages/core/src/resolvers/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ function getSchema<Schema extends ComponentObject = ComponentObject>(
} {
const refInfo = getRefInfo(schema.$ref, context);

const { specKey, refPaths } = refInfo;
const { specKey, refPaths = [] } = refInfo;

const schemaByRefPaths: Schema | undefined =
refPaths && get(context.specs[specKey || context.specKey], refPaths);
let schemaByRefPaths: Schema | undefined = get(
context.specs[context.specKey],
refPaths,
);
if (!schemaByRefPaths) {
schemaByRefPaths = context.specs?.[
specKey || context.specKey
] as unknown as Schema;
}
if (isReference(schemaByRefPaths)) {
return getSchema(schemaByRefPaths, context);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { extname } from './path';
* @param property
*/
export const isReference = (property: any): property is ReferenceObject => {
return Boolean(property.$ref);
return Boolean(property?.$ref);
};

export const isDirectory = (path: string) => {
Expand Down

1 comment on commit 69280a3

@vercel
Copy link

@vercel vercel bot commented on 69280a3 Oct 19, 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.