Files
mizan/protocol/mizan-codegen/tests/fixtures/afi_schema.json
Ryth Azhur 43bcf3f26f Mizan codegen substrate: Rust kernel + Rust codegen binary, JS generator deleted
The Mizan codegen substrate moves off JavaScript template-literal emission
onto a compiled Rust binary that consumes the same OpenAPI + x-mizan-* IR
the JS substrate consumed. Three structural wins fall out of one move:

1. Moat closes. The codegen logic (how `affects` becomes auto-invalidation,
   how named contexts collapse onto bundled fetches, how the registry-to-
   Provider mapping is shaped) ships compiled instead of as source bytes
   in every consumer's node_modules.

2. Pattern F (lines.push append-walls) becomes structurally unauthorable.
   The emit substrate is askama templates in templates/<target>/*.j2 —
   actual target-language files with {{ ... }} substitution markers,
   syntax-highlighted natively, type-checked against the render context
   structs at compile time. The Rust emit modules build typed render
   contexts and call .render(); no string-builder surface exists.

3. OpenAPI `default`-bearing fields now emit as non-optional in TS / Python
   / Rust — the server always populates them, so consumer code reads them
   without nullable checks. Surfaced by Blazr's typecheck on regeneration.

Layout:
  frontends/mizan-rust/        — Rust port of @mizan/base; #[cfg(feature="pyo3")]
                                 exposes PyMizanClient for the Python target.
  protocol/mizan-codegen/      — codegen binary source + askama templates.
  protocol/mizan-generate/     — npm-package shim. bin/launcher.mjs dispatches
                                 to the platform-appropriate prebuilt binary.
                                 Old generator/ JS tree deleted.
  tests/rust/                  — wire-parity drivers. drive_kernel exercises
                                 raw client.call() / fetch_context(); drive_emitted
                                 exercises the typed crate the codegen emits.
  tests/afi/afi_codegen_app.py — codegen entrypoint module (imports + registers).
  backends/mizan-fastapi/.../schema.py — adds outputNullable so the Rust
                                 codegen can wrap T | None responses in Option<T>.

Verification:
  - 20 mizan-codegen tests green (IR deserialization, byte-equivalent
    parity vs JS baseline for stage1/rust/python/react/vue/svelte,
    structural test for channels).
  - tests/rust/run_wire_parity.py — 12/12 probes green via the Rust binary
    driving the FastAPI fixture end-to-end.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 18:26:32 -04:00

685 lines
16 KiB
JSON

{
"openapi": "3.1.0",
"info": {
"title": "mizan Server Functions",
"description": "Auto-generated schema for mizan server functions",
"version": "1.0.0"
},
"paths": {
"/mizan/echo": {
"post": {
"summary": "Echoes the input back.",
"operationId": "echo",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/echoInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/echoOutput"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": false
}
}
},
"/mizan/whoami": {
"post": {
"summary": "Returns the current user identity.",
"operationId": "whoami",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/whoamiOutput"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": false
}
}
},
"/mizan/user_profile": {
"post": {
"summary": "One half of the user context.",
"operationId": "userProfile",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/userProfileInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/userProfileOutput"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": "user"
}
}
},
"/mizan/user_orders": {
"post": {
"summary": "Other half of the user context \u2014 same param, proves param elevation.",
"operationId": "userOrders",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/userOrdersInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/userOrdersOutput"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": "user"
}
}
},
"/mizan/update_profile": {
"post": {
"summary": "Mutation declaring affects on the user context.",
"operationId": "updateProfile",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/updateProfileInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/updateProfileOutput"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": false
}
}
},
"/mizan/find_user": {
"post": {
"summary": "Optional return \u2014 exercises Pydantic `T | None` schema introspection.",
"operationId": "findUser",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/findUserInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"anyOf": [
{
"$ref": "#/components/schemas/findUserOutput"
},
{
"type": "null"
}
],
"title": "Response Finduser"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": false
}
}
},
"/mizan/rename_user": {
"post": {
"summary": "Merge target \u2014 kernel splices return value into the user context.",
"operationId": "renameUser",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/renameUserInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/renameUserOutput"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
},
"x-mizan": {
"transport": "http",
"isContext": false
}
}
}
},
"components": {
"schemas": {
"HTTPValidationError": {
"properties": {
"detail": {
"items": {
"$ref": "#/components/schemas/ValidationError"
},
"type": "array",
"title": "Detail"
}
},
"type": "object",
"title": "HTTPValidationError"
},
"OrderOutput": {
"properties": {
"id": {
"type": "integer",
"title": "Id"
},
"user_id": {
"type": "integer",
"title": "User Id"
},
"total": {
"type": "integer",
"title": "Total"
}
},
"type": "object",
"required": [
"id",
"user_id",
"total"
],
"title": "OrderOutput"
},
"ValidationError": {
"properties": {
"loc": {
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
},
"type": "array",
"title": "Location"
},
"msg": {
"type": "string",
"title": "Message"
},
"type": {
"type": "string",
"title": "Error Type"
},
"input": {
"title": "Input"
},
"ctx": {
"type": "object",
"title": "Context"
}
},
"type": "object",
"required": [
"loc",
"msg",
"type"
],
"title": "ValidationError"
},
"echoInput": {
"properties": {
"text": {
"type": "string",
"title": "Text"
}
},
"type": "object",
"required": [
"text"
],
"title": "echoInput"
},
"echoOutput": {
"properties": {
"message": {
"type": "string",
"title": "Message"
}
},
"type": "object",
"required": [
"message"
],
"title": "echoOutput"
},
"findUserInput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
}
},
"type": "object",
"required": [
"user_id"
],
"title": "findUserInput"
},
"findUserOutput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
},
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"user_id",
"name"
],
"title": "findUserOutput"
},
"renameUserInput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
},
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"user_id",
"name"
],
"title": "renameUserInput"
},
"renameUserOutput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
},
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"user_id",
"name"
],
"title": "renameUserOutput"
},
"updateProfileInput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
},
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"user_id",
"name"
],
"title": "updateProfileInput"
},
"updateProfileOutput": {
"properties": {
"ok": {
"type": "boolean",
"title": "Ok"
}
},
"type": "object",
"required": [
"ok"
],
"title": "updateProfileOutput"
},
"userOrdersInput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
}
},
"type": "object",
"required": [
"user_id"
],
"title": "userOrdersInput"
},
"userOrdersOutput": {
"items": {
"$ref": "#/components/schemas/OrderOutput"
},
"type": "array",
"title": "userOrdersOutput"
},
"userProfileInput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
}
},
"type": "object",
"required": [
"user_id"
],
"title": "userProfileInput"
},
"userProfileOutput": {
"properties": {
"user_id": {
"type": "integer",
"title": "User Id"
},
"name": {
"type": "string",
"title": "Name"
}
},
"type": "object",
"required": [
"user_id",
"name"
],
"title": "userProfileOutput"
},
"whoamiOutput": {
"properties": {
"email": {
"type": "string",
"title": "Email"
},
"authenticated": {
"type": "boolean",
"title": "Authenticated"
}
},
"type": "object",
"required": [
"email",
"authenticated"
],
"title": "whoamiOutput"
}
}
},
"x-mizan-functions": [
{
"name": "echo",
"camelName": "echo",
"hasInput": true,
"inputType": "echoInput",
"outputType": "echoOutput",
"outputNullable": false,
"transport": "http",
"isContext": false,
"isForm": false,
"formName": null,
"formRole": null
},
{
"name": "whoami",
"camelName": "whoami",
"hasInput": false,
"inputType": null,
"outputType": "whoamiOutput",
"outputNullable": false,
"transport": "http",
"isContext": false,
"isForm": false,
"formName": null,
"formRole": null
},
{
"name": "user_profile",
"camelName": "userProfile",
"hasInput": true,
"inputType": "userProfileInput",
"outputType": "userProfileOutput",
"outputNullable": false,
"transport": "http",
"isContext": "user",
"isForm": false,
"formName": null,
"formRole": null
},
{
"name": "user_orders",
"camelName": "userOrders",
"hasInput": true,
"inputType": "userOrdersInput",
"outputType": "userOrdersOutput",
"outputNullable": false,
"transport": "http",
"isContext": "user",
"isForm": false,
"formName": null,
"formRole": null
},
{
"name": "update_profile",
"camelName": "updateProfile",
"hasInput": true,
"inputType": "updateProfileInput",
"outputType": "updateProfileOutput",
"outputNullable": false,
"transport": "http",
"isContext": false,
"isForm": false,
"formName": null,
"formRole": null,
"affects": [
{
"type": "context",
"name": "user"
}
]
},
{
"name": "find_user",
"camelName": "findUser",
"hasInput": true,
"inputType": "findUserInput",
"outputType": "findUserOutput",
"outputNullable": true,
"transport": "http",
"isContext": false,
"isForm": false,
"formName": null,
"formRole": null
},
{
"name": "rename_user",
"camelName": "renameUser",
"hasInput": true,
"inputType": "renameUserInput",
"outputType": "renameUserOutput",
"outputNullable": false,
"transport": "http",
"isContext": false,
"isForm": false,
"formName": null,
"formRole": null,
"merge": [
"user"
]
}
],
"x-mizan-contexts": {
"user": {
"functions": [
"user_profile",
"user_orders"
],
"params": {
"user_id": {
"type": "integer",
"sharedBy": [
"user_profile",
"user_orders"
],
"required": true
}
}
}
}
}