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

Conversation

gwagjiug
Copy link

@gwagjiug gwagjiug commented Apr 16, 2025

PR Description

Changes

  1. Refactored createRef and parseRef functions:

Added validation to ensure createRef accepts an array and is not empty.

Improved error handling for parseRef to check if the reference string starts with #/.

  1. Error Handling:

Both functions now throw detailed error messages when invalid inputs are provided, making debugging easier.

Why is this change needed?

The validation ensures the functions behave correctly, providing meaningful feedback when invalid input is passed.

This change improves the robustness of the SchemaComponentsMap class and provides better developer experience by catching errors earlier.

Copy link

changeset-bot bot commented Apr 16, 2025

⚠️ No Changeset found

Latest commit: 43e0d11

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@smorimoto smorimoto requested a review from Copilot April 24, 2025 13:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the createRef and parseRef functions to improve input validation and error handling.

  • Added array type and empty check validations for createRef.
  • Improved ref format check and detailed error messaging in parseRef.
Comments suppressed due to low confidence (2)

src/schema-components-map.ts:17

  • [nitpick] Consider using a custom error class or a centralized error handler to provide more consistent and actionable error messages across similar functions.
if (!Array.isArray(paths)) {

src/schema-components-map.ts:27

  • [nitpick] For consistency with the createRef function, consider unifying the error handling strategy by possibly reusing the same error construct or message formatting.
if (!ref.startsWith("#/")) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant