# schema **Repository Path**: zhou_bing94/schema ## Basic Information - **Project Name**: schema - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-12 - **Last Updated**: 2026-11-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # schema —— 代码生成框架(schemacore,可复用子模块) 零业务符号的 Schema 驱动代码生成框架。其他项目把它作为 git submodule 引入, 只填自己的「配置 + 输入数据」,即可复用同一套生成机制,无需复制生成器代码。 ## 目录结构 ``` schema/ ← 本仓库根(作为子模块挂到消费方约定相对路径) ├── schemacore/ ← 框架层(零业务符号,唯一需要复用部分) │ ├── base_generator.py 基础生成器:宏名派生 / 标签过滤 / 幂等写出 │ ├── config_loader.py 读取 [[outputs]] TOML + YAML 条目,无继承 │ ├── cli.py 入口编排:逐 output 异常隔离、--check/--toml/--strict │ ├── java_formatter.py Java 错误码格式化及旧参数 formatter 兼容入口 │ ├── targets/ 参数语言输出:c/params.py、java/params.py、arkts/params.py │ ├── kinds/params_kind.py 参数统一过滤与语言派发 │ ├── kinds/param_register_kind.py 参数注册体生成 │ └── tests/ 框架单测(用临时 output_root,不触碰消费方产物) ├── template/consumer/ ← 消费端权威骨架 + 设计规范(新增模块直接复制它) ├── conftest.py pytest 会话级:把本仓库根加入 sys.path ├── requirements.txt PyYAML └── .gitignore ``` 业务相关的一切(`input/` 数据、`schema_core.toml`、自定义 kinds 包、生成入口) **留在消费方自己的仓库**,本仓库不包含任何 `comm.` / `foundation::` / `COMM_` 字样。 ## 依赖 - Python 3.11+(`tomllib` 内置);低于 3.11 需 `pip install tomli` - `PyYAML>=6.0` ## 消费方如何接入(B方案:纯配置驱动) 1. 在消费模块里把本仓作为 submodule 挂在约定相对路径,使之与模块同级: ``` your_project/ ├── foundation/ 你的其它模块 ├── communication/ ├── csdk/ └── schema/ ← git submodule add git@gitee.com:zhou_bing94/schema.git schema ``` 2. **复制消费端骨架**:`cp -r template/consumer <你的模块>/schema`,删掉 `input/example.*`, 按 `template/consumer/input/README.md` 写你自己的 `.toml` + 同目录 `.yaml`, 按需编辑 `schema_core.toml`(`output_root` / `scan_root` / `[core].cpp.*`)。 详见 `template/consumer/README.md`。 3. **生成入口** `schema/generate.bat` 已把「顶层框架目录 `..\..\schema`」与「本地 schema 目录」 加入 `PYTHONPATH`,再跑 `python -m schemacore.cli --root .`: ```bat schema\generate.bat # 生成(写盘) python -m schemacore.cli --root . --check # 只读幂等校验,[CHECK-OK] 即通过 ``` 4. **自定义 kinds**(可选):在消费端 `schema/_kinds/` 写渲染器包,于 `schema_core.toml` 登记 `kinds_modules = ["_kinds"]`。框架 `import` 它并并入派发表, 消费端零生成逻辑。详见 `template/consumer/kinds/README.md`。 ## 运行框架自测 参数输出 `kind="params"` 默认 `target="c"`,也支持 `java`、`arkts`;未知 target 报错。三种语言共享 YAML、命名、枚举和标签过滤,各输出模块仅负责格式。修改语言格式时改 `targets/<语言>/params.py`,不要复制加载和校验机制。ArkTS 输出导出的静态常量类,类名取输出文件名;`macro_prefix` / `value_prefix` / `key_prefix` / `tags` 与既有参数输出共用。错误码等其他 kind 的语言支持保持原状。 在本仓库根目录执行: ```bash pytest # 跑 schemacore/tests,全部用临时 output_root,不触碰消费方产物 ``` ## 版本管理 当前版本:`1.4.0`,唯一事实源是本仓库根目录的 `VERSION.txt`。`schema_api` 是消费方兼容契约,不等同于产品版本;Git tag 只用于发布审计。