Skip to Content
TAdminWebApi contracts and generator

WebApi contracts and generator

On this page

Unified results

TWebApi.UnifyResult and UnifyResult<T> define a response envelope. Default JSON property names use camelCase:

{ "code": 200, "data": { "name": "Example" }, "msg": null, "time": "2026-01-01T00:00:00Z", "isSuccess": true }

Code == 200 means business success. The filter maps errors to their corresponding HTTP statuses.

UnifyResultFilter recognizes IOperResult. The table describes the common filter’s default conversions; host-specific domain filters may extend them. Responses already sent are not wrapped again.

Controller result or failure sourceUnified response
Ordinary successful return valueCode = 200, original value in Data
Successful IOperResultCode = 200, content in Data, error-description field mapped to Msg
Failed IOperResultCode = 500; OperCode is not copied directly to HTTP status
Unauthenticated / forbidden / password change required401 / 403 / 403 respectively
Invalid arguments or JSON400; argument validation failure uses 422
KeyNotFoundException404
Oversized body / canceled operation413 / 503 respectively

For example, a failed result with OperCode = 404 still follows the failed-IOperResult branch and becomes 500. Express an intended HTTP 404 through the host’s supported error mapping, rather than changing only the result’s integer. OperResult.IsSuccess, response Code and actual HTTP status belong to different layers; see operation results.

Clients should check HTTP status, then process code, msg and data according to the response contract. Handle expired identity, insufficient permissions, validation failures and server errors separately. A non-200 response does not always require login again.

Filters and special responses

ValidationFilter validates arguments. AllowAnonymousAttribute declares anonymous endpoints. SkipUnifyResultAttribute skips the success envelope. TAdmin integrates identity and authorization filters.

Use explicit file response contracts for downloads and binary exports. Blob responses have different handling from JSON envelopes, and unwrapped success must retain correct failure status handling. TemporaryFileHttpResult supports sending a temporary file with an explicit resource lifecycle.

JSON type collection

TWebApi.Generator collects WebApi input and return types at compile time. GenerateJsonSerializableAttribute marks JSON context generation targets. The current generator maintains related physical .g.cs files near target source types. Inspect generated output and diagnostics after adding DTOs.

Provide JSON metadata for object fields, interface implementations, nested containers, closed generics and dynamic value types. Register contexts with SystemTextJsonService and the WebApi serialization pipeline.

AOT and public contracts

Use named DTO types and the host’s common integer and time converters. Native AOT requires JSON metadata for input, output and wrapper types.

Source lives in TAdmin/src/TWebApi and TAdmin/analyzer/TWebApi.Generator. See hosting and TUtility JSON.