Skip to content
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

Duplicate Attributes if the same xsd:element is listed multiple times in the schema #521

Open
jhancock-taxa opened this issue Jun 27, 2024 · 3 comments

Comments

@jhancock-taxa
Copy link

I can't share the schema because contracts that prevent me from sharing, but basically if there is the same element many times and it merges them, it's duplicating schema attributes.

I.e. the MaxLengthAttribute will get duplicated in the output because every single example has xsd:length value="6" in it in all references to the same thing.

@mganss
Copy link
Owner

mganss commented Jun 28, 2024

Could you post a (made up) minimal schema that shows the issue?

@jhancock-taxa
Copy link
Author

I should also note that if it finds. Min and Max Length it also creates duplicate StringLengthAttributes.

So here's a property that's outputted:

        /// <summary>
        /// <para xml:lang="en">Maximum length: 150.</para>
        /// <para xml:lang="en">Minimum length: 16. Maximum length: 16.</para>
        /// <para xml:lang="en">Pattern: [A-Za-z0-9]*.</para>
        /// </summary>
        [global::System.ComponentModel.DataAnnotations.StringLengthAttribute(150)]
        [global::System.ComponentModel.DataAnnotations.StringLengthAttribute(16, MinimumLength=16)]
        [global::System.ComponentModel.DataAnnotations.RegularExpressionAttribute("[A-Za-z0-9]*")]
        [global::System.Diagnostics.CodeAnalysis.AllowNullAttribute()]
        [global::System.Diagnostics.CodeAnalysis.MaybeNullAttribute()]
        [global::System.Xml.Serialization.XmlElementAttribute("VendorControlNum")]
        public string VendorControlNum { get; set; }

From this in the xsd:

		<xsd:element name="VendorControlNum" minOccurs="0">
			<xsd:simpleType>
				<xsd:restriction base="AlphaNumericType">
					<xsd:length value="16"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:element>

And then there is another restriction elsewhere:

	<xsd:simpleType name="AlphaNumericType">
		<xsd:restriction base="StringType">
			<xsd:pattern value="[A-Za-z0-9]*" />
			<xsd:maxLength value="150" />
		</xsd:restriction>
	</xsd:simpleType>

Every single definition is identical. Somehow the StringLength(150) is there but that isn't listed anywhere that this field is defined.

From my understanding, these should be similar to how CSS works in that it goes from least to most specific and takes the most specific version that is found in the chain.

Thus this should not use the maxlength in the restriction because it's defined on the field, but should add the pattern

It appears that instead it's adding multiples instead of doing the merging.

@jhancock-taxa
Copy link
Author

Also, it appears that this is also doubling the XML documentation in places (along with xml documentation that generates msbuild warnings because if incorrectly escaped docs)

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

No branches or pull requests

2 participants