public void RegisterSwaggerDoc(Uri endpoint, bool forceReregister = false) { if (forceReregister || currentSwaggerEndpoint != endpoint) { serviceInterfaceMethodSpecDic = null; } if (serviceInterfaceMethodSpecDic == null) { currentSwaggerEndpoint = endpoint; swaggerDocStore.RegisterSwaggerDoc(endpoint); Type type = typeof(TServiceInterface); serviceInterfaceMethodSpecDic = new Dictionary <string, HttpMethodSpec>(); serviceInterfaceMethodSpecDic.Clear(); //var matchs=regex.Matches(serviceInterfaceSpec.Template); var controllerName = ServiceSpec.ServiceName; //(matchs.Count >= 2) ? matchs[1].Groups[0].Value.ToString() : matchs[0].Groups[0].Value.ToString(); List <HttpMethodSpec> httpMethodSpecList; if (!swaggerDocStore.TryGetValue(endpoint, controllerName, out httpMethodSpecList)) { throw new KeyNotFoundException("RegisterSwaggerDoc"); } var methodInfos = type.GetMethods(); foreach (var methodInfo in methodInfos) { var apiSpec = ApiSpecAttribute.TakeFrom(type, methodInfo.Name); var template = (apiSpec == null) ? methodInfo.Name : apiSpec.Template; var path = string.IsNullOrEmpty(template) ? $"/{ServiceSpec.SwaggerRoutePath}":$"/{ServiceSpec.SwaggerRoutePath}/{template}"; var matchedMethodSpec = httpMethodSpecList.Find(spec => spec.Path.Contains(path)) ?? throw new KeyNotFoundException("RegisterSwaggerDoc"); serviceInterfaceMethodSpecDic[methodInfo.Name] = matchedMethodSpec; } } }
public HttpSpecFactory() { swaggerDocStore = SwaggerDocStore.Instance; ServiceSpec = ApiSpecAttribute.TakeFrom(typeof(TServiceInterface)); }