From c3a6445c06ed5571dd28dc419fa2caabb4773dae Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Tue, 17 Nov 2020 22:55:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwaggerStudy.sln | 25 ++++++++++ .../Controllers/WeatherForecastController.cs | 37 ++++++++++++++ SwaggerStudy/Program.cs | 27 ++++++++++ SwaggerStudy/Properties/launchSettings.json | 31 ++++++++++++ SwaggerStudy/Startup.cs | 50 +++++++++++++++++++ SwaggerStudy/SwaggerStudy.csproj | 7 +++ SwaggerStudy/appsettings.Development.json | 9 ++++ SwaggerStudy/appsettings.json | 10 ++++ 8 files changed, 196 insertions(+) create mode 100644 SwaggerStudy.sln create mode 100644 SwaggerStudy/Controllers/WeatherForecastController.cs create mode 100644 SwaggerStudy/Program.cs create mode 100644 SwaggerStudy/Properties/launchSettings.json create mode 100644 SwaggerStudy/Startup.cs create mode 100644 SwaggerStudy/SwaggerStudy.csproj create mode 100644 SwaggerStudy/appsettings.Development.json create mode 100644 SwaggerStudy/appsettings.json diff --git a/SwaggerStudy.sln b/SwaggerStudy.sln new file mode 100644 index 0000000..fd25050 --- /dev/null +++ b/SwaggerStudy.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30711.63 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwaggerStudy", "SwaggerStudy\SwaggerStudy.csproj", "{6322570B-CB1E-4C88-A1C8-903114CBB926}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6322570B-CB1E-4C88-A1C8-903114CBB926}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6322570B-CB1E-4C88-A1C8-903114CBB926}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6322570B-CB1E-4C88-A1C8-903114CBB926}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6322570B-CB1E-4C88-A1C8-903114CBB926}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {73858C6B-1220-4E68-8FB1-2460777BC2BD} + EndGlobalSection +EndGlobal diff --git a/SwaggerStudy/Controllers/WeatherForecastController.cs b/SwaggerStudy/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..f3900de --- /dev/null +++ b/SwaggerStudy/Controllers/WeatherForecastController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SwaggerStudy.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IActionResult Get() + { + var rng = new Random(); + var result = Enumerable.Range(1, 5).Select(index => new + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = rng.Next(index), + }) + .ToArray(); + + return new JsonResult(result); + } + } +} diff --git a/SwaggerStudy/Program.cs b/SwaggerStudy/Program.cs new file mode 100644 index 0000000..a08e824 --- /dev/null +++ b/SwaggerStudy/Program.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SwaggerStudy +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/SwaggerStudy/Properties/launchSettings.json b/SwaggerStudy/Properties/launchSettings.json new file mode 100644 index 0000000..42a3ad7 --- /dev/null +++ b/SwaggerStudy/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:30311", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "SwaggerStudy": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SwaggerStudy/Startup.cs b/SwaggerStudy/Startup.cs new file mode 100644 index 0000000..9ad5115 --- /dev/null +++ b/SwaggerStudy/Startup.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SwaggerStudy +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/SwaggerStudy/SwaggerStudy.csproj b/SwaggerStudy/SwaggerStudy.csproj new file mode 100644 index 0000000..842a770 --- /dev/null +++ b/SwaggerStudy/SwaggerStudy.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/SwaggerStudy/appsettings.Development.json b/SwaggerStudy/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/SwaggerStudy/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SwaggerStudy/appsettings.json b/SwaggerStudy/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/SwaggerStudy/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}