Namespaces, assemblies, projects and directories, the solution, binaries, images, systemd units, config paths, environment variables, protocol method names, the media type and the raw chunk magic all move to MoShiro/moshiro. Existing data and deployments are not compatible and must be recreated. Also fix the architecture tests after the solution layout change and make the update tests independent of their order.
26 lines
1.0 KiB
C#
26 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Builder;
|
||
using Microsoft.AspNetCore.Http;
|
||
|
||
namespace MoShiro.Backend.Api;
|
||
|
||
public static class EndpointConventions
|
||
{
|
||
/// <summary>每个端点都必须有 operationId(snake_case,资源_动作)、summary 和 tag。</summary>
|
||
public static RouteHandlerBuilder Api(this RouteHandlerBuilder builder, string operationId, string summary, string tag) =>
|
||
builder.WithName(operationId).WithSummary(summary).WithTags(tag);
|
||
|
||
public static RouteHandlerBuilder Returns<T>(this RouteHandlerBuilder builder, int status = StatusCodes.Status200OK) =>
|
||
builder.Produces<T>(status);
|
||
|
||
/// <summary>登记该端点可能返回的错误状态(problem+json),让 OpenAPI 文档完整。</summary>
|
||
public static RouteHandlerBuilder ProducesProblems(this RouteHandlerBuilder builder, params int[] statuses)
|
||
{
|
||
foreach (int status in statuses)
|
||
{
|
||
builder.Produces<ProblemDto>(status, Problems.ContentType);
|
||
}
|
||
|
||
return builder;
|
||
}
|
||
}
|