Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

The XSD generator was ignoring <required>true</required> in model definitions, generating minOccurs="0" (optional) for all fields unless an undocumented parameter was set.

Changes

XsdGenerator.java

  • Removed dependency on enforceMandatoryElements parameter - now respects field.isRequired() directly
  • Required fields omit minOccurs="0", making them mandatory in XSD validation
  • Parameter kept for backward compatibility

modello.mdo

  • Removed incorrect <required>true</required> from ModelField's type field
  • Type is optional when association element is present

Test Added

  • Added RequiredFieldXsdGeneratorTest to verify required fields are enforced without the XSD_ENFORCE_MANDATORY_ELEMENTS parameter
  • Test validates that XML missing required fields fails validation
  • Test validates that XML with required fields passes validation

Example

Model definition:

<field>
  <name>title</name>
  <required>true</required>
  <type>String</type>
</field>

Before:

<xs:element minOccurs="0" name="title" type="xs:string"/>  <!-- Optional -->

After:

<xs:element name="title" type="xs:string"/>  <!-- Required -->

Fixes #ARCHETYPE-684

Original prompt

This section details on the original issue you should resolve

<issue_title>Required attribute is not taken into account</issue_title>
<issue_description>Looks like setting <required>true</required> for fields is not take into account ...

https://issues.apache.org/jira/browse/ARCHETYPE-684</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits October 26, 2025 07:43
- 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 <6705942+slachiewicz@users.noreply.github.com>
…ments parameter

Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix required attribute not being taken into account Fix XSD generator to respect required field attribute Oct 26, 2025
Copilot AI requested a review from slachiewicz October 26, 2025 07:51
Copilot finished work on behalf of slachiewicz October 26, 2025 07:51
@slachiewicz slachiewicz marked this pull request as ready for review October 26, 2025 12:31
@slawekjaranowski
Copy link
Member

@copilot can you add a unit test for such change?

…ATORY_ELEMENTS parameter

- Created RequiredFieldXsdGeneratorTest to verify required fields are enforced by default
- Added required-field.mdo test model with both required and optional fields
- Test validates that XML missing required fields fails validation
- Test validates that XML with required fields passes validation

Co-authored-by: slawekjaranowski <3578921+slawekjaranowski@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot can you add a unit test for such change?

Added RequiredFieldXsdGeneratorTest that validates required fields are enforced without needing the XSD_ENFORCE_MANDATORY_ELEMENTS parameter. The test:

  1. Generates an XSD from a model with both required and optional fields
  2. Validates that XML with required fields passes
  3. Validates that XML missing required fields fails validation
  4. Validates that optional fields can be omitted

Commit: 449af72

Copilot finished work on behalf of slawekjaranowski October 27, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required attribute is not taken into account

3 participants