-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
739 additions
and
519 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,12 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<LangVersion>latest</LangVersion> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\TypeScript.ContractGenerator\TypeScript.ContractGenerator.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</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 |
---|---|---|
@@ -1,24 +1,21 @@ | ||
using System; | ||
|
||
using AspNetCoreExample.Api.Models; | ||
using AspNetCoreExample.Api.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AspNetCoreExample.Api.Controllers | ||
namespace AspNetCoreExample.Api.Controllers; | ||
|
||
[Route("v1/user/{userId}/blog")] | ||
public class NotesController : ControllerBase | ||
{ | ||
[Route("v1/user/{userId}/blog")] | ||
public class NotesController : ControllerBase | ||
[HttpPost] | ||
public ActionResult AddEntry(Guid userId, [FromBody] BlogEntry entry) | ||
{ | ||
[HttpPost] | ||
public ActionResult AddEntry(Guid userId, [FromBody] BlogEntry entry) | ||
{ | ||
return Ok(); | ||
} | ||
return Ok(); | ||
} | ||
|
||
[HttpPost("batch")] | ||
public ActionResult AddEntries(Guid userId, [FromBody] BlogEntry[] entries) | ||
{ | ||
return Ok(); | ||
} | ||
[HttpPost("batch")] | ||
public ActionResult AddEntries(Guid userId, [FromBody] BlogEntry[] entries) | ||
{ | ||
return Ok(); | ||
} | ||
} |
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,30 +1,38 @@ | ||
using System; | ||
|
||
using AspNetCoreExample.Api.Models; | ||
using AspNetCoreExample.Api.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AspNetCoreExample.Api.Controllers | ||
namespace AspNetCoreExample.Api.Controllers; | ||
|
||
[Route("v1/users")] | ||
public class UserController : ControllerBase | ||
{ | ||
[Route("v1/user")] | ||
public class UserController : ControllerBase | ||
[HttpPost] | ||
public ActionResult CreateUser([FromBody] User user) | ||
{ | ||
return Ok(); | ||
} | ||
|
||
[HttpDelete("{userId:guid}")] | ||
public ActionResult DeleteUser(Guid userId) | ||
{ | ||
return Ok(); | ||
} | ||
|
||
[HttpGet("{userId:guid}")] | ||
public ActionResult<User> GetUser(Guid userId) | ||
{ | ||
[HttpPost] | ||
public ActionResult CreateUser([FromBody] User user) | ||
{ | ||
return Ok(); | ||
} | ||
return Ok(null); | ||
} | ||
|
||
[HttpDelete("{userId}")] | ||
public ActionResult DeleteUser(Guid userId) | ||
{ | ||
return Ok(); | ||
} | ||
[HttpGet] | ||
public ActionResult<User[]> SearchUsers([FromQuery] string name) | ||
{ | ||
return Ok(TotallyNotHttpMethod(name)); | ||
} | ||
|
||
[HttpGet("{userId}")] | ||
public ActionResult<User> GetUser(Guid userId) | ||
{ | ||
return Ok(null); | ||
} | ||
private User[] TotallyNotHttpMethod(string name) | ||
{ | ||
return Array.Empty<User>(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
AspNetCoreExample.Api/Controllers/WeatherForecastController.cs
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,62 @@ | ||
using System.Text.Json; | ||
|
||
using AspNetCoreExample.Api.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
using SkbKontur.TypeScript.ContractGenerator.TypeBuilders.ApiController; | ||
|
||
namespace AspNetCoreExample.Api.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class WeatherForecastController : ControllerBase | ||
{ | ||
public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
[HttpGet(Name = "GetWeatherForecast")] | ||
public IEnumerable<WeatherForecast> Get() | ||
{ | ||
return Enumerable.Range(1, 5) | ||
.Select(index => new WeatherForecast | ||
{ | ||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = summaries[Random.Shared.Next(summaries.Length)] | ||
}) | ||
.ToArray(); | ||
} | ||
|
||
[HttpPost("Update/{city}")] | ||
public void Update(string city, [FromBody] WeatherForecast forecast, CancellationToken cancellationToken) | ||
{ | ||
} | ||
|
||
[HttpPost("~/[action]")] | ||
public void Reset(int seed) | ||
{ | ||
} | ||
|
||
[UrlOnly] | ||
[HttpGet("{city}")] | ||
public ActionResult Download(string city) | ||
{ | ||
var forecast = new WeatherForecast | ||
{ | ||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(1)), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = summaries[Random.Shared.Next(summaries.Length)] | ||
}; | ||
return File(JsonSerializer.SerializeToUtf8Bytes(forecast), "application/json"); | ||
} | ||
|
||
private static readonly string[] summaries = | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
private readonly ILogger<WeatherForecastController> logger; | ||
} |
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,8 +1,7 @@ | ||
namespace AspNetCoreExample.Api.Models | ||
namespace AspNetCoreExample.Api.Models; | ||
|
||
public class BlogEntry | ||
{ | ||
public class BlogEntry | ||
{ | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
} | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
} |
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,10 +1,7 @@ | ||
using System; | ||
namespace AspNetCoreExample.Api.Models; | ||
|
||
namespace AspNetCoreExample.Api.Models | ||
public class User | ||
{ | ||
public class User | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
} |
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,15 @@ | ||
using SkbKontur.TypeScript.ContractGenerator.Attributes; | ||
|
||
namespace AspNetCoreExample.Api.Models; | ||
|
||
public class WeatherForecast | ||
{ | ||
public DateOnly Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
[ContractGeneratorIgnore] | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
public string? Summary { get; set; } | ||
} |
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,25 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
20 changes: 20 additions & 0 deletions
20
AspNetCoreExample.Api/TypeScriptConfiguration/CustomGenerator.cs
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,20 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
using SkbKontur.TypeScript.ContractGenerator; | ||
using SkbKontur.TypeScript.ContractGenerator.Internals; | ||
using SkbKontur.TypeScript.ContractGenerator.TypeBuilders.ApiController; | ||
|
||
namespace AspNetCoreExample.Api.TypeScriptConfiguration; | ||
|
||
public class CustomGenerator : CustomTypeGenerator | ||
{ | ||
public CustomGenerator() | ||
{ | ||
var controllerBase = TypeInfo.From<ControllerBase>(); | ||
WithTypeLocationRule(t => controllerBase.IsAssignableFrom(t), t => $"Api/{t.Name.Replace("Controller", "Api")}") | ||
.WithTypeLocationRule(t => !controllerBase.IsAssignableFrom(t), t => $"DataTypes/{t.Name}") | ||
.WithTypeRedirect(TypeInfo.From<Guid>(), "Guid", @"DataTypes\Guid") | ||
.WithTypeRedirect(TypeInfo.From<DateOnly>(), "DateOnly", @"DataTypes\DateOnly") | ||
.WithTypeBuildingContext(t => controllerBase.IsAssignableFrom(t), (u, t) => new ApiControllerTypeBuildingContext(u, t)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
AspNetCoreExample.Api/TypeScriptConfiguration/TypesProvider.cs
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,20 @@ | ||
using AspNetCoreExample.Api.Controllers; | ||
|
||
using SkbKontur.TypeScript.ContractGenerator; | ||
using SkbKontur.TypeScript.ContractGenerator.Abstractions; | ||
using SkbKontur.TypeScript.ContractGenerator.Internals; | ||
|
||
namespace AspNetCoreExample.Api.TypeScriptConfiguration; | ||
|
||
public class TypesProvider : IRootTypesProvider | ||
{ | ||
public ITypeInfo[] GetRootTypes() | ||
{ | ||
return new[] | ||
{ | ||
TypeInfo.From<WeatherForecastController>(), | ||
TypeInfo.From<UserController>(), | ||
TypeInfo.From<NotesController>() | ||
}; | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
Oops, something went wrong.