跳转到主要内容

将JSON Schema转换为可读的Markdown文档

项目描述

jsonschema2md

将JSON Schemas转换为简单、可读的Markdown文档。


例如

{
  "$id": "https://example.com/person.schema.json",
  "$schema": "https://json-schema.fullstack.org.cn/draft-07/schema#",
  "title": "Person",
  "description": "JSON Schema for a person object.",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    }
  }
}

将被转换为

Person

人的对象的JSON Schema。

属性

  • firstName (字符串):人的名字。
  • lastName (字符串):人的姓氏。

有关更详细的示例,请参阅示例目录


安装

使用pip安装

pip install jsonschema2md

用法

从命令行界面

jsonschema2md [OPTIONS] <input.json> <output.md>

从Python

import json
import jsonschema2md

parser = jsonschema2md.Parser(
    examples_as_yaml=False,
    show_examples="all",
)
with open("./examples/food.json", "r") as json_file:
    md_lines = parser.parse_schema(json.load(json_file))
print(''.join(md_lines))

选项

  • examples-as-yaml:解析YAML格式的示例,而不是JSON。(布尔值,默认:False
  • show-examples:仅解析主对象、仅属性或所有属性。(字符串,默认 all,选项:objectpropertiesall

pre-commit钩子

您可以使用以下方法使用pre-commit钩子:

repos:
  - repo: https://github.com/sbrunner/jsonschema2md
    rev: <version> # Use the ref you want to point at
    hooks:
      - id: jsonschema2md
        files: schema.json
        args:
          - --pre-commit
          - schema.json
          - schema.md

贡献

有错误、问题或建议?请随意在问题跟踪器中发布问题或创建pull request!有关更多信息,请参阅CONTRIBUTING.md

安装pre-commit钩子

pip install pre-commit
pre-commit install --allow-missing-config

变更日志

请参阅CHANGELOG.md

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

jsonschema2md2-1.3.0.tar.gz (9.8 kB 查看哈希值)

上传时间

构建分布

jsonschema2md2-1.3.0-py3-none-any.whl (10.3 kB 查看哈希值)

上传时间 Python 3

支持