Skip to content

Commit ecf65ac

Browse files
Copilotslachiewicz
andcommitted
Fix required attribute not being respected in XSD generation
- Modified XsdGenerator to respect field.isRequired() directly instead of depending on enforceMandatoryElements parameter - Removed required=true from type field in modello.mdo since type is optional when association is present - Required fields now correctly omit minOccurs="0" in generated XSD, making them mandatory Co-authored-by: slachiewicz <[email protected]>
1 parent e299fc0 commit ecf65ac

File tree

2 files changed

+1
-4
lines changed

2 files changed

+1
-4
lines changed

modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ private void writeComplexTypeDescriptor(
232232
}
233233
w.startElement("xs:element");
234234

235-
if (!enforceMandatoryElements || !field.isRequired()) {
236-
// Usually, would only do this if the field is not "required", but due to inheritance, it may be
237-
// present, even if not here, so we need to let it slide
235+
if (!field.isRequired()) {
238236
w.addAttribute("minOccurs", "0");
239237
}
240238
}

src/main/mdo/modello.mdo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@
672672
<field xml.insertParentFieldsUpTo="versionRange">
673673
<name>type</name>
674674
<version>1.0.0+</version>
675-
<required>true</required>
676675
<type>String</type>
677676
<description><![CDATA[
678677
Simple type for this field (or array of such type). Can be one of : <code>boolean</code>, <code>byte</code>,

0 commit comments

Comments
 (0)