SMS služba: prostředník nad SMS-Služba.cz (API XML 3.0)

- JSON API /v1: odeslání SMS, doručenka, události, potvrzení událostí, kredit
- vlastní API klíč pro každou aplikaci (X-Api-Key, API_KEYS)
- po chybě přihlášení k bráně se volání zastaví, aby se účet nezablokoval
- heslo maskované v logu, odeslání se nikdy neopakuje automaticky
- /health, /docs a OpenAPI s prefixem z ROOT_PATH
- .NET 10, šablona .NET 8 nahrazena projektem v src/, testy v tests/
- dokumentace: návrh, stav a návod pro napojení aplikací
This commit is contained in:
JiriUhlir
2026-10-20 10:21:03 +02:00
parent 908d6c9954
commit 63547942af
57 changed files with 3233 additions and 40 deletions
+55
View File
@@ -0,0 +1,55 @@
using Microsoft.OpenApi;
using SmsSluzba.Api.Auth;
namespace SmsSluzba.Api.OpenApi;
internal static class OpenApiSetup
{
public const string DocumentPath = "/openapi/v1.json";
private const string ApiKeySchemeId = "ApiKey";
private const string ProtectedPathPrefix = "/v1/";
public static IServiceCollection AddSmsOpenApi(this IServiceCollection services, string? rootPath) =>
services.AddOpenApi(options => options.AddDocumentTransformer((document, _, _) =>
{
document.Info = new OpenApiInfo
{
Title = "SMS služba",
Version = "v1",
Description = "Prostředník nad SMS-Služba.cz. Návod pro napojení aplikací je v documentation/integration.md.",
};
// Behind the AppFactory proxy the request host is internal and the prefix is stripped,
// so a relative server with ROOT_PATH keeps "Try it out" on /apps/<app-id>.
document.Servers = [new OpenApiServer { Url = rootPath ?? "/" }];
document.Components ??= new OpenApiComponents();
document.Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
document.Components.SecuritySchemes[ApiKeySchemeId] = new OpenApiSecurityScheme
{
Type = SecuritySchemeType.ApiKey,
Name = ApiKeyFilter.HeaderName,
In = ParameterLocation.Header,
Description = "API klíč aplikace.",
};
foreach (var (path, item) in document.Paths)
{
if (!path.StartsWith(ProtectedPathPrefix, StringComparison.Ordinal))
{
continue;
}
foreach (var operation in item.Operations?.Values ?? Enumerable.Empty<OpenApiOperation>())
{
operation.Security ??= [];
operation.Security.Add(new OpenApiSecurityRequirement
{
[new OpenApiSecuritySchemeReference(ApiKeySchemeId, document)] = [],
});
}
}
return Task.CompletedTask;
}));
}