One operation, many shapes, one contract
A workflow's PATCH /order/{id}/{eventID} takes a different payload for each event, and each event may need different authorities. Most frameworks describe it as one call that takes Object. Chenile lists its variants once, publishes the same variants to AI agents, OpenAPI and the service registry, and uses them to type and guard every request.
Exchange
Payload
What you write, and what Chenile publishes from it
The source on the left is all there is. The OpenAPI 3.1 document and the MCP tools on the right are generated from it at startup, from the same variants and the same schema generator.
One PATCH /order/{id}/{eventID}, typed per event.
One POST /q/{queryName}, typed per query, guarded per tenant.
<!-- who may raise each event --> <event-information eventId="submit" meta-acls="order.submit"/> <event-information eventId="cancel" meta-acls="order.cancel"/> <flow id="order-flow" default="true"> <manual-state id="DRAFT" initialState="true"> <on eventId="submit" newStateId="SUBMITTED" meta-description="Submit the order for approval"/> <on eventId="cancel" newStateId="CANCELLED" meta-description="Cancel the order"/> </manual-state> <manual-state id="SUBMITTED"/> <manual-state id="CANCELLED"/> </flow>
// The action's second type argument is the event's payload type. public class SubmitOrderAction extends AbstractSTMTransitionAction<Order, SubmitPayload> { … } public record SubmitPayload(String comment, LocalDate deliveryDate) {} // One controller method serves every event. @PatchMapping("/order/{id}/{eventID}") @BodyTypeSelector("orderBodyTypeSelector") // StmBodyTypeSelector @ChenileOperation(contractName = "order_processById", description = "Process an order workflow event") @ChenileMCP @SecurityConfig public ResponseEntity<…> processById(HttpServletRequest request, @PathVariable String id, @PathVariable String eventID, @ChenileParamType(Object.class) @RequestBody String eventPayload) { return process(request, id, eventID, eventPayload); }
[
{ "name": "students", "id": "Student.getAll",
"description": "Search students",
"acls": ["student.read"],
"paginated": true, "sortable": true,
"columnMetadata": {
"branch": {
"columnType": "DropDown",
"dropDownValues": ["CSE", "ECE"],
"filterable": true, "containsQuery": true,
"sortable": true },
"name": {
"columnType": "Text",
"filterable": true, "likeQuery": true }
} },
{ "tenantId": "acme", "name": "students",
"id": "acme.Student.getAll",
"description": "Search students (acme's own SQL and ACLs)",
"acls": ["acme.registrar"], … }
]
// Your own query controller, so it can carry @SecurityConfig. // The queryPolymorph bean ships with chenile-query-controller. @PostMapping("/q/{queryName}") @ChenileOperation(contractName = "querySearch", description = "Execute a named Chenile query") @ChenilePolymorph("queryPolymorph") @SecurityConfig public ResponseEntity<GenericResponse<SearchResponse>> search( HttpServletRequest request, @PathVariable String queryName, @RequestBody SearchRequest<Map<String, Object>> searchRequest) { return process("search", request, queryName, searchRequest); } // Per request: x-chenile-tenant-id: acme → needs acme.registrar // any other tenant → needs student.read
paths: /order/{id}/submit: # one path per event patch: operationId: order_processById_submit summary: Submit the order for approval x-chenile-variant: order_processById_submit x-chenile-authorities: [order.submit] parameters: - name: id in: path required: true schema: { type: string } requestBody: content: application/json: schema: { $ref: '#/components/schemas/SubmitPayload' } /order/{id}/cancel: patch: operationId: order_processById_cancel x-chenile-authorities: [order.cancel] … components: schemas: SubmitPayload: # JSON Schema 2020-12 type: object properties: comment: { type: string } deliveryDate: { type: string, format: date }
{
"name": "order_processById_submit",
"description": "Submit the order for approval",
"inputSchema": {
"type": "object",
"properties": {
"id": { "type": "string" },
"eventPayload": {
"type": "object",
"description": "Submit the order for approval",
"properties": {
"comment": { "type": "string" },
"deliveryDate": { "type": "string", "format": "date" }
}
}
}
}
}
// eventID is fixed to "submit", so the tool does not ask for it.
// order_processById_cancel is a second tool with its own schema.
paths: /q/students: # one path per query post: operationId: querySearch_students summary: Search students x-chenile-variant: querySearch_students x-chenile-authorities: [student.read] # the base definition's requestBody: content: application/json: schema: type: object properties: pageNum: { type: integer } numRowsInPage: { type: integer } sortCriteria: type: array items: properties: name: { type: string, enum: [branch] } ascendingOrder: { type: boolean } filters: type: object properties: branch: type: array items: { type: string, enum: [CSE, ECE] } name: { type: string } # LIKE match …
// From the MCP query endpoint, POST /mcp/q/{queryName} { "name": "mcpQuerySearch_students", "description": "Search students", "inputSchema": { "type": "object", "properties": { "searchRequest": { "type": "object", "description": "Search request for query students", "properties": { "filters": { "type": "object", "properties": { "branch": { "type": "array", "items": { "type": "string", "enum": ["CSE", "ECE"] } }, "name": { "type": "string" } } }, "pageNum": { "type": "integer" }, … } } } } }
Abridged. Add an event to the states XML and it appears as a new path, a new MCP tool and a new guarded variant on the next start, with no Java change.
Abridged. The contract has one variant per query name, described by its base definition. At request time QueryPolymorph resolves the variant against the caller's tenant (x-chenile-tenant-id), so acme callers need acme.registrar and everyone else needs student.read.
The contract is decided once
Who lists the variants
A ChenilePolymorphProvider. Usually it is the operation's own body type selector: StmBodyTypeSelector lists one variant per workflow event, SubclassBodyTypeSelector one per registered subclass. When the variants come from somewhere else, such as one per query definition, name a provider with @ChenilePolymorph("bean"). The bean that types the request is the bean that describes it, so the two cannot drift.
What a variant says
A complete name (by default <contractName>_<suffix>), a description, the payload type or JSON schema, the fixed parameter values or body field that select it, and the authorities it needs. ChenilePolymorphInitializer computes the list at startup, checks that names are unique and that no two variants are selected the same way, and stores it on the operation.
Published once, the same everywhere
MCP publishes one tool per variant. OpenAPI publishes one path per variant selected by a path variable (for example PATCH /order/{id}/submit, or POST /q/students for queries) and a oneOf body for the others, with x-chenile-authorities. The service registry stores the variants with their JSON Schemas and serves an OpenAPI document for the whole system.
The same schema generator
Every schema comes from ChenileJsonSchemaGenerator (JSON Schema Draft 2020-12, the dialect of OpenAPI 3.1), so an AI agent, an OpenAPI client and the registry see the same shape for SubmitPayload.
Queries: one endpoint, a contract per query, ACLs per tenant
POST /q/{queryName} serves every query a deployable defines. QueryPolymorph makes each query a variant, so it gets its own OpenAPI path, its own MCP tool and its own guard.
A schema from the query definition
Each variant's request schema is built from the query's column metadata: filterable columns become filters (an array for contains queries, a one-or-two item array for ranges, an enum for drop-downs), sortable columns the sortCriteria names, and paging fields only when the query is paginated.
Tenant overrides, resolved per request
A tenant can redefine a query under the same name, with its own SQL and its own acls. The contract keeps one variant per name, described by the base definition. For each request, QueryPolymorph.resolveVariant looks up the caller's tenant (x-chenile-tenant-id) and returns that tenant's definition, so its ACLs are the ones checked.
Guarded by your controller
The query controller that ships with Chenile is unguarded. To enforce the ACLs, write your own query controller with @ChenilePolymorph("queryPolymorph") and a plain @SecurityConfig, as in the Query, per tenant example above.
The chenile-highway picks the variant
Every transport goes through the same highway, so an HTTP call, an MCP tool call, an event and a local proxy call are typed and guarded the same way.
1 · Which variant
Before any selector runs, the typing step matches the request against the variants: all of a variant's fixed values must equal the request's path variables and headers, and its body field (for subclasses) the body's, read with a streaming parser. The most specific match wins, and a tie is an error. A provider can resolve the variant itself, as queries do for tenant-specific definitions.
2 · Which type
The body type selector sets the payload type. If it sets none, the typing step falls back to the operation's default type (chenile.transform.selector-fallback, on by default). Then the transformers convert the body, JSON by default.
3 · Who may call it
The security interceptor runs after the typing step. A plain @SecurityConfig on the operation guards each request with its variant's authorities (a workflow event's meta-acls, a query's acls), and with the operation's own authorities when the variant has none.
Polymorphism, the concept → Developer guide → Every transport adapter →