Esempio n. 1
0
        public SwaggerDocument GetSwagger(string rootUrl, string apiVersion)
        {
            var cacheKey = string.Format("{0}_{1}", rootUrl, apiVersion);
            SwaggerDocument srcDoc = null;
            if (!_cache.TryGetValue(cacheKey, out srcDoc))
            {
                SwaggerGenerator generator = _swaggerProvider as SwaggerGenerator;

                var apiExplorer = (IApiExplorer)generator.GetType().GetRuntimeFields().Where(f => f.Name == "_apiExplorer").First().GetValue(generator);
                var settings = (JsonSerializerSettings)generator.GetType().GetRuntimeFields().Where(f => f.Name == "_jsonSerializerSettings").First().GetValue(generator);
                var apiVersions = (IDictionary<string, Info>)generator.GetType().GetRuntimeFields().Where(f => f.Name == "_apiVersions").First().GetValue(generator);
                var options = (SwaggerGeneratorOptions)generator.GetType().GetRuntimeFields().Where(f => f.Name == "_options").First().GetValue(generator);

                var myGenerator = new MySwaggerGenerator(apiExplorer, settings, apiVersions, options);
                srcDoc = myGenerator.GetSwagger(rootUrl, apiVersion);
                srcDoc.vendorExtensions = new Dictionary<string, object> { { "ControllerDesc", GetControllerDesc(apiVersion) } };

                _cache.TryAdd(cacheKey, srcDoc);

            }
            return srcDoc;
        }