Skip to content

Add Hook Interface for Customizable XSD Parsing and Code Generation#111

Closed
eleenmohd-wk wants to merge 11 commits intoxuri:masterfrom
raduionita-wk:ri/compact-and-hook
Closed

Add Hook Interface for Customizable XSD Parsing and Code Generation#111
eleenmohd-wk wants to merge 11 commits intoxuri:masterfrom
raduionita-wk:ri/compact-and-hook

Conversation

@eleenmohd-wk
Copy link
Contributor

@eleenmohd-wk eleenmohd-wk commented Oct 28, 2025

PR Details

This PR introduces am optional plugin system via the Hook interface that allows users to customize the XSD parsing and code generation process without modifying xgen's core logic.

There are 5 interception points:

  • OnStartElement: Intercept XML start elements during parsing
  • OnEndElement: Intercept XML end elements during parsing
  • OnCharData: Intercept character data/text content during parsing
  • OnGenerate: Intercept code generation before each type is processed
  • OnAddContent: Post-process generated code content

During XML parsing (parsing.go), the hook intercepts the XML token stream before xgen processes it. Each hook method returns a next boolean - if false, xgen skips that element, allowing custom filtering or preprocessing.

The hook intercepts code generation (genGo.go) at two points:

  1. Before generating code for each type (OnGenerate): Can skip generating specific types by returning false
  2. After generating each code block (OnAddContent): Receives a pointer to the generated code string. Can modify, enhance, or replace the generated code

Description

Adds Parser.Hooks map[string]Hook for handling custom logic on specific elements

Related Issue

Motivation and Context

expands functionality w/o major changes to the core code. the hook is optional and all existing code continues to work without modification so there's no changes in the existing functionality

How Has This Been Tested

unit tests

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 55.38462% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.94%. Comparing base (2cb22a3) to head (9fb581e).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
genGo.go 61.90% 8 Missing and 8 partials ⚠️
parser.go 43.47% 7 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #111      +/-   ##
==========================================
+ Coverage   81.92%   82.94%   +1.02%     
==========================================
  Files          37       37              
  Lines        1870     1636     -234     
==========================================
- Hits         1532     1357     -175     
+ Misses        246      174      -72     
- Partials       92      105      +13     
Flag Coverage Δ
unittests 82.94% <55.38%> (+1.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xuri xuri added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants