Example #1
0
        public async Task <string> RunAsync()
        {
            var generator = new AssemblyTypeToSwaggerGenerator(Settings);
            var service   = generator.Generate(ClassNames);

            return(service.ToJson());
        }
Example #2
0
 public async Task <SwaggerService> RunAsync()
 {
     return(await Task.Run(() =>
     {
         var generator = new AssemblyTypeToSwaggerGenerator(Settings);
         return generator.Generate(ClassNames);
     }));
 }
 private Task LoadAssemblyAsync()
 {
     return(RunTaskAsync(async() =>
     {
         AllClassNames = await Task.Run(() =>
         {
             var generator = new AssemblyTypeToSwaggerGenerator(Command.Settings);
             return generator.GetClasses();
         });
     }));
 }
        public void When_loading_type_from_assembly_then_correct_count_of_properties_are_loaded()
        {
            //// Arrange
            var assemblyPath = "../../../NSwag.Demo.Web/bin/NSwag.Demo.Web.dll";
            var generator    = new AssemblyTypeToSwaggerGenerator(assemblyPath);

            //// Act
            var service = generator.Generate("NSwag.Demo.Web.Models.Person");

            //// Assert
            Assert.AreEqual(4, service.Definitions["Person"].Properties.Count);
        }
Example #5
0
 private Task LoadAssembly()
 {
     return(RunTaskAsync(async() =>
     {
         AllClassNames = await Task.Run(() =>
         {
             var generator = new AssemblyTypeToSwaggerGenerator(AssemblyPath);
             return generator.GetClasses();
         });
         ClassName = AllClassNames.FirstOrDefault();
     }));
 }
Example #6
0
 public async Task <string> GenerateSwaggerAsync()
 {
     return(await RunTaskAsync(async() =>
     {
         return await Task.Run(() =>
         {
             var generator = new AssemblyTypeToSwaggerGenerator(AssemblyPath, new JsonSchemaGeneratorSettings {
                 DefaultEnumHandling = DefaultEnumHandling
             });
             return generator.Generate(ClassName).ToJson();
         });
     }));
 }
Example #7
0
        public async Task When_loading_type_from_assembly_then_correct_count_of_properties_are_loaded()
        {
            //// Arrange
            var assemblyPath = "../../../NSwag.Demo.Web/bin/NSwag.Demo.Web.dll";
            var generator    = new AssemblyTypeToSwaggerGenerator(new AssemblyTypeToSwaggerGeneratorSettings
            {
                AssemblyPath = assemblyPath
            });

            //// Act
            var document = await generator.GenerateAsync(new[] { "NSwag.Demo.Web.Models.Person" });

            //// Assert
            Assert.AreEqual(6, document.Definitions["Person"].Properties.Count);
        }
        private void GenerateTypeSwagger(FilePath outputFile, SwaggerGeneratorSettings settings)
        {
            var genSettings = settings.JsonSettings as AssemblyTypeToSwaggerGeneratorSettings ??
                              SettingsFactory.GetAssemblyToSwaggerSettings();

            genSettings.AssemblyPath                = Source.MakeAbsolute(Environment).FullPath;
            genSettings.DefaultEnumHandling         = settings.EnumAsString ? EnumHandling.String : EnumHandling.Integer;
            genSettings.DefaultPropertyNameHandling = settings.CamelCaseProperties
                ? PropertyNameHandling.CamelCase
                : PropertyNameHandling.Default;
            genSettings.ReferencePaths = settings.AssemblyPaths.Select(a => a.FullPath).ToArray();
            var gen     = new AssemblyTypeToSwaggerGenerator(genSettings);
            var service = gen.Generate(gen.GetClasses());

            using (var stream = new StreamWriter(FileSystem.GetFile(outputFile).OpenWrite()))
            {
                stream.WriteAsync(service.ToJson());
            }
        }