一键导入
yaml
YAML & JSON Schema Conventions
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
YAML & JSON Schema Conventions
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | yaml |
| description | YAML & JSON Schema Conventions |
Generic skill — This skill is project-agnostic. Do not add project-specific references, paths, or terminology here.
Consult this when reading, writing, or modifying any YAML or JSON files in a project.
Never use raw yaml.safe_load() / yaml.dump() directly in application code. Instead:
BaseModel that matches the YAML structuremodel.model_validate(yaml.safe_load(path)) — gives type-safe attribute access and catches schema violations immediatelyyaml.dump(model.model_dump(exclude_none=True), ...) — produces clean YAML without None clutterWrap these in load_* / save_* helper functions so callers never touch raw dicts.
When saving YAML, prepend a schema tag so VS Code (with the YAML extension) provides autocompletion and validation:
# yaml-language-server: $schema=../../schemas/my_format.json
Use a relative path from the YAML file to the JSON Schema file. Save helpers should add this automatically.
Another approach is to publish schemas as GitHub Release artifacts and reference via absolute URL. (TODO: add details for ibek projects)
Generate JSON Schema files from Pydantic models using model.model_json_schema():
import json
schema = MyModel.model_json_schema()
Path("schemas/my_format.json").write_text(json.dumps(schema, indent=2) + "\n")
Commit generated schemas to the repo so VS Code picks them up without running code. Add a test that compares committed schemas against model_json_schema() output to catch staleness.
Literal["a", "b"] for enum-like string fields — catches typos at validation timemodel_config = ConfigDict(extra="allow") only for formats with user-defined fields; keep all others strictexclude_none=True when dumping so optional fields don't clutter YAML with null entriesbool | None flags, use None as the default (not False) so absent flags are omitted from output@dataclass for structures that are serialized to/from YAMLload_* / save_* helpers (with schema tag injection)model_json_schema()