Skip to content

refactor: createRef and parseRef with Improved Error Handling and Validation #1178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/schema-components-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ export class SchemaComponentsMap {
}

createRef = (paths: string[]) => {
if (!Array.isArray(paths)) {
throw new Error(`Expected an array, but received: ${typeof paths}`);
}
if (paths.length === 0) {
throw new Error("Paths array cannot be empty.");
}
return ["#", ...paths].join("/");
};

parseRef = (ref: string) => {
if (!ref.startsWith("#/")) {
throw new Error(`Invalid ref format: ${ref}. It should start with "#/"`);
}
return ref.split("/");
};

Expand Down