Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksvensson committed Sep 18, 2018
0 parents commit 945208e
Show file tree
Hide file tree
Showing 17 changed files with 692 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
@@ -0,0 +1,34 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
22 changes: 22 additions & 0 deletions build.ps1
@@ -0,0 +1,22 @@
Set-Location src

# Build project.
dotnet build

# Create the Swagger file.
Set-Location Sample.Api
dotnet swagger "tofile" --output "../../res/swagger.json" "../Sample.Api/bin/Debug/netcoreapp2.1/Sample.Api.dll" v1
Set-Location ..

# Clear the generated code.
Remove-Item "Sample.Client/Generated" -Force -Recurse

# Generate client.
autorest --input-file="../res/swagger.json" `
--output-folder="Sample.Client/Generated" `
--namespace="Sample.Client" `
--override-client-name="SampleClient" `
--csharp

# Reset the location.
Set-Location ..
1 change: 1 addition & 0 deletions res/swagger.json
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"version":"v1","title":"Sample API"},"paths":{"/api/Foo":{"get":{"tags":["Foo"],"operationId":"Foos_GetAll","consumes":[],"produces":["text/plain","application/json","text/json"],"parameters":[],"responses":{"200":{"description":"Success","schema":{"uniqueItems":false,"type":"array","items":{"type":"string"}}}}}}},"definitions":{},"tags":[]}
19 changes: 19 additions & 0 deletions src/Sample.Api/Controllers/FooController.cs
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace Sample.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class FooController : ControllerBase
{
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<string>), 200)]
[SwaggerOperation(OperationId = "Foos_GetAll")]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "foo", "bar" };
}
}
}
24 changes: 24 additions & 0 deletions src/Sample.Api/Program.cs
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Sample.Api
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
30 changes: 30 additions & 0 deletions src/Sample.Api/Properties/launchSettings.json
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50360",
"sslPort": 44350
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Sample.Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
21 changes: 21 additions & 0 deletions src/Sample.Api/Sample.Api.csproj
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Swashbuckle.AspNetCore.Cli" Version="3.0.0-beta1" />
</ItemGroup>

</Project>
55 changes: 55 additions & 0 deletions src/Sample.Api/Startup.cs
@@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;

namespace Sample.Api
{
public class Startup
{
public IConfiguration Configuration { get; }

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.EnableAnnotations();
c.SwaggerDoc("v1", new Info
{
Title = "Sample API",
Version = "v1"
});
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseMvc();

app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sample API");
});
}
}
}
9 changes: 9 additions & 0 deletions src/Sample.Api/appsettings.Development.json
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
8 changes: 8 additions & 0 deletions src/Sample.Api/appsettings.json
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit 945208e

Please sign in to comment.