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

            return(service.ToJson());
        }
Beispiel #2
0
 public async Task <SwaggerService> RunAsync()
 {
     return(await Task.Run(() =>
     {
         var generator = new AssemblyTypeToSwaggerGenerator(Settings);
         return generator.Generate(ClassNames);
     }));
 }
        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);
        }
Beispiel #4
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();
         });
     }));
 }
        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(new AssemblyTypeToSwaggerGeneratorSettings
            {
                AssemblyPath = assemblyPath
            });

            //// Act
            var document = generator.Generate(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());
            }
        }