diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs index a994ebbb..390e10e3 100644 --- a/XmlSchemaClassGenerator/ModelBuilder.cs +++ b/XmlSchemaClassGenerator/ModelBuilder.cs @@ -618,6 +618,7 @@ private TypeModel CreateTypeModel(XmlSchemaComplexType complexType) return classModel; } + private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType) { List restrictions = null; @@ -625,9 +626,8 @@ private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType) var facets = simpleType.Content switch { - XmlSchemaSimpleTypeRestriction typeRestriction => typeRestriction.Facets.Cast().ToList(), XmlSchemaSimpleTypeUnion typeUnion when AllMembersHaveFacets(typeUnion, out baseFacets) => baseFacets.SelectMany(f => f).ToList(), - _ => new(), + _ => MergeRestrictions(simpleType) }; if (facets.Count > 0) @@ -651,6 +651,27 @@ static bool AllMembersHaveFacets(XmlSchemaSimpleTypeUnion typeUnion, out List r.Facets.Cast()).ToList(); return retval; } + + static List MergeRestrictions(XmlSchemaSimpleType type) + { + if (type == null) return new(); + var baseFacets = MergeRestrictions(type.BaseXmlSchemaType as XmlSchemaSimpleType); + if (type.Content is XmlSchemaSimpleTypeRestriction typeRestriction) + { + var facets = typeRestriction.Facets.Cast().ToList(); + foreach (var facet in facets) + { + var baseFacet = baseFacets + .Where(f => f is not XmlSchemaEnumerationFacet + && f.GetType() == facet.GetType()) + .SingleOrDefault(); + if (baseFacet != null) + baseFacets.Remove(baseFacet); + baseFacets.Add(facet); + } + } + return baseFacets; + } } private static List EnsureEnumValuesUnique(List enumModelValues)