internal static void Init(Func <string, Service> buildService)
        {
            string[] paths = GetAllPaths().Where(p => !SwaggerFiles.Keys.Contains(p)).ToArray();

            foreach (string path in paths)
            {
                Service service = buildService(path);
                if (Info != null)
                {
                    service.Info = Info;
                }
                if (SecurityDefinitions != null)
                {
                    service.SecurityDefinitions = SecurityDefinitions;
                }
                if (BasePath != null)
                {
                    service.BasePath = BasePath;
                }

                string swagger = Serializer.Process(service);
                if (SwaggerFiles.ContainsKey(path) == false)
                {
                    SwaggerFiles.Add(path, swagger);
                }
            }
        }
Beispiel #2
0
        public static string GenerateSwaggerFile()
        {
            string path = GetAllPaths().Where(p => !SwaggerFiles.Keys.Contains(p)).Single();

            SwaggerSchema service = ServiceBuilder.Build("/");

            service.Info = Info;
            service.SecurityDefinitions = SecurityDefinitions;

            string swagger = Serializer.Process(service);

            if (SwaggerFiles.ContainsKey(path) == false)
            {
                SwaggerFiles.Add(path, swagger);
            }

            return(JsonConvert.SerializeObject(service, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }));
        }