Repository navigation
XsdGenerator: emit mixed="true" on complexTypes with xml.format="mixed" fields - #628
Conversation
…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.
530c211 to
faff993
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
The fix is correct — both code paths that emit mixed="true" are logically sound:
writeComplexTypeDescriptor: the guardm.getTagName() == nullcorrectly excludes wrapper-element fields (Case 1), limitingmixed="true"to body-level class elements only (Case 2).writeListElement: the anonymousxs:complexTypeinside a wrapper element correctly getsmixed="true"forxml.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"withoutxml.tagName(body-level / Case 2), and - a field annotated
xml.format="mixed"withxml.tagName(wrapper / Case 1 — exerciseswriteListElement)
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.
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.
gnodet-bot
left a comment
There was a problem hiding this comment.
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.
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.
gnodet-bot
left a comment
There was a problem hiding this comment.
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.
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 withmixed="true"on thexs:complexType.Two cases are handled:
Field with
xml.format="mixed"andxml.tagName(wrapper element): the content lives inside the wrapper child element, so the anonymousxs:complexTypewritten bywriteListElement()getsmixed="true".Field with
xml.format="mixed"and noxml.tagName: the content is body text of the class element itself, so the namedxs:complexTypewritten bywriteComplexTypeDescriptor()getsmixed="true". Fields withxml.tagNameare 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.