Mizan IR: cut over to KDL, delete OpenAPI envelope
Replaces the transitional OpenAPI 3.0 + `x-mizan-*` extensions
substrate with the canonical Mizan IR as KDL, per docs/AFI_ARCHITECTURE.md:
"KDL is the contract; everything else (REST envelopes, OpenAPI
documents, framework idioms) is sediment around it."
End-to-end cutover. No transitional path left on main.
Forward direction:
cores/mizan-python/src/mizan_core/ir.py
build_ir() walks mizan_core.registry, introspects Pydantic
models directly (no JSON-Schema indirection), and emits the
Mizan IR document. The KDL grammar is locked in this file's
module docstring.
Backends emit KDL:
backends/mizan-fastapi/src/mizan_fastapi/ir.py
`python -m mizan_fastapi.ir <module>` — CLI entry point.
backends/mizan-django/.../management/commands/export_mizan_ir.py
`manage.py export_mizan_ir` — Django mgmt command.
Codegen consumes KDL:
protocol/mizan-codegen/Cargo.toml: + kdl = "6"
protocol/mizan-codegen/src/ir.rs: NamedType { Struct/List/Enum/Alias }
+ TypeShape { Primitive/Ref/List/Optional/Enum/Union } sum types,
replacing the JsonSchema sprawl. KDL parser walks the
`kdl::KdlDocument` tree into typed Rust structs.
protocol/mizan-codegen/src/fetch.rs: subprocess command switches
to the new IR-export entry points.
All emit modules (stage1 / react / python / rust / vue / svelte /
channels) port their type-walkers from JsonSchema to the new
sum types — case analysis collapses substantially.
Substrate-honesty wins beyond the moat closure:
- `int | bool` multi-arm unions land as `TypeShape::Union` (was
silently coerced to "string" before).
- `<CamelName>Output = list[T]` returns emit as named alias
types instead of struct-shaped wrappers, so consumer code
`.map()` works directly on the type.
- Pydantic field defaults flow through to `default` properties
in KDL, then back to non-optional shape in every target.
Deleted:
- backends/mizan-fastapi/src/mizan_fastapi/{cli,schema}.py
- backends/mizan-django/.../export_mizan_schema.py
- openapi-bearing half of mizan/export/__init__.py (edge
manifest generator preserved — separate concern).
- tests/afi/schema_normalizer.py
- tests/fixtures/{afi_schema.json, channels_schema.json}
- tests/fixtures/js_* baseline directories.
Verification:
- 20 mizan-codegen unit tests green (IR deserialization,
byte-equivalence parity across stage1/rust/python/react/vue/svelte
against fresh KDL-driven baselines, channels structural).
- tests/rust/run_wire_parity.py: 12/12 probes green driving
the binary end-to-end through KDL.
- Blazr studio-ui typechecks against the regenerated React client.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
18
protocol/mizan-codegen/tests/fixtures/baselines/vue/contexts/user.ts
vendored
Normal file
18
protocol/mizan-codegen/tests/fixtures/baselines/vue/contexts/user.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanFetch } from '@mizan/base'
|
||||
|
||||
import type { userProfileOutput, userOrdersOutput } from '../types'
|
||||
|
||||
export interface UserContextData {
|
||||
user_profile: userProfileOutput
|
||||
user_orders: userOrdersOutput
|
||||
}
|
||||
|
||||
export interface UserContextParams {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export function fetchUserContext(params: UserContextParams): Promise<UserContextData> {
|
||||
return mizanFetch('user', params)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/echo.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/echo.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { echoInput, echoOutput } from '../types'
|
||||
|
||||
export function callEcho(args: echoInput): Promise<echoOutput> {
|
||||
return mizanCall('echo', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/findUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/findUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { findUserInput, findUserOutput } from '../types'
|
||||
|
||||
export function callFindUser(args: findUserInput): Promise<findUserOutput> {
|
||||
return mizanCall('find_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/renameUser.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/renameUser.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { renameUserInput, renameUserOutput } from '../types'
|
||||
|
||||
export function callRenameUser(args: renameUserInput): Promise<renameUserOutput> {
|
||||
return mizanCall('rename_user', args)
|
||||
}
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/whoami.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/functions/whoami.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { whoamiOutput } from '../types'
|
||||
|
||||
export function callWhoami(): Promise<whoamiOutput> {
|
||||
return mizanCall('whoami', {})
|
||||
}
|
||||
14
protocol/mizan-codegen/tests/fixtures/baselines/vue/index.ts
vendored
Normal file
14
protocol/mizan-codegen/tests/fixtures/baselines/vue/index.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export * from './types'
|
||||
|
||||
export { fetchUserContext, type UserContextData, type UserContextParams } from './contexts/user'
|
||||
|
||||
export { callEcho } from './functions/echo'
|
||||
export { callWhoami } from './functions/whoami'
|
||||
export { callUpdateProfile } from './mutations/updateProfile'
|
||||
export { callFindUser } from './functions/findUser'
|
||||
export { callRenameUser } from './functions/renameUser'
|
||||
|
||||
// Stage 2 framework adapter
|
||||
export * from './vue'
|
||||
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/mutations/updateProfile.ts
vendored
Normal file
9
protocol/mizan-codegen/tests/fixtures/baselines/vue/mutations/updateProfile.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { mizanCall } from '@mizan/base'
|
||||
|
||||
import type { updateProfileInput, updateProfileOutput } from '../types'
|
||||
|
||||
export function callUpdateProfile(args: updateProfileInput): Promise<updateProfileOutput> {
|
||||
return mizanCall('update_profile', args)
|
||||
}
|
||||
64
protocol/mizan-codegen/tests/fixtures/baselines/vue/types.ts
vendored
Normal file
64
protocol/mizan-codegen/tests/fixtures/baselines/vue/types.ts
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
export interface OrderOutput {
|
||||
id: number
|
||||
user_id: number
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface echoInput {
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface echoOutput {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface findUserInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface findUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface renameUserOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileInput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface updateProfileOutput {
|
||||
ok: boolean
|
||||
}
|
||||
|
||||
export interface userOrdersInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export type userOrdersOutput = OrderOutput[]
|
||||
|
||||
export interface userProfileInput {
|
||||
user_id: number
|
||||
}
|
||||
|
||||
export interface userProfileOutput {
|
||||
user_id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface whoamiOutput {
|
||||
email: string
|
||||
authenticated: boolean
|
||||
}
|
||||
|
||||
96
protocol/mizan-codegen/tests/fixtures/baselines/vue/vue.ts
vendored
Normal file
96
protocol/mizan-codegen/tests/fixtures/baselines/vue/vue.ts
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
// AUTO-GENERATED by mizan — do not edit
|
||||
|
||||
import { ref, computed, onMounted, onUnmounted, onServerPrefetch, type ComputedRef } from 'vue'
|
||||
import { registerContext, type ContextState } from '@mizan/base'
|
||||
|
||||
import { fetchUserContext, type UserContextData, type UserContextParams, callUpdateProfile, callEcho, callWhoami, callFindUser, callRenameUser } from '../index'
|
||||
|
||||
export function useUserContext(params: UserContextParams) {
|
||||
const state = ref<ContextState<UserContextData>>({ data: null, status: 'idle', error: null })
|
||||
let handle: ReturnType<typeof registerContext> | null = null
|
||||
|
||||
onMounted(() => {
|
||||
handle = registerContext('user', params, () => fetchUserContext(params))
|
||||
handle.subscribe(() => { state.value = handle!.getState() })
|
||||
handle.refetch()
|
||||
})
|
||||
|
||||
onServerPrefetch(async () => {
|
||||
handle = registerContext('user', params, () => fetchUserContext(params))
|
||||
await handle.refetch()
|
||||
state.value = handle.getState()
|
||||
})
|
||||
|
||||
onUnmounted(() => { handle?.unregister() })
|
||||
|
||||
return {
|
||||
state,
|
||||
userProfile: computed(() => state.value.data?.user_profile ?? null) as ComputedRef<userProfileOutput | null>,
|
||||
userOrders: computed(() => state.value.data?.user_orders ?? null) as ComputedRef<userOrdersOutput | null>,
|
||||
loading: computed(() => state.value.status === 'loading'),
|
||||
error: computed(() => state.value.error),
|
||||
}
|
||||
}
|
||||
|
||||
export function useUpdateProfile() {
|
||||
const isPending = ref(false)
|
||||
const error = ref<Error | null>(null)
|
||||
async function mutate(args: Parameters<typeof callUpdateProfile>[0]) {
|
||||
isPending.value = true; error.value = null
|
||||
try { return await callUpdateProfile(args) }
|
||||
catch (e) { error.value = e as Error; throw e }
|
||||
finally { isPending.value = false }
|
||||
}
|
||||
return { mutate, isPending, error }
|
||||
}
|
||||
|
||||
export function useEcho() {
|
||||
const isPending = ref(false)
|
||||
const error = ref<Error | null>(null)
|
||||
async function mutate(args: Parameters<typeof callEcho>[0]) {
|
||||
isPending.value = true; error.value = null
|
||||
try { return await callEcho(args) }
|
||||
catch (e) { error.value = e as Error; throw e }
|
||||
finally { isPending.value = false }
|
||||
}
|
||||
return { mutate, isPending, error }
|
||||
}
|
||||
|
||||
export function useWhoami() {
|
||||
const isPending = ref(false)
|
||||
const error = ref<Error | null>(null)
|
||||
async function mutate() {
|
||||
isPending.value = true; error.value = null
|
||||
try { return await callWhoami() }
|
||||
catch (e) { error.value = e as Error; throw e }
|
||||
finally { isPending.value = false }
|
||||
}
|
||||
return { mutate, isPending, error }
|
||||
}
|
||||
|
||||
export function useFindUser() {
|
||||
const isPending = ref(false)
|
||||
const error = ref<Error | null>(null)
|
||||
async function mutate(args: Parameters<typeof callFindUser>[0]) {
|
||||
isPending.value = true; error.value = null
|
||||
try { return await callFindUser(args) }
|
||||
catch (e) { error.value = e as Error; throw e }
|
||||
finally { isPending.value = false }
|
||||
}
|
||||
return { mutate, isPending, error }
|
||||
}
|
||||
|
||||
export function useRenameUser() {
|
||||
const isPending = ref(false)
|
||||
const error = ref<Error | null>(null)
|
||||
async function mutate(args: Parameters<typeof callRenameUser>[0]) {
|
||||
isPending.value = true; error.value = null
|
||||
try { return await callRenameUser(args) }
|
||||
catch (e) { error.value = e as Error; throw e }
|
||||
finally { isPending.value = false }
|
||||
}
|
||||
return { mutate, isPending, error }
|
||||
}
|
||||
|
||||
export type { ContextState } from '@mizan/base'
|
||||
export { configure, initSession, MizanError } from '@mizan/base'
|
||||
Reference in New Issue
Block a user