Ejemplo n.º 1
0
 private Info CreateInfoForApiVersion(string version)
 => new Info()
 {
     Title       = "Alza API",
     Version     = version,
     Description = ApiVersions.ContainsKey(version) ? ApiVersions[version] : ""
 };
Ejemplo n.º 2
0
 /// <summary>
 /// 自定义版本+路由构造函数,继承基类路由
 /// </summary>
 /// <param name="actionName"></param>
 /// <param name="version"></param>
 public CustomRouteAttribute(
     ApiVersions version,
     string actionName = "[action]"
     ) : base($"/api/{version.ToString()}/[controller]/{actionName}")
 {
     GroupName = version.ToString();
 }
Ejemplo n.º 3
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Attribute" /> class.</summary>
 public ApiAttribute(ApiVersions version, string apiName, HttpMethods httpMethod = HttpMethods.GET, string description = "", params string[] rootApiName)
 {
     Version     = version;
     ApiName     = apiName;
     RootApiName = rootApiName;
     HttpMethod  = httpMethod;
     Description = description;
 }
Ejemplo n.º 4
0
 public void MultipleApiVersions(
     IEnumerable <Info> apiVersions,
     Func <ApiDescription, string, bool> versionSupportResolver)
 {
     ApiVersions.Clear();
     foreach (var version in apiVersions)
     {
         ApiVersions.Add(version);
     }
     VersionSupportResolver = versionSupportResolver;
 }
Ejemplo n.º 5
0
        /// <summary> Construct a new instance of the <see cref="ServiceBase"/> Class. </summary>
        /// <param name="region">The region to use in the web service calls.</param> <param
        /// name="ver"><The version of the particular service.</param> <param name="endPoint">The
        /// end point for the given service.</param>
        public ServiceBase(ApiRegions region, ApiVersions ver, ApiEndPoints endPoint, string key)
        {
            Region   = region;
            Version  = ver;
            EndPoint = endPoint;
            ApiKey   = key;

            BaseUri = new Uri(string.Format(baseURL, Regions.GetRegions[region]));

            CreateMapping();

            RateLimitManager.Instance.Add(ApiKey);
        }
Ejemplo n.º 6
0
        public void ValidateClone()
        {
            var options      = new ArmClientOptions();
            var apiVersions1 = new ApiVersions(options);
            var apiVersions2 = apiVersions1.Clone();

            Assert.IsFalse(ReferenceEquals(apiVersions1, apiVersions2));
            Assert.AreEqual(apiVersions1.TryGetApiVersion("{Microsoft.Resources/subscriptions/resourceGroups}"), apiVersions2.TryGetApiVersion("{Microsoft.Resources/subscriptions/resourceGroups}"));

            apiVersions1.SetApiVersion("{Microsoft.Resources/subscriptions/resourceGroups}", "1500-10-10");
            Assert.IsFalse(ReferenceEquals(apiVersions1, apiVersions2));
            Assert.AreNotEqual(apiVersions1, apiVersions2);
        }
Ejemplo n.º 7
0
        private static string GetRouteTemplate(ApiVersions version, string moduleName = "", string actionName = "[action]")
        {
            var    path          = moduleName == "" ? version.ToString() : version.ToString() + "/" + moduleName;
            var    startupConfig = StartupConfigHelper.Get();
            string temp;

            switch (startupConfig.TenantRouteStrategy)
            {
            case TenantRouteStrategy.Route:
                temp = "/{__tenant__}/api/" + path + "/[controller]/" + actionName;
                break;

            case TenantRouteStrategy.Host:
                temp = "/api/" + path + "/[controller]/" + actionName;
                break;

            default:
                temp = "/{__tenant__}/api/" + path + "/[controller]/" + actionName;
                break;
            }
            return(temp);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get the latest version supported. If ApiVersions is populated, returns the latest one from that list.
        /// Otherwise, checks and returns the DefaultApiVersion. If nothing could be found, throws an exception.
        /// </summary>
        /// <returns>Version number</returns>
        public string GetLatestVersion()
        {
            int numberOfVersions = ApiVersions.Count;

            if (numberOfVersions > 0)
            {
                if ((!isApiListSorted) && (numberOfVersions > 1))
                {
                    ApiVersions.Sort();
                    isApiListSorted = true;
                }

                return(ApiVersions[numberOfVersions - 1]);
            }

            if (!string.IsNullOrWhiteSpace(DefaultApiVersion))
            {
                return(DefaultApiVersion);
            }

            throw new Exception("Could not determine an available version.");
        }
Ejemplo n.º 9
0
 public WebApiVersionAttribute(ApiVersions version)
     : base(new ApiVersion((int)version, 0))
 {
 }
Ejemplo n.º 10
0
 public void SingleApiVersion(Info info)
 {
     ApiVersions.Clear();
     ApiVersions.Add(info);
     VersionSupportResolver = null;
 }
Ejemplo n.º 11
0
        public void Start(StartContext context)
        {
            var config = context.AppHost.GetRequired <HttpConfiguration>();

            var swagger = config.EnableSwagger(
                c =>
            {
                if (IgnoreObsoleteActions)
                {
                    c.IgnoreObsoleteActions();
                }
                if (IgnoreObsoleteProperties)
                {
                    c.IgnoreObsoleteProperties();
                }
                if (DescribeAllEnumsAsStrings)
                {
                    c.DescribeAllEnumsAsStrings();
                }
                if (UseFullTypeNameInSchemaIds)
                {
                    c.UseFullTypeNameInSchemaIds();
                }
                if (UsePrettyPrint)
                {
                    c.PrettyPrint();
                }
                if (UseResolveConflictingActions)
                {
                    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                }
                if (UseApiVersions)
                {
                    if (ApiVersions.Count == 1)
                    {
                        var apiVersion = ApiVersions.Single();
                        c.SingleApiVersion(apiVersion.Key, apiVersion.Value);
                    }
                    else if (ApiVersions.Count > 1)
                    {
                        var apiRegex = new Regex(
                            @"\b(?<version>v\d+)\b",
                            RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        c.MultipleApiVersions(
                            (apiDesc, targetApiVersion) =>
                        {
                            var match = apiRegex.Match(apiDesc.GetControllerAndActionAttributes <RoutePrefixAttribute>().First().Prefix);
                            return(match.Success && string.Equals(match.Groups["version"].Value, targetApiVersion, StringComparison.OrdinalIgnoreCase));
                        },
                            vc =>
                        {
                            foreach (var apiVersion in ApiVersions)
                            {
                                vc.Version(apiVersion.Key, apiVersion.Value);
                            }
                        });
                    }
                }
            });

            if (UseUI)
            {
                swagger.EnableSwaggerUi(c => c.EnableDiscoveryUrlSelector());
            }
        }
 public ApiVersionsTests()
 {
     Versions = new ApiVersions {
         V1_0, V2_0, V2_1, V3_0, V3_1, V3_2, V4_0
     };
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 自定义版本+路由构造函数,继承基类路由
 /// </summary>
 /// <param name="moduleName">模块名称</param>
 /// <param name="actionName"></param>
 /// <param name="version"></param>
 public CustomRouteAttribute(ApiVersions version, string moduleName = "", string actionName = "[action]") : base(GetRouteTemplate(version, moduleName, actionName))
 {
     GroupName = version.ToString();
 }
Ejemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="action"></param>
 /// <param name="version"></param>
 public CustomRouteAttribute(string controller = "[controller]", string action = "[action]", ApiVersions version = ApiVersions.web) : base($"{version}/{controller}.{action}")
 {
     this.GroupName = version.ToString();
 }
 public RangedVersioningControllerConvention(ApiVersions versions)
 {
     _versions = versions;
 }