public static HashSet <string> GetDefaultNamespaces(this MetadataTypesConfig config, MetadataTypes metadata) { var namespaces = config.DefaultNamespaces.ToHashSet(); //Add any ignored namespaces used foreach (var ns in metadata.Namespaces) { //Ignored by IsUserType() if (!ns.StartsWith("System") && !config.IgnoreTypesInNamespaces.Contains(ns)) { continue; } if (!namespaces.Contains(ns)) { namespaces.Add(ns); } } return(namespaces); }
public static bool IgnoreType(this MetadataType type, MetadataTypesConfig config, List <string> overrideIncludeType = null) { // If is a systemType and export types doesn't include this if (type.IgnoreSystemType() && config.ExportTypes.All(x => x.Name != type.Name)) { return(true); } var includes = overrideIncludeType ?? config.IncludeTypes; if (includes != null && !includes.Contains(type.Name)) { return(true); } if (config.ExcludeTypes != null && config.ExcludeTypes.Any(x => type.Name == x || type.Name.StartsWith(x + "`"))) { return(true); } return(false); }
public string GenerateTypeScript(NativeTypesBase request, MetadataTypesConfig typesConfig) { //Include SS types by removing ServiceStack namespaces if (typesConfig.AddServiceStackTypes) { typesConfig.IgnoreTypesInNamespaces = new List <string>(); } var metadataTypes = NativeTypesMetadata.GetMetadataTypes(Request, typesConfig); metadataTypes.Types.RemoveAll(x => x.Name == "Service"); if (typesConfig.AddServiceStackTypes) { //IReturn markers are metadata properties that are not included as normal interfaces var generator = ((NativeTypesMetadata)NativeTypesMetadata).GetMetadataTypesGenerator(typesConfig); metadataTypes.Types.Insert(0, generator.ToType(typeof(IReturn <>))); metadataTypes.Types.Insert(0, generator.ToType(typeof(IReturnVoid))); } var typeScript = new TypeScriptGenerator(typesConfig).GetCode(metadataTypes, base.Request, NativeTypesMetadata); return(typeScript); }
public static bool IgnoreType(this MetadataType type, MetadataTypesConfig config, List<string> overrideIncludeType = null) { // If is a systemType and export types doesn't include this if (type.IgnoreSystemType() && config.ExportTypes.All(x => x.Name != type.Name)) return true; var includes = overrideIncludeType ?? config.IncludeTypes; if (includes != null && !includes.Contains(type.Name)) return true; if (config.ExcludeTypes != null && config.ExcludeTypes.Any(x => type.Name == x || type.Name.StartsWith(x + "`"))) return true; return false; }
public CSharpGenerator(MetadataTypesConfig config) { Config = config; feature = HostContext.GetPlugin<NativeTypesFeature>(); }
public static void RemoveIgnoredTypesForNet(this MetadataTypes metadata, MetadataTypesConfig config) { metadata.RemoveIgnoredTypes(config); //Don't include Exported Types in System metadata.Types.RemoveAll(x => x.IgnoreSystemType()); }
public MetadataTypesGenerator(ServiceMetadata meta, MetadataTypesConfig config) { this.meta = meta; this.config = config; }
public static string GetTypeName(this MetadataPropertyType prop, MetadataTypesConfig config, List<MetadataType> allTypes) { if (prop.IsValueType != true || prop.IsEnum == true) return prop.Type; if (prop.IsSystemType == true) { if (prop.Type != "Nullable`1" || prop.GenericArgs?.Length != 1) return prop.Type; if (config.ExportValueTypes) return prop.Type; // Find out if the ValueType is not a SystemType or Enum by looking if this Info is declared in another prop var genericArg = prop.GenericArgs[0]; var typeInfo = allTypes.Where(x => x.Properties != null) .SelectMany(x => x.Properties) .FirstOrDefault(x => x.Type == genericArg); return typeInfo != null && typeInfo.IsSystemType != true && typeInfo.IsEnum != true ? "String" : prop.Type; } //Whether or not to emit the Struct Type Name, info: https://github.com/ServiceStack/Issues/issues/503#issuecomment-262133343 return config.ExportValueTypes ? prop.Type : "String"; }
public MetadataTypes GetMetadataTypes(IRequest req, MetadataTypesConfig config = null, Func<Operation, bool> predicate = null) { return GetMetadataTypesGenerator(config).GetMetadataTypes(req, predicate); }
internal MetadataTypesGenerator GetMetadataTypesGenerator(MetadataTypesConfig config) { return(new MetadataTypesGenerator(meta, config ?? defaults)); }
public JavaGenerator(MetadataTypesConfig config) { Config = config; AllTypes = new List<MetadataType>(); }
public MetadataTypes GetMetadataTypes(IRequest req, MetadataTypesConfig config = null) { return new MetadataTypesGenerator(meta, config ?? defaults).GetMetadataTypes(req); }
public JavaGenerator(MetadataTypesConfig config) { Config = config; }
public SwiftGenerator(MetadataTypesConfig config) { Config = config; }
public static bool IgnoreType(this MetadataType type, MetadataTypesConfig config) { if (type.IgnoreSystemType() && config.ExportTypes.All(x => x.Name != type.Name)) return true; if (config.IncludeTypes != null && !config.IncludeTypes.Contains(type.Name)) return true; if (config.ExcludeTypes != null && config.ExcludeTypes.Any(x => type.Name == x || type.Name.StartsWith(x + "`"))) return true; return false; }
public VbNetGenerator(MetadataTypesConfig config) { Config = config; }
public static string CSharpNamespace(IRequest req, MetadataTypesConfig config) => $"option csharp_namespace = \"{config.GlobalNamespace}\";";
public static string GetCode(MetadataTypes metadata, string defaultBaseUrl = null) { Config = metadata.Config; var namespaces = new HashSet <string>(); Config.DefaultNamespaces.Each(x => namespaces.Add(x)); metadata.Types.Each(x => namespaces.Add(x.Namespace)); metadata.Operations.Each(x => namespaces.Add(x.Request.Namespace)); const bool flag = false; Config.AddReturnMarker = flag; Config.MakeVirtual = Config.MakePartial = flag; Config.AddDescriptionAsComments = flag; Config.AddDefaultXmlNamespace = "http://schemas.servicestack.net/dtogen-types"; Config.AddDataContractAttributes = flag; Config.MakeDataContractsExtensible = flag; Config.AddIndexesToDataMembers = flag; Config.InitializeCollections = flag; Config.AddResponseStatus = flag; Config.AddImplicitVersion = null; var sb = new StringBuilderWrapper(new StringBuilder()); sb.AppendLine("/* Options:"); sb.AppendLine("Version: {0}".Fmt(Version)); sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl ?? defaultBaseUrl)); sb.AppendLine(); sb.AppendLine("ServerVersion: {0}".Fmt(metadata.Version)); sb.AppendLine("MakePartial: {0}".Fmt(Config.MakePartial)); sb.AppendLine("MakeVirtual: {0}".Fmt(Config.MakeVirtual)); sb.AppendLine("AddReturnMarker: {0}".Fmt(Config.AddReturnMarker)); sb.AppendLine("AddDescriptionAsComments: {0}".Fmt(Config.AddDescriptionAsComments)); sb.AppendLine("AddDataContractAttributes: {0}".Fmt(Config.AddDataContractAttributes)); sb.AppendLine("AddDefaultXmlNamespace: {0}".Fmt(Config.AddDefaultXmlNamespace)); sb.AppendLine("MakeDataContractsExtensible: {0}".Fmt(Config.MakeDataContractsExtensible)); sb.AppendLine("AddIndexesToDataMembers: {0}".Fmt(Config.AddIndexesToDataMembers)); sb.AppendLine("InitializeCollections: {0}".Fmt(Config.InitializeCollections)); sb.AppendLine("AddResponseStatus: {0}".Fmt(Config.AddResponseStatus)); sb.AppendLine("AddImplicitVersion: {0}".Fmt(Config.AddImplicitVersion)); sb.AppendLine("DefaultNamespaces: {0}".Fmt(Config.DefaultNamespaces.ToArray().Join(", "))); sb.AppendLine("*/"); sb.AppendLine(); namespaces.ToList().ForEach(x => sb.AppendLine("using {0};".Fmt(x))); if (Config.AddDataContractAttributes && Config.AddDefaultXmlNamespace != null) { sb.AppendLine(); namespaces.Where(x => !Config.DefaultNamespaces.Contains(x)).ToList() .ForEach(x => sb.AppendLine("[assembly: ContractNamespace(\"{0}\", ClrNamespace=\"{1}\")]" .Fmt(Config.AddDefaultXmlNamespace, x))); } sb.AppendLine(); string lastNS = null; sb.AppendLine("#region Operations"); sb.AppendLine(); foreach (var operation in metadata.Operations .OrderBy(x => x.Request.Namespace) .OrderBy(x => x.Request.Name)) { var request = operation.Request; var response = operation.Response; lastNS = AppendType(ref sb, request, lastNS, new CreateTypeOptions { ImplementsFn = () => { if (!Config.AddReturnMarker && !request.ReturnVoidMarker && request.ReturnMarkerGenericArgs == null) { return(null); } if (request.ReturnVoidMarker) { return("IReturnVoid"); } if (request.ReturnMarkerGenericArgs != null) { return(Type("IReturn`1", request.ReturnMarkerGenericArgs)); } return(response != null ? Type("IReturn`1", new[] { response.Name }) : null); }, IsRequest = true, }); lastNS = AppendType(ref sb, operation.Response, lastNS, new CreateTypeOptions { IsResponse = true, }); } if (lastNS != null) { sb.AppendLine("}"); } sb.AppendLine(); sb.AppendLine("#endregion"); sb.AppendLine(); sb.AppendLine(); lastNS = null; sb.AppendLine("#region Types"); sb.AppendLine(); foreach (var type in metadata.Types .OrderBy(x => x.Namespace) .OrderBy(x => x.Name)) { lastNS = AppendType(ref sb, type, lastNS, new CreateTypeOptions { IsType = true }); } if (lastNS != null) { sb.AppendLine("}"); } sb.AppendLine(); sb.AppendLine("#endregion"); return(sb.ToString()); }
public NativeTypesMetadata(ServiceMetadata meta, MetadataTypesConfig defaults) { this.meta = meta; this.defaults = defaults; }
public SwiftGenerator(MetadataTypesConfig config) { Config = config; feature = HostContext.GetPlugin<NativeTypesFeature>(); AllTypes = new List<MetadataType>(); }
public TypeScriptGenerator(MetadataTypesConfig config) { Config = config; }
public GrpcProtoGenerator(MetadataTypesConfig config) { Config = config; feature = HostContext.AssertPlugin <NativeTypesFeature>(); grpc = HostContext.AssertPlugin <GrpcFeature>(); }
public static bool ForceInclude(this MetadataTypesConfig config, Type type) => HostContext.Metadata.ForceInclude.Contains(type);
internal MetadataTypesGenerator GetMetadataTypesGenerator(MetadataTypesConfig config) { return new MetadataTypesGenerator(meta, config ?? defaults); }
public static bool ForceInclude(this MetadataTypesConfig config, MetadataType type) => HostContext.Metadata.ForceInclude.Any(x => type.Type != null ? x == type.Type : type.Name == x.Name && type.Namespace == x.Namespace);
public static void RemoveIgnoredTypes(this MetadataTypes metadata, MetadataTypesConfig config) { var includeList = GetIncludeList(metadata, config); metadata.Types.RemoveAll(x => x.IgnoreType(config, includeList)); var matchingResponseTypes = includeList != null ? metadata.Operations.Where(x => x.Response != null && includeList.Contains(x.Response.Name)) .Map(x => x.Response).ToArray() : TypeConstants<MetadataType>.EmptyArray; metadata.Operations.RemoveAll(x => x.Request.IgnoreType(config, includeList)); metadata.Operations.Each(x => { if (x.Response != null && x.Response.IgnoreType(config, includeList)) { x.Response = null; } }); //When the included Type is a Response Type because defined in another Service that's not included //ref: https://forums.servicestack.net/t/class-is-missing-from-generated-code/3030 foreach (var responseType in matchingResponseTypes) { if (!metadata.Operations.Any(x => x.Response != null && x.Response.Name == responseType.Name) && metadata.Types.All(x => x.Name != responseType.Name)) { metadata.Types.Add(responseType); } } }
public MetadataTypes GetMetadataTypes(IRequest req, MetadataTypesConfig config = null) { return(new MetadataTypesGenerator(meta, config ?? defaults).GetMetadataTypes(req)); }
public static List<string> GetIncludeList(MetadataTypes metadata, MetadataTypesConfig config) { const string wildCard = ".*"; if (config.IncludeTypes == null) return null; var typesToExpand = config.IncludeTypes .Where(s => s.Length > 2 && s.EndsWith(wildCard)) .Map(s => s.Substring(0, s.Length - 2)); if (typesToExpand.Count == 0) return config.IncludeTypes; // From IncludeTypes get the corresponding MetadataTypes var includedMetadataTypes = metadata.Operations .Select(o => o.Request) .Where(t => typesToExpand.Contains(t.Name)) .ToList(); var includeSet = includedMetadataTypes .Where(x => x.ReturnMarkerTypeName != null) .Select(x => x.ReturnMarkerTypeName.Name) .ToHashSet(); var includedResponses = metadata.Operations .Where(t => typesToExpand.Contains(t.Request.Name) && t.Response != null) .Select(o => o.Response) .ToList(); includedResponses.ForEach(x => includeSet.Add(x.Name)); var returnTypesForInclude = metadata.Operations .Where(x => x.Response != null && includeSet.Contains(x.Response.Name)) .Map(x => x.Response); // GetReferencedTypes for both request + response objects var referenceTypes = includedMetadataTypes .Union(returnTypesForInclude) .Where(x => x != null) .SelectMany(x => x.GetReferencedTypeNames()); return referenceTypes .Union(config.IncludeTypes) .Union(typesToExpand) .Union(returnTypesForInclude.Select(x => x.Name)) .Distinct() .ToList(); }
public MetadataTypes GetMetadataTypes(IRequest req, MetadataTypesConfig config = null) { return GetMetadataTypesGenerator(config).GetMetadataTypes(req); }
public CSharpGenerator(MetadataTypesConfig config) { Config = config; }
public static bool IgnoreType(this MetadataType type, MetadataTypesConfig config) { if (type.IgnoreSystemType()) return true; if (config.IncludeTypes != null && !config.IncludeTypes.Contains(type.Name)) return true; if (config.ExcludeTypes != null && config.ExcludeTypes.Contains(type.Name)) return true; return false; }
public SwiftGenerator(MetadataTypesConfig config) { Config = config; feature = HostContext.GetPlugin <NativeTypesFeature>(); AllTypes = new List <MetadataType>(); }
public MetadataTypes GetMetadataTypes(IRequest req, MetadataTypesConfig config = null, Func <Operation, bool> predicate = null) { return(GetMetadataTypesGenerator(config).GetMetadataTypes(req, predicate)); }
public static string GetCode(MetadataTypes metadata, string defaultBaseUrl = null) { Config = metadata.Config; var namespaces = new HashSet<string>(); Config.DefaultNamespaces.Each(x => namespaces.Add(x)); metadata.Types.Each(x => namespaces.Add(x.Namespace)); metadata.Operations.Each(x => namespaces.Add(x.Request.Namespace)); const bool flag = false; Config.AddReturnMarker = flag; Config.MakeVirtual = Config.MakePartial = flag; Config.AddDescriptionAsComments = flag; Config.AddDefaultXmlNamespace = "http://schemas.servicestack.net/dtogen-types"; Config.AddDataContractAttributes = flag; Config.MakeDataContractsExtensible = flag; Config.AddIndexesToDataMembers = flag; Config.InitializeCollections = flag; Config.AddResponseStatus = flag; Config.AddImplicitVersion = null; var sb = new StringBuilderWrapper(new StringBuilder()); sb.AppendLine("/* Options:"); sb.AppendLine("Version: {0}".Fmt(Version)); sb.AppendLine("BaseUrl: {0}".Fmt(Config.BaseUrl ?? defaultBaseUrl)); sb.AppendLine(); sb.AppendLine("ServerVersion: {0}".Fmt(metadata.Version)); sb.AppendLine("MakePartial: {0}".Fmt(Config.MakePartial)); sb.AppendLine("MakeVirtual: {0}".Fmt(Config.MakeVirtual)); sb.AppendLine("AddReturnMarker: {0}".Fmt(Config.AddReturnMarker)); sb.AppendLine("AddDescriptionAsComments: {0}".Fmt(Config.AddDescriptionAsComments)); sb.AppendLine("AddDataContractAttributes: {0}".Fmt(Config.AddDataContractAttributes)); sb.AppendLine("AddDefaultXmlNamespace: {0}".Fmt(Config.AddDefaultXmlNamespace)); sb.AppendLine("MakeDataContractsExtensible: {0}".Fmt(Config.MakeDataContractsExtensible)); sb.AppendLine("AddIndexesToDataMembers: {0}".Fmt(Config.AddIndexesToDataMembers)); sb.AppendLine("InitializeCollections: {0}".Fmt(Config.InitializeCollections)); sb.AppendLine("AddResponseStatus: {0}".Fmt(Config.AddResponseStatus)); sb.AppendLine("AddImplicitVersion: {0}".Fmt(Config.AddImplicitVersion)); sb.AppendLine("DefaultNamespaces: {0}".Fmt(Config.DefaultNamespaces.ToArray().Join(", "))); sb.AppendLine("*/"); sb.AppendLine(); namespaces.ToList().ForEach(x => sb.AppendLine("using {0};".Fmt(x))); if (Config.AddDataContractAttributes && Config.AddDefaultXmlNamespace != null) { sb.AppendLine(); namespaces.Where(x => !Config.DefaultNamespaces.Contains(x)).ToList() .ForEach(x => sb.AppendLine("[assembly: ContractNamespace(\"{0}\", ClrNamespace=\"{1}\")]" .Fmt(Config.AddDefaultXmlNamespace, x))); } sb.AppendLine(); string lastNS = null; sb.AppendLine("#region Operations"); sb.AppendLine(); foreach (var operation in metadata.Operations .OrderBy(x => x.Request.Namespace) .OrderBy(x => x.Request.Name)) { var request = operation.Request; var response = operation.Response; lastNS = AppendType(ref sb, request, lastNS, new CreateTypeOptions { ImplementsFn = () => { if (!Config.AddReturnMarker && !request.ReturnVoidMarker && request.ReturnMarkerGenericArgs == null) return null; if (request.ReturnVoidMarker) return "IReturnVoid"; if (request.ReturnMarkerGenericArgs != null) return Type("IReturn`1", request.ReturnMarkerGenericArgs); return response != null ? Type("IReturn`1", new[] { response.Name }) : null; }, IsRequest = true, }); lastNS = AppendType(ref sb, operation.Response, lastNS, new CreateTypeOptions { IsResponse = true, }); } if (lastNS != null) sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("#endregion"); sb.AppendLine(); sb.AppendLine(); lastNS = null; sb.AppendLine("#region Types"); sb.AppendLine(); foreach (var type in metadata.Types .OrderBy(x => x.Namespace) .OrderBy(x => x.Name)) { lastNS = AppendType(ref sb, type, lastNS, new CreateTypeOptions { IsType = true }); } if (lastNS != null) sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("#endregion"); return sb.ToString(); }
public MetadataTypes GetMetadataTypes(IRequest req, MetadataTypesConfig config = null) { return(GetMetadataTypesGenerator(config).GetMetadataTypes(req)); }
public TypeScriptGenerator(MetadataTypesConfig config) { Config = config; feature = HostContext.GetPlugin <NativeTypesFeature>(); }
public static void RemoveIgnoredTypes(this MetadataTypes metadata, MetadataTypesConfig config) { var includeList = GetIncludeList(metadata, config); metadata.Types.RemoveAll(x => x.IgnoreType(config, includeList)); metadata.Operations.RemoveAll(x => x.Request.IgnoreType(config, includeList)); metadata.Operations.Each(x => { if (x.Response != null && x.Response.IgnoreType(config, includeList)) { x.Response = null; } }); }
public SwiftGenerator(MetadataTypesConfig config) { Config = config; AllTypes = new List <MetadataType>(); }