private void GenerateSpecification() { swaggerSpecification = new SwaggerSpecification { ApiInfo = new SwaggerApiInfo { Title = title, Version = apiVersion, }, Host = host, BasePath = apiBaseUrl, Schemes = schemes, }; // generate documentation IEnumerable <SwaggerRouteMetadata> metadata = routeCacheProvider.GetCache().RetrieveMetadata <SwaggerRouteMetadata>(); Dictionary <string, Dictionary <string, SwaggerEndpointInfo> > endpoints = new Dictionary <string, Dictionary <string, SwaggerEndpointInfo> >(); foreach (SwaggerRouteMetadata m in metadata) { if (m == null) { continue; } string path = m.Path; if (!string.IsNullOrEmpty(swaggerSpecification.BasePath) && swaggerSpecification.BasePath != "/") { path = path.Replace(swaggerSpecification.BasePath, ""); } if (!endpoints.ContainsKey(path)) { endpoints[path] = new Dictionary <string, SwaggerEndpointInfo>(); } endpoints[path].Add(m.Method, m.Info); // add definitions if (swaggerSpecification.ModelDefinitions == null) { swaggerSpecification.ModelDefinitions = new Dictionary <string, JSchema>(); } foreach (string key in SchemaCache.Cache.Keys) { if (swaggerSpecification.ModelDefinitions.ContainsKey(key)) { continue; } swaggerSpecification.ModelDefinitions.Add(key, SchemaCache.Cache[key]); } } swaggerSpecification.PathInfos = endpoints; }
private void GenerateSpecification() { this.swaggerSpecification = new SwaggerSpecification { ApiInfo = new SwaggerApiInfo { Title = this.title, Version = this.apiVersion, }, Host = this.host, BasePath = this.apiBaseUrl, Schemes = this.schemes, }; // generate documentation IEnumerable <SwaggerRouteMetadata> metadata = this.routeCacheProvider.GetCache() .RetrieveMetadata <SwaggerRouteMetadata>(); Dictionary <string, Dictionary <string, SwaggerEndpointInfo> > endpoints = new Dictionary <string, Dictionary <string, SwaggerEndpointInfo> >(); foreach (SwaggerRouteMetadata m in metadata) { if (m == null) { continue; } string path = m.Path; if (!string.IsNullOrEmpty(this.swaggerSpecification.BasePath) && this.swaggerSpecification.BasePath != "/") { path = path.Replace(this.swaggerSpecification.BasePath, ""); } if (!endpoints.ContainsKey(path)) { endpoints[path] = new Dictionary <string, SwaggerEndpointInfo>(); } endpoints[path].Add(m.Method, m.Info); } this.swaggerSpecification.PathInfos = endpoints; }