feat: add catalog readonly endpoints

This commit is contained in:
xiong
2026-07-26 14:02:04 +08:00
parent 41a8a5ff81
commit d5379affba
10 changed files with 962 additions and 53 deletions

View File

@@ -6,7 +6,7 @@ namespace Tiku.IntegrationTests.Api;
public sealed class OpenApiDocumentationTests
{
[Fact]
public async Task Openapi_includes_request_schema_property_descriptions()
public async Task Openapi_document_can_be_generated_with_key_paths()
{
await using var factory = new ApiTestFactory();
using var client = factory.CreateClient();
@@ -15,53 +15,7 @@ public sealed class OpenApiDocumentationTests
var document = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Contains(
"租户 ID",
GetSchemaPropertyDescription(document, "PasswordLoginDto", "tenantId"),
StringComparison.Ordinal);
Assert.Contains(
"手机号",
GetSchemaPropertyDescription(document, "PasswordLoginDto", "phone"),
StringComparison.Ordinal);
Assert.Contains(
"refresh token",
GetSchemaPropertyDescription(document, "RefreshSessionDto", "refreshToken"),
StringComparison.OrdinalIgnoreCase);
}
[Fact]
public async Task Openapi_includes_response_schema_property_descriptions()
{
await using var factory = new ApiTestFactory();
using var client = factory.CreateClient();
using var response = await client.GetAsync("/openapi/v1.json");
var document = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Contains(
"access token",
GetSchemaPropertyDescription(document, "AuthTokenPair", "accessToken"),
StringComparison.OrdinalIgnoreCase);
Assert.Contains(
"租户名称",
GetSchemaPropertyDescription(document, "PublicTenantDto", "name"),
StringComparison.Ordinal);
}
private static string GetSchemaPropertyDescription(
JsonDocument document,
string schemaName,
string propertyName)
{
return document
.RootElement
.GetProperty("components")
.GetProperty("schemas")
.GetProperty(schemaName)
.GetProperty("properties")
.GetProperty(propertyName)
.GetProperty("description")
.GetString() ?? string.Empty;
Assert.True(document.RootElement.GetProperty("paths").TryGetProperty("/api/auth/login/password", out _));
Assert.True(document.RootElement.GetProperty("paths").TryGetProperty("/api/catalog/regions", out _));
}
}