Exemple #1
0
        private void ProcessServices()
        {
            var configuration = _getConfigurationCached.Execute();

            if (configuration == null)
            {
                return;
            }

            var deployed = _getDeploymentCount.Execute();

            if (deployed == 0)
            {
                return;
            }

            var services = _getActiveServices.Execute();

            var notFetched = services.Where(x => x.Status == ServiceStatus.Deployed).ToList();

            if (notFetched.Any())
            {
                _fetchServiceDefinitions.Execute(notFetched);
            }

            _mergeOpenApiSchemas.Execute(services);
        }
        public void Execute(JObject mainSchema, ServiceDefinition service)
        {
            var configuration = _getConfigurationCached.Execute();
            var json          = JObject.Parse(service.JsonData);

            var schema = service.JsonData;

            var types = json["components"]["schemas"].ToKeyValuePairs();

            foreach (var type in types)
            {
                schema = schema.Replace($"#/components/schemas/{type.Key}", $"#/components/schemas/{service.Id}_{type.Key}");
            }

            var serviceJson = JObject.Parse(schema);

            foreach (var type in types)
            {
                mainSchema["components"]["schemas"][$"{service.Id}_{type.Key}"] = serviceJson["components"]["schemas"][type.Key];
            }

            var paths     = json["paths"].ToKeyValuePairs();
            var urlFilter = configuration.UrlFilter ?? "/";

            foreach (var path in paths)
            {
                if (!path.Key.Contains(urlFilter))
                {
                    continue;
                }

                mainSchema["paths"][path.Key] = serviceJson["paths"][path.Key];
            }
        }
Exemple #3
0
        private void UpdateSchemaMasterData(JObject mainSchema)
        {
            var configuration = _getConfigurationCached.Execute();

            mainSchema["info"]["title"]       = configuration.Title;
            mainSchema["info"]["description"] = configuration.Description;

            if (!string.IsNullOrEmpty(configuration.TermsUrl))
            {
                mainSchema["info"]["termsOfService"] = configuration.TermsUrl;
            }
            if (!string.IsNullOrEmpty(configuration.ContactEmail))
            {
                mainSchema["info"]["contact"]          = new JObject();
                mainSchema["info"]["contact"]["email"] = configuration.ContactEmail;
            }

            if (!string.IsNullOrEmpty(configuration.ContactEmail))
            {
                mainSchema["info"]["license"]         = new JObject();
                mainSchema["info"]["license"]["name"] = configuration.LicenseName;
                mainSchema["info"]["license"]["url"]  = configuration.LicenseUrl;
            }

            if (configuration.SecurityType == SecurityType.BasicAuth)
            {
                mainSchema["components"]["securitySchemes"] = new JObject();
                mainSchema["components"]["securitySchemes"]["basicAuth"]           = new JObject();
                mainSchema["components"]["securitySchemes"]["basicAuth"]["type"]   = "http";
                mainSchema["components"]["securitySchemes"]["basicAuth"]["scheme"] = "basic";
            }

            if (configuration.SecurityType == SecurityType.ApiKey)
            {
                mainSchema["components"]["securitySchemes"] = new JObject();
                mainSchema["components"]["securitySchemes"]["ApiKeyAuth"]         = new JObject();
                mainSchema["components"]["securitySchemes"]["ApiKeyAuth"]["type"] = "apiKey";
                mainSchema["components"]["securitySchemes"]["ApiKeyAuth"]["in"]   = "header";
                mainSchema["components"]["securitySchemes"]["ApiKeyAuth"]["name"] = configuration.SecurityKeyName;
            }
        }
        private void FetchServiceDefinition(ServiceDefinition service)
        {
            var configuration = _getConfigurationCached.Execute();
            var segment       = "/swagger.json";

            if (!string.IsNullOrEmpty(configuration.JsonEndpoint) && configuration.JsonEndpoint.Contains(".json"))
            {
                segment = configuration.JsonEndpoint;
            }

            var urls = service.ServiceUrls.Split(',');

            foreach (var url in urls)
            {
                try
                {
                    var json = url
                               .AppendPathSegment(segment)
                               .GetStringAsync().Result;

                    if (json.Length > 0)
                    {
                        service.JsonData = json;
                        service.Status   = ServiceStatus.Fetched;
                    }
                }
                catch (Exception e) {}

                if (service.Status == ServiceStatus.Fetched)
                {
                    return;
                }
            }

            service.JsonData = null;
            service.Retry++;
        }