Skip to content

Make XSD more strict for other Document types #2766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.12.x
Choose a base branch
from

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented May 5, 2025

Q A
Type improvement
BC Break yes
Fixed issues -

Summary

The goal of this change is to detect earlier when an XML attribute is used while it's not supported by Doctrine ODM.

BC Break: previously, the XSD schema allowed some attributes or child elements that were not used in the metadata. Example: "collection" name for embedded documents.

Element document embedded-document mapped-superclass query-result-document view
id Yes Yes Yes Yes Yes
field Yes Yes Yes Yes Yes
embed-one Yes Yes Yes Yes Yes
embed-many Yes Yes Yes Yes Yes
reference-one Yes Yes Yes Yes Yes
reference-many Yes Yes Yes Yes Yes
discriminator-field Yes Yes Yes Yes Yes
discriminator-map Yes Yes Yes Yes Yes
default-discriminator-value Yes Yes Yes Yes Yes
lifecycle-callbacks Yes Yes Yes Yes Yes
also-load-methods Yes Yes Yes Yes Yes
indexes Yes Yes Yes
search-indexes Yes
shard-key Yes
read-preference Yes
schema-validation Yes
time-series Yes
Attibute document embedded-document mapped-superclass query-result-document view
db Yes Yes Yes
name Yes Yes Yes Yes Yes
write-concern Yes Yes
collection Yes Yes
capped-collection Yes Yes
capped-collection-size Yes Yes
capped-collection-max Yes Yes
repository-class Yes Yes Yes
inheritance-type Yes Yes Yes Yes Yes
change-tracking-policy Yes Yes Yes
read-only Yes Yes
view Yes
root-class Yes

@GromNaN GromNaN added this to the 2.12.0 milestone May 5, 2025
@alcaeus alcaeus self-requested a review May 6, 2025 08:17
<xs:element name="reference-one" type="odm:reference-one" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="reference-many" type="odm:reference-many" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="also-load-methods" type="odm:also-load-methods" minOccurs="0" />
<xs:element name="indexes" type="odm:indexes" minOccurs="0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query result documents don't have indexes. Looking at the elements possible in a document, I think we should add lifecycle callbacks and the three discriminator elements (field, map, default value) here as well.

<xs:element name="reference-one" type="odm:reference-one" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="reference-many" type="odm:reference-many" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="also-load-methods" type="odm:also-load-methods" minOccurs="0" />
<xs:element name="indexes" type="odm:indexes" minOccurs="0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to confirm in tests, but IIRC embedded documents can be discriminated and also have lifecycle callbacks, so those elements should be added.

</xs:complexType>

<xs:complexType name="mapped-superclass">
<xs:attribute name="name" type="xs:NMTOKEN" />
<xs:choice minOccurs="0" maxOccurs="unbounded">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For mapped superclasses, we should check the inheritance logic in the mapping driver to confirm what elements are allowed. IIRC, attributes like the write concern, capped collection information, etc. is all inherited to documents, so we may want to add it here as well.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for taking the time to dig into what elements and attributes are valid for which document types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants