forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXsdGenerator.cs
More file actions
55 lines (47 loc) · 1.87 KB
/
Copy pathXsdGenerator.cs
File metadata and controls
55 lines (47 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using ServiceStack.Host;
using ServiceStack.Logging;
namespace ServiceStack.Metadata
{
public class XsdGenerator
{
private readonly ILog log = LogManager.GetLogger(typeof(XsdGenerator));
public bool OptimizeForFlash { get; set; }
public ICollection<Type> OperationTypes { get; set; }
private string Filter(string xsd)
{
return !this.OptimizeForFlash ? xsd : xsd.Replace("ser:guid", "xs:string");
}
public override string ToString()
{
if (OperationTypes == null || OperationTypes.Count == 0) return null;
var uniqueTypes = new HashSet<Type>();
var uniqueTypeNames = new List<string>();
foreach (var opType in OperationTypes)
{
var refTypes = opType.GetReferencedTypes();
foreach (var type in refTypes)
{
if (type.IsDto())
{
var baseTypeWithSameName = XsdMetadata.GetBaseTypeWithTheSameName(type);
if (uniqueTypeNames.Contains(baseTypeWithSameName.GetOperationName()))
{
log.WarnFormat("Skipping duplicate type with existing name '{0}'", baseTypeWithSameName.GetOperationName());
}
if (HostContext.AppHost.ExportSoapType(baseTypeWithSameName))
{
uniqueTypes.Add(baseTypeWithSameName);
}
}
}
}
this.OperationTypes = uniqueTypes;
var schemaSet = XsdUtils.GetXmlSchemaSet(OperationTypes);
var xsd = XsdUtils.GetXsd(schemaSet);
var filteredXsd = Filter(xsd);
return filteredXsd;
}
}
}