Skip to content

Refactor: Minor safety and modernization updates in processSchema#34

Open
Manas-Dikshit wants to merge 13 commits intowebpack:mainfrom
Manas-Dikshit:main
Open

Refactor: Minor safety and modernization updates in processSchema#34
Manas-Dikshit wants to merge 13 commits intowebpack:mainfrom
Manas-Dikshit:main

Conversation

@Manas-Dikshit
Copy link
Copy Markdown

@Manas-Dikshit Manas-Dikshit commented Mar 2, 2026

Changes

  • Null and type checks (!json || typeof json !== 'object') have been added for improved recursion safety.
  • Optional chaining (visitor?.method) has been used instead of potentially throwing an error.
  • Object.keys() has replaced the use of for...in for enhanced compatibility.
  • !Array.isArray() checks have been included for object expectations.

Impact

  • No breaking changes have been made.
  • Improved error safety and code clarity.
  • Identical functionality remains for backward compatibility.
  • Compatible with modern Node.js runtimes and linting configurations.

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Is this AI generated code?

@Manas-Dikshit
Copy link
Copy Markdown
Author

Hey @alexander-akait — I used AI assistance mainly for syntax suggestions and safety checks, but the logic and final implementation were manually reviewed and tested by me. It’s fully aligned with the existing behavior.
Screenshot 2026-03-03 173154
Screenshot 2026-03-03 173214
These are AI assisted.

If there is any mistakes or logic fall in the refined code then kindly suggest the changes.

Updated JSDoc comments for better clarity and added type definitions.
Updated type definitions for SchemaVisitor and parameters in the processSchema function to use JSONSchema.
Updated comments for clarity and restructured constant definitions for nested schema traversal.
* @typedef {Object} SchemaVisitor
* @property {(schema: JSONSchema | boolean, context?: ProcessContext) => JSONSchema | boolean | void} [schema]
* @property {(obj: JSONSchema | boolean, context?: ProcessContext) => JSONSchema | boolean | void} [object]
* @property {(arr: (JSONSchema | boolean)[], context?: ProcessContext) => void} [array]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just interesting why we have boolean here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. JSON Schema allows boolean schemas, but instead of manually adding boolean I can switch to JSONSchema7Definition from json-schema types which already includes it.
can i ?
@alexander-akait

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We support more than JSONSchema7, it should be support old formats too

Copy link
Copy Markdown
Author

@Manas-Dikshit Manas-Dikshit Mar 12, 2026

Choose a reason for hiding this comment

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

what kind of changes the below code needs
Screenshot 2026-03-13 013743

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

/cc @bjohansebas Can you take a look at this too?

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.

2 participants