Add Hook Interface for Customizable XSD Parsing and Code Generation#114
Merged
xuri merged 21 commits intoxuri:masterfrom Nov 17, 2025
Merged
Add Hook Interface for Customizable XSD Parsing and Code Generation#114xuri merged 21 commits intoxuri:masterfrom
xuri merged 21 commits intoxuri:masterfrom
Conversation
…used dependency from go.mod
Add Hook Interface for Customizable XSD Parsing and Code Generation
- Add TestOnAddContentCoverage to test OnAddContent calls across different type generators - Add TestOnAddContentForAllTypes to verify hook integration with existing fixtures - Create hook-coverage.xsd fixture to exercise SimpleType (list/union/basic), ComplexType, Group, and AttributeGroup generators - These tests cover lines 162, 190, 203, 282, 323, and 351 in genGo.go - Ensures all OnAddContent hook calls are properly tested and can modify generated code
Contributor
Author
|
@xuri Im not sure why you're not getting assigned as a reviewer to my PR. I tried to close it and reopen it, but it's still not working. Do you think you can take a look at these changes? |
|
@xuri friendly bump: would you be able to take a look at this PR? |
xuri
approved these changes
Nov 17, 2025
Owner
xuri
left a comment
There was a problem hiding this comment.
Great work! Thanks for your contribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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:
Description
Adds Parser.Hooks
map[string]Hookfor handling custom logic on specific elementsRelated 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
Checklist