XiHan.Framework.Protocols.Http
5.0.0-preview.1
Prefix Reserved
See the version list below for details.
dotnet add package XiHan.Framework.Protocols.Http --version 5.0.0-preview.1
NuGet\Install-Package XiHan.Framework.Protocols.Http -Version 5.0.0-preview.1
<PackageReference Include="XiHan.Framework.Protocols.Http" Version="5.0.0-preview.1" />
<PackageVersion Include="XiHan.Framework.Protocols.Http" Version="5.0.0-preview.1" />
<PackageReference Include="XiHan.Framework.Protocols.Http" />
paket add XiHan.Framework.Protocols.Http --version 5.0.0-preview.1
#r "nuget: XiHan.Framework.Protocols.Http, 5.0.0-preview.1"
#:package XiHan.Framework.Protocols.Http@5.0.0-preview.1
#addin nuget:?package=XiHan.Framework.Protocols.Http&version=5.0.0-preview.1&prerelease
#tool nuget:?package=XiHan.Framework.Protocols.Http&version=5.0.0-preview.1&prerelease
XiHan.Framework.Protocols.Http
HTTP 协议适配器(Ring 5)。提供 protocols.http@1,把登记表里暴露给 HTTP 的操作映射为 ASP.NET Core 端点(RFC-0011、spec/conventions/operation-ids.md)。
builder.AddXiHan(xihan => xihan.UseStandardProfile().UseFeature<HttpProtocolFeature>().UseFeature<OrdersFeature>());
var app = builder.Build();
app.UseXiHan(); // 构造上下文、把端点元数据里的操作描述放入上下文、回写 Problem Details
app.MapXiHanOperations(); // orders.create → POST /orders,orders.get → GET /orders/{id} …
app.MapXiHanOpenApi(); // /openapi.json:OpenAPI 3.1,从登记表与 OperationSchema 生成,带权限 / 策略扩展
规则
路由推导:
create→POST /{resource},list→GET /{resource};请求声明了id属性时get→GET /{resource}/{id}、update→PUT /{resource}/{id}、delete→DELETE /{resource}/{id}、其他动词 →POST /{resource}/{id}:{verb}(契约声明只读且请求没有嵌套对象时改用GET,Google AIP-136,ADR-0041),没有id时去掉/{id}段落在集合(或单例资源)上(GET /{resource}、PUT /{resource}、DELETE /{resource}、POST /{resource}:{verb});get/list/delete的请求带嵌套对象时(GET / DELETE 不读请求体)改用 POST 自定义动词(POST /{resource}:list)。是否含id看请求的序列化元数据,不用反射;没有类型化元数据的插件代理看请求 Schema 的properties。两个操作推导出同一条路由时MapXiHanOperations以PROTOCOLS_CONFLICT_002启动失败。显式覆盖:XiHan:Protocols:Http:Routes:<操作 ID>=POST /orders:export;前缀XiHan:Protocols:Http:RoutePrefix=/api。绑定:路由值(最优先)、JSON 请求体(POST/PUT/PATCH,必须是对象)、查询串合并成一个 JSON 对象交给
IOperationInvoker;路由值与查询串按请求类型序列化元数据里的属性类型写成 JSON 布尔、整数、浮点、数值枚举或数组(集合属性的单值也写成数组),属性名取序列化名、不分大小写匹配;找不到属性或没有元数据(插件代理)时写字符串,多值写字符串数组;属性名按请求类型序列化上下文的命名策略匹配,建议PropertyNamingPolicy = CamelCase加PropertyNameCaseInsensitive = true(示例的SampleJsonContext)。响应:成功
create为 201、其余 200,正文是响应类型的 JSON;写出方式以OperationResponseWriter挂在端点元数据上,幂等回放时端点不执行,由UseXiHan()用它写出首次的状态码与正文(ADR-0064);失败由UseXiHan()写成 RFC 9457 Problem Details(detail按Accept-Language本地化;VALIDATION 错误带字段级errors——字段键 → 本地化消息数组,所有错误带标量details,见Hosting.AspNetCore)。授权:Authorize 阶段按契约的权限或策略判定(描述经端点元数据进入上下文);
Stability.Internal的操作不发布;Expose不含Http的操作不发布。OpenAPI:
MapXiHanOpenApi(options?, pattern = "/openapi.json")在第一次请求时从登记表、权限码注册表、已装配的认证处理器与宿主的全部端点生成 OpenAPI 3.1 并缓存,绕过内核管道。OpenApiOptions指定info.title/info.version/servers(缺省标题取应用名、版本取框架版本、不写servers)。路径与方法同路由推导;路由参数与(无请求体方法的)查询参数、请求体、成功响应都来自OperationSchema,$defs提升到components/schemas(字符串枚举定义也是一个组件,属性与查询参数以$ref引用);失败响应统一引用ProblemDetails组件(标准成员加code、traceId、errors:字段键 → 字符串数组、details:名字 → 标量)。没有 Schema 的操作只发布路径与operationId。OpenApiDocumentBuilder.Build(OpenApiDocumentSource)是不经宿主的生成入口(测试与工具用);OpenApiDocumentSource.FromServices(services, options, endpoints, locale)从容器组装与MapXiHanOpenApi相同的输入(登记表、权限码注册表、认证方案、普通端点、按区域的摘要),导出工具据此得到与/openapi.json逐字节相同的文档(ADR-0034)。OpenAPI 认证方案(ADR-0032):容器里有
Scheme == "Bearer"的IAuthenticationHandler(Security.Jwt、Security.OpenIdConnect)时发布components.securitySchemes.bearer(http/bearer/JWT)并挂全局security: [{ bearer: [] }],没有权限也没有策略要求的操作与端点标security: [];权限码与策略名不进 scope,仍只走x-xihan-*。ApiKey 等其他方案不发布。OpenAPI 操作文案(ADR-0052):
summary取消息目录里<操作 ID>.title,description取<操作 ID>.description(-换_,与 MCPtools/list同两个键),各自没有就不写;授权要求由生成器按区域附在description末尾一行(HttpMessages:需要权限 <码>(<显示名>)/ 需要策略 <名> / 需要登录),权限的显示名先取permissions.<权限码>.name(-换_),没有再取权限定义的;x-xihan-permissions的displayName/description同样先取permissions.<权限码>.name/.description。文案里不要再手写。装配了本地化时按Accept-Language协商出的区域分别生成与缓存(Content-Language标出区域,缺省en-US),没有装配时只有一份文档、没有目录文案。OpenAPI 标签与分组(ADR-0052):顶层
tags的x-displayName/description取openapi.tags.<资源段>.name/.description,name仍是资源码;OpenApiOptions.Groups声明OpenApiGroup(名字, 排序, 所属特性, 额外标签),全量文档带x-tagGroups(一个标签只归排序靠前的一组),每组另发/openapi/<组名>.json(标题取openapi.groups.<组名>.name),GetXiHanOpenApiDocuments()列出全部文档给 Scalar:foreach (var link in app.GetXiHanOpenApiDocuments(options)) scalar.AddDocument(link.Name, link.Title, link.Url);。OpenAPI 字段说明(ADR-0052):Schema 里
Kernel.Generators从 XML 注释折进的description进参数、请求体与成功响应(没有根说明时是按区域的「成功」);某个区域可用openapi.schemas.<snake_case 的 Schema 名>.description与.properties.<snake_case 的属性名>覆盖。OpenAPI 普通端点(ADR-0032):
EndpointDataSource里没有OperationDescriptor、有 HTTP 方法元数据、带IAcceptsMetadata或IProducesResponseTypeMetadata之一、没有ExcludeFromDescription()的路由端点进文档——Hub、探针、重定向、静态资源没有这两种元数据,自然不进。路由参数作path参数(string);WithName作operationId,WithSummary/WithDescription/WithTags照搬;RequireXiHanPermission/RequireXiHanPolicy/RequireXiHanAuthentication出x-xihan-permission/x-xihan-policy,权限码并入x-xihan-permissions。Accepts/Produces按内容类型写:JSON 只引用已登记操作的根 Schema(显式WithXiHanOperationSchema(request:, response:),或按Accepts<T>/Produces<T>的类型与操作的请求 / 响应类型自动匹配,取 ID 最小且有 Schema 的操作;被引用的根提升到components/schemas/<title>,操作自己也改为$ref),multipart/form-data是含format: binary属性(file/files)的对象,表单是对象,text/*与string是字符串,其余二进制是format: binary的字符串;失败响应同样引用ProblemDetails。JSON 类型引用不到以PROTOCOLS_VALIDATION_010生成失败,不做第二套推导;与操作共用一条路由以PROTOCOLS_CONFLICT_002生成失败。OpenAPI 权限扩展(ADR-0031):契约有
Permission的操作带x-xihan-permission(权限码),有Policy的带x-xihan-policy(策略名),都没有则不带;不占用标准security/securitySchemes(权限码不是 OAuth scope,那些字段留给认证方案)。components.x-xihan-permissions按权限码(序数排序)给出权限定义,收录范围 = 文档里已发布操作引用的权限码 ∪PermissionRegistry登记的全部定义——只在 gRPC / MCP 暴露的操作或端点级RequireXiHanPermission用到的权限也在其中,授权界面据此生成;被引用但未登记的只有code,description为 null 时省略。OpenApiDocumentBuilder.Build(registry, options, permissions, title, version)的permissions为 null 时只按引用写。{ "paths": { "/orders": { "post": { "operationId": "orders.create", "x-xihan-permission": "orders.write" } } }, "components": { "schemas": { "...": {} }, "x-xihan-permissions": { "orders.read": { "code": "orders.read", "displayName": "Read orders" }, "orders.write": { "code": "orders.write", "displayName": "Place orders", "description": "Create orders for the current tenant." } } } }
依赖方向
依赖 XiHan.Framework.Kernel、XiHan.Framework.Hosting.AspNetCore 与 Microsoft.AspNetCore.App。协议适配器在宿主之上(Ring 5)。
状态
P3:可用。OpenAPI 的 Schema 由 Kernel.Generators 产出。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- XiHan.Framework.Hosting.AspNetCore (>= 5.0.0-preview.1)
- XiHan.Framework.Kernel (>= 5.0.0-preview.1)
- XiHan.Framework.Localization.Abstractions (>= 5.0.0-preview.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on XiHan.Framework.Protocols.Http:
| Package | Downloads |
|---|---|
|
XiHan.Framework.Profiles.Full
曦寒框架 Full 组合包 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.0-preview.2 | 44 | 11/6/2026 |
| 5.0.0-preview.1 | 45 | 11/4/2026 |