A Python script that automatically generates JSON schemas from Apple Developer documentation pages. This tool was developed to help create schemas for the micromdm/apple-device-services project.
The script uses Selenium WebDriver to fetch Apple Developer documentation pages (which require JavaScript rendering), parses the content using BeautifulSoup, and generates JSON Schema files based on a predefined template.
- Automatic Schema Generation: Extracts title, description, API version, and property definitions from Apple Developer documentation
- Type Detection: Automatically detects standard JSON Schema types vs. custom object references
- Required Field Detection: Identifies required properties from the documentation
- Custom Output Directory: Save generated schemas to any directory
- JSON Schema 2020-12 Compliant: Uses the latest JSON Schema specification
- Python 3.13+
- Firefox browser
- UV Python package manager
-
Install UV:
brew install uv
-
Create a virtual environment:
uv venv
-
Activate the virtual environment:
source .venv/bin/activate -
Install dependencies:
uv pip install -r pyproject.toml
uv run schemer.py <Apple Developer Doc URL> [output_directory (relative path)]Generate schema in current directory:
uv run schemer.py https://developer.apple.com/documentation/appleschoolmanagerapi/documentlinksGenerate schema in specific directory:
uv run schemer.py https://developer.apple.com/documentation/appleschoolmanagerapi/documentlinks ./asm/schemasIf you want to see more about UV, check here: https://docs.astral.sh/uv/
- Fetch Page: Uses Selenium Firefox WebDriver to load the Apple Developer documentation page with JavaScript rendered
- Parse Content: Extracts structured information using BeautifulSoup:
- Title from
.titleclass - Description from
.abstract.contentclass - API version from
.platformclass - Properties from
.row.paramsections
- Title from
- Generate Schema: Creates JSON Schema with:
- Standard types (
string,number,boolean, etc.) use"type"field - Custom objects use
"$ref"field pointing to{ObjectName}.json - Required fields detected from property requirement text
- Standard types (
- Save File: Outputs to specified directory with filename matching the documentation title
The script uses SchemaTemplate.json as a base template following JSON Schema 2020-12 specification:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "",
"description": "",
"x-apple-developer-api-uri": "",
"x-apple-developer-api-version": "",
"type": "",
"required": [ "" ],
"properties": {
"": {
"description": "",
"type": "",
"$ref": ""
}
}
}The script is designed to work with Apple Developer API documentation pages that follow the standard format, including:
- Apple School Manager API
- Apple Business Manager API
- Device Enrollment Program API
- And other Apple enterprise APIs
This tool was created to support the micromdm/apple-device-services project. Contributions and improvements are welcome!