-
Notifications
You must be signed in to change notification settings - Fork 180
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
SimpleType restrictions applied to their container collection #506
Comments
Fixed in 2.1.1141. |
Thanks for the update! Now it works better in the use case I described.
|
Can you show an example? |
I tried the previous version again and it turns out the last remark of mine was incorrect - it doesn't generate restrictions as I remembered. Sorry about the confusion and thanks for quick response! |
I have a similar issue but require/have a different fix instead of omitting the restrictions it would be preferred to have the max length be the max occurs on the collection in the XSD. Additionally, it would be nice to tag the primitive string types with the correct annotations. Currently I have a flavor of the project that does this. <?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Standards Editor (build:R1.6.15) on 2019 Feb 14 13:31:41, ISO 20022 version : 2013-->
<xs:schema xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
<xs:element name="Document" type="PostalAddress24"/>
<xs:simpleType name="Max70Text">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="70"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="PostalAddress24">
<xs:sequence>
<xs:element maxOccurs="7" minOccurs="0" name="AdrLine" type="Max70Text"/>
</xs:sequence>
</xs:complexType>
</xs:schema> actual [XmlElementAttribute("AdrLine")]
public Collection<string> AdrLine
{
get
{
return _adrLine;
}
init
{
_adrLine = value;
}
} expected [XmlElementAttribute("AdrLine")]
[MaxLengthAttribute(7)]
public Collection<string> AdrLine
{
get
{
return _adrLine;
}
init
{
_adrLine = value;
}
} My implementation #510 [XmlElementAttribute("AdrLine")]
[MaxLengthAttribute(7)]
public Collection<Max70Text> AdrLine
{
get
{
return _adrLine;
}
init
{
_adrLine = value;
}
}
//seperateClass for primitive string type
[GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.0.864.0")]
[SerializableAttribute()]
[XmlTypeAttribute("Max70Text", Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08")]
[XmlRootAttribute("Max70Text", Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08")]
public partial class Max70Text
{
/// <summary>
/// <para xml:lang="en">Minimum length: 1.</para>
/// <para xml:lang="en">Maximum length: 70.</para>
/// </summary>
[MinLengthAttribute(1)]
[MaxLengthAttribute(70)]
[XmlTextAttribute()]
public string Value { get; set; }
public static implicit operator Max70Text(string obj) => new() { Value = obj };
public static implicit operator string(Max70Text obj) => obj.Value;
} |
Hi,
So I have an xsd that contains following definitions. Problem is that whenever an element has maxOccurs > 1 and type refers to a simpleType, restrictions (at least minLength and maxLength) of the simpleType are added to generated collection itself.
Take a look at BuyerOrganisationDepartment for example; intention of the xsd is a collection of 0-2 strings each the length of 0-35 characters but DataAnnotations of generated code seem to be picked up from the simpleType resulting to a collection of 0-35 strings of any length.
Is there a workaround for this or do I have to fix the classes manually?
Code is generated with following command
xscgen --netCore --separateFiles --datetime-offset --output ./MyPath --namespace MyNamespace ./MyXsd.xsd
The text was updated successfully, but these errors were encountered: