-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from LykkeCity/respect_required_attribute
Preserve information about required attributes
- Loading branch information
Showing
8 changed files
with
255 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26430.12 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lykke.Common.ApiLibrary", "src\Lykke.Common.ApiLibrary\Lykke.Common.ApiLibrary.csproj", "{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26430.12 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lykke.Common.ApiLibrary", "src\Lykke.Common.ApiLibrary\Lykke.Common.ApiLibrary.csproj", "{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWebService", "test\TestWebService\TestWebService.csproj", "{27EA72E9-6B13-4E7E-BB43-678C09103334}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1DF2AA57-4EE8-4E83-A2E1-420ECCEA8999}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{27EA72E9-6B13-4E7E-BB43-678C09103334}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{27EA72E9-6B13-4E7E-BB43-678C09103334}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{27EA72E9-6B13-4E7E-BB43-678C09103334}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{27EA72E9-6B13-4E7E-BB43-678C09103334}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {62E0D70F-9328-42B0-BB4F-FC9C4864AB10} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace TestWebService | ||
{ | ||
internal static class Program | ||
{ | ||
static Task Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel() | ||
.UseUrls("http://*:5000") | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseStartup<Startup>() | ||
.UseApplicationInsights() | ||
.Build(); | ||
|
||
return host.RunAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using Common.Log; | ||
using Lykke.Common.ApiLibrary.Middleware; | ||
using Lykke.Common.ApiLibrary.Swagger; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Newtonsoft.Json.Serialization; | ||
using Swashbuckle.AspNetCore.Swagger; | ||
|
||
namespace TestWebService | ||
{ | ||
public class Startup | ||
{ | ||
|
||
public IContainer ApplicationContainer { get; private set; } | ||
public IConfigurationRoot Configuration { get; } | ||
public ILog Log { get; private set; } | ||
|
||
public Startup(IHostingEnvironment env) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(env.ContentRootPath) | ||
.AddEnvironmentVariables(); | ||
Configuration = builder.Build(); | ||
|
||
} | ||
|
||
public IServiceProvider ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddMvc() | ||
.AddJsonOptions(options => | ||
{ | ||
options.SerializerSettings.ContractResolver = | ||
new DefaultContractResolver(); | ||
}); | ||
|
||
services.AddSwaggerGen(options => | ||
{ | ||
options.DefaultLykkeConfiguration("v1", "ClientAccountRecovery API"); | ||
// options.SwaggerDoc( | ||
// $"v1", | ||
// new Info | ||
// { | ||
// Version = "v1", | ||
// Title = "App title" | ||
// }); | ||
}); | ||
services.Configure<MvcJsonOptions>(c => | ||
{ | ||
// Serialize all properties to camelCase by default | ||
c.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | ||
}); | ||
|
||
|
||
var builder = new ContainerBuilder(); | ||
builder.Populate(services); | ||
ApplicationContainer = builder.Build(); | ||
|
||
return new AutofacServiceProvider(ApplicationContainer); | ||
|
||
} | ||
|
||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseMvc(); | ||
app.UseSwagger(c => | ||
{ | ||
c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value); | ||
}); | ||
app.UseSwaggerUI(x => | ||
{ | ||
x.RoutePrefix = "swagger/ui"; | ||
x.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); | ||
}); | ||
app.UseStaticFiles(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace TestWebService | ||
{ | ||
[Route("api/[controller]")] | ||
[Produces("application/json")] | ||
[Consumes("application/json")] | ||
public class TestController : Controller | ||
{ | ||
[HttpPost("one")] | ||
[SwaggerOperation("NonNullableEnum")] | ||
[ProducesResponseType(typeof(ResponseModel), 200)] | ||
public IActionResult One([FromBody] RequestModel parameter) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
return Ok(new ResponseModel | ||
{ | ||
NonNullable = parameter.NonNullable, | ||
Nullable = parameter.Nullable, | ||
SomeDouble = parameter.SomeDouble, | ||
SomeInt = parameter.SomeInt, | ||
SomeString = parameter.SomeString | ||
}); | ||
} | ||
|
||
} | ||
|
||
[BindRequired] | ||
public class RequestModel | ||
{ | ||
[Required] | ||
public Enum NonNullable { get; set; } | ||
|
||
[Required] | ||
public Enum? Nullable { get; set; } | ||
|
||
[Required] | ||
public string SomeString { get; set; } | ||
|
||
[Required] | ||
public int SomeInt { get; set; } | ||
|
||
[Required] | ||
public double SomeDouble { get; set; } | ||
|
||
|
||
} | ||
|
||
public class ResponseModel | ||
{ | ||
[Required] | ||
public Enum NonNullable { get; set; } | ||
|
||
[Required] | ||
public Enum? Nullable { get; set; } | ||
|
||
[Required] | ||
public string SomeString { get; set; } | ||
|
||
[Required] | ||
public int SomeInt { get; set; } | ||
|
||
[Required] | ||
public double SomeDouble { get; set; } | ||
|
||
|
||
} | ||
public enum Enum | ||
{ | ||
One, | ||
Two, | ||
Three | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Lykke.Common.ApiLibrary\Lykke.Common.ApiLibrary.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary> |