GeezerVison is showing github.com — XsdGenerator: emit mixed="true" on complexTypes with xml.format="mixed" fields by gnodet · Pull Request #628 · codehaus-plexus/modello
Conversation
gnodet
commented
Nov 8, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
When a Modello field is annotated with xml.format="mixed", the corresponding XML element accepts both free text and child elements. The XSD generator must reflect this with mixed="true" on the xs:complexType.
Two cases are handled:
-
Field with xml.format="mixed" and xml.tagName (wrapper element): the content lives inside the wrapper child element, so the anonymous xs:complexType written by writeListElement() gets mixed="true".
-
Field with xml.format="mixed" and no xml.tagName: the content is body text of the class element itself, so the named xs:complexType written by writeComplexTypeDescriptor() gets mixed="true". Fields with xml.tagName are explicitly excluded from this check because their mixed content lives inside a wrapper child element (case 1), not in the class body.
Without this fix, IDEs and XSD validators reject the inline text syntax even though the generated StAX reader accepts it correctly.
Discovered while working on gnodet/maven#139.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gnodet
added a commit
to gnodet/maven
that referenced
this pull request
Nov 8, 2026
…SD fix
The XSD for <options> and <alias> must carry mixed="true" on their
xs:complexType so that IDEs and schema validators accept both the inline
text syntax and the structured <arg>-child syntax documented for these
fields.
The fix is in codehaus-plexus/modello#628 (XsdGenerator: emit
mixed="true" for xml.format="mixed" fields). Pin to the SNAPSHOT until
that PR is released, then update to 2.8.2.
…d" fields
When a Modello field is annotated with xml.format="mixed", the
corresponding XML element accepts both free text and child elements.
The XSD generator must reflect this with mixed="true" on the
xs:complexType.
Two cases are handled:
1. Field with xml.format="mixed" and xml.tagName (wrapper element):
the content lives inside the wrapper child element, so the anonymous
xs:complexType written by writeListElement() gets mixed="true".
2. Field with xml.format="mixed" and no xml.tagName: the content is
body text of the class element itself, so the named xs:complexType
written by writeComplexTypeDescriptor() gets mixed="true". Fields
with xml.tagName are explicitly excluded from this check because their
mixed content lives inside a wrapper child element (case 1), not in
the class body.
Without this fix, IDEs and XSD validators reject the inline text syntax
even though the generated StAX reader accepts it correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix is correct — both code paths that emit mixed="true" are logically sound:
writeComplexTypeDescriptor: the guard m.getTagName() == null correctly excludes wrapper-element fields (Case 1), limiting mixed="true" to body-level class elements only (Case 2).
writeListElement: the anonymous xs:complexType inside a wrapper element correctly gets mixed="true" for xml.format="mixed" fields.
Null-safety is fine: getFormat() and getTagName() can both return null; the check uses "mixed".equals(...) and == null.
Missing test coverage. There is no test verifying the generated XSD. Consider adding a test model in modello-plugins/modello-plugin-xsd/src/test/resources/ with:
- a field annotated
xml.format="mixed" without xml.tagName (body-level / Case 2), and
- a field annotated
xml.format="mixed" with xml.tagName (wrapper / Case 1 — exercises writeListElement)
Then assert that mixed="true" appears on the class-level xs:complexType for the first case, and on the wrapper's inner xs:complexType for the second — and that it does not appear on unrelated xs:complexType elements.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add MixedContentXsdGeneratorTest to verify that the XSD generator
emits mixed="true" on the correct xs:complexType elements when a
field uses xml.format="mixed":
- Case 2 (body-level): a String field with xml.format="mixed" and
no xml.tagName triggers mixed="true" on the class-level named
xs:complexType (MixedBody).
- Case 1 (wrapper): a List field with xml.format="mixed" and an
explicit xml.tagName triggers mixed="true" on the anonymous
xs:complexType inside the wrapper element (MixedWrapper).
- Control: a class with no mixed field (Plain) must NOT get
mixed="true" on its xs:complexType.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up on my earlier review — the missing test coverage is now addressed. Good work adding both cases and a control assertion.
One issue in the new test:
assertNotNull(xsdFile, ...) does not check that the file was actually created. new File(path) never returns null — this assertion is always true whether the XSD was generated or not. A silent generation failure (e.g. wrong output directory) would leave the XSD file absent, doc = db.parse(xsdFile) would throw, and the error message would be "No such file or directory" instead of the intended "Generated XSD file must exist".
Replace with assertTrue(xsdFile.exists(), ...).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
xml-apis:2.0.2 is a phantom version that Maven relocates to 1.0.b2,
which does not include org.w3c.dom.ElementTraversal. The class is part
of the JDK since Java 9, so the test passes on JDK 9+, but fails on
JDK 8. The last real release containing ElementTraversal is 1.4.01.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous finding addressed — assertTrue(xsdFile.exists(), ...) is in place. LGTM.
Pre-fix validation: static trace confirms the test was failing before the fix — without w.addAttribute("mixed", "true"), the XPath finds 0 complexType nodes with mixed="true", causing assertEquals(1, 0) to fail on both assertions.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|