Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article describes how to generate specifications for Solidity smart contracts using Claude Code.
The workflow produces both contract specifications and readable documentation, then builds a website where developers can browse the generated material.
The following article defines the specification format used for Solidity contracts.
The end result is a documentation site like this:
Contract Documentation Generator
Writing smart contract specifications manually takes considerable time. The work involves parsing ABIs, listing functions and events, describing each element, mapping Solidity types to OpenAPI schemas, and extracting NatSpec comments. Repeating this process for dozens of contracts is difficult to scale.
I built the Contract Documentation Generator to automate this workflow with Claude Code. It consists of three independent Claude Code skills that cover specification generation, documentation, and website construction.
Why introduce an intermediate representation (Contract Spec JSON)?
The initial design generated OpenAPI specifications directly from ABIs. However, ABIs do not contain the human-readable information needed to explain function behavior, parameter semantics, or the conditions under which errors occur. OpenAPI documents, on the other hand, benefit from detailed descriptions, example values, and error response definitions.
Bridging that gap requires several operations, including AI-assisted description generation, NatSpec extraction, and error analysis.
Combining everything in one step makes it difficult to isolate the source of a problem. Introducing Contract Spec JSON as an intermediate representation allows each stage to save its output as a file, making problems easier to diagnose.
Contract Spec JSON provides three benefits.
- Incremental quality improvements Each stage can be validated separately: raw ABI → structured JSON → AI enrichment → OpenAPI.
- Reuse Both OpenAPI specifications and Markdown documentation can be generated from the same Contract Spec JSON.
- Easier debugging Intermediate files make it easier to identify the stage where a problem occurred.
Separating responsibilities across three skills
The Contract Documentation Generator consists of three distinct skills.
flowchart TB
subgraph Input["入力"]
ABI[ABI ファイル]
SOL[Solidity ソース]
end
subgraph Skill1["contract-spec-generator"]
P1[Phase 1: 分析・選択]
P2[Phase 2: Contract Spec JSON生成]
P3[Phase 3: AI強化]
P4[Phase 4: 品質検証]
P5[Phase 5: OpenAPI生成]
P1 --> P2 --> P3 --> P4 --> P5
end
subgraph Skill2["contract-doc-generator"]
D1[テンプレート適用]
D2[概要ページ生成]
D3[サイドバー生成]
D1 --> D2 --> D3
end
subgraph Skill3["contract-site-builder"]
S1[Docusaurus初期化]
S2[swagger-ui-react統合]
S3[ダークモード対応]
S1 --> S2 --> S3
end
Input --> Skill1
Skill1 -->|OpenAPI YAML<br>Contract Spec JSON| Skill2
Skill2 -->|Markdown<br>sidebars.js| Skill3
Skill3 --> Site[Docusaurusサイト]
| Skill | Responsibility | Input | Output |
|---|---|---|---|
| contract-spec-generator | Specification generation | ABI + Solidity source | OpenAPI YAML + Contract Spec JSON |
| contract-doc-generator | Documentation generation | OpenAPI + Contract Spec JSON | Markdown + sidebars.js |
| contract-site-builder | Website construction | Markdown + OpenAPI | Docusaurus site |
Each skill concentrates on a single responsibility. If a stage fails, only the corresponding skill needs to be rerun.
Specification generation (contract-spec-generator)
The contract-spec-generator produces OpenAPI specifications through five main phases, preceded by language configuration.
Phase 0: Language configuration
Choose the language for the generated documentation.
- Supported languages: English (en), Japanese (ja), Korean (ko), and Simplified Chinese (zh-CN).
- The configuration is saved in
language.jsonfor use by subsequent phases.
Phase 1: Contract analysis and selection
Scan the ABI directory to identify the target contracts.
- Automatically exclude test contracts, abstract contracts, and interfaces.
- If specifications already exist, detect changes and update only the affected contracts.
Phase 2: Contract Spec JSON generation
Analyze the ABIs and Solidity source code to generate the intermediate representation.
- Extracted information Inheritance relationships, struct definitions, modifier definitions, state variables, and function signatures.
- Type mapping
address→pattern: "^0x[0-9a-fA-F]{40}$", anduint256→type: string.
Phase 3: AI enrichment
AI agents enrich the Contract Spec JSON.
- NatSpec extraction
enhance-spec-from-source.pyextracts comments from Solidity source code. - Error analysis
analyze-errors.pyfollows function call chains to identify errors. - spec-reviewer agent Improves descriptions, adds modifier information, and replaces generic descriptions with contract-specific explanations.
- language-translator agent Translates the content if a language other than English has been selected.
Phase 4: Quality validation
validate-spec.py checks the quality of the Contract Spec JSON.
- Presence of required fields.
- Description quality, including minimum length and whitespace checks.
- Accuracy of type mappings.
- Consistency of error response definitions.
Phase 5: OpenAPI generation
Generate OpenAPI 3.0 YAML specifications from the validated Contract Spec JSON.
- Output files
{ContractName}.openapi.yaml- OpenAPI specificationdoc-config.json- Configuration for website construction
Documentation generation (contract-doc-generator)
The contract-doc-generator converts machine-readable specifications into documentation intended for human readers.
Individual contract documentation
Generate a Markdown document for each contract.
- An overview in two or three paragraphs.
- Inheritance relationships.
- Explanations of major features, accompanied by Mermaid sequence diagrams.
- Security considerations.
- Lists of contract elements, including constants, variables, mappings, read functions, write functions, events, errors, structs, and modifiers.
System overview (seven required pages)
Generate seven pages describing the system as a whole.
| Page | Content |
|---|---|
| overview.md | Overall purpose and components |
| architecture.md | Mermaid diagrams showing relationships between components |
| roles.md | Access control roles and their permissions |
| security.md | Security considerations and mitigations |
| testing.md | Testing strategy and coverage |
| upgrade.md | Upgrade mechanisms, such as the UUPS pattern |
| audit.md | Security audit history and remediation |
The docs-reviewer and overview-reviewer agents review and improve these pages. Generated audit or testing descriptions should be checked against actual audit records and test results rather than treated as evidence by themselves.
Website construction (contract-site-builder)
The contract-site-builder packages the generated documentation into a website.
Technology stack
- Docusaurus 3.9.2 Static site generator.
- swagger-ui-react Interactive presentation of API specifications.
I initially considered Redocusaurus, but switched to swagger-ui-react because of React 19 compatibility issues. This made it possible to support both dark and light themes.
Development versus production builds
| Mode | File management | Purpose |
|---|---|---|
| Development | Symbolic links | Changes to source files appear immediately |
| Production build | File copies | Works in hosting environments such as Vercel |
During a production build, npm run sync runs automatically before npm run build, replacing symbolic links with actual files.
Technology choices
Several technical decisions shaped the Contract Documentation Generator.
Moving to Python
The scripts were originally written in JavaScript, but I migrated them all to Python. In the Claude Code workflow, Python provides readable code for complex file and JSON operations. Its standard library also covers tasks such as ABI parsing and source file processing.
Standardizing on OpenAPI 3.0 YAML
I standardized the output on OpenAPI 3.0 YAML. Early versions generated Swagger 2.0 JSON as well, but the additional format increased maintenance costs without being used.
Maintaining React 18 compatibility
The project uses Docusaurus 3.9.2 and maintains compatibility with React 18. The selected version of swagger-ui-react also works with React 18.
How to use it
Run the three commands in order.
Step 1: Generate specifications
ABIは artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json、コントラクトは node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol にあります。contract-spec-generator skillを使用して仕様書を作成してください。Once the five-phase pipeline completes, it generates the following outputs:
docs/contract/specs/- OpenAPI YAML specificationsdocs/contract/ir/- Contract Spec JSON filesdocs/contract/doc-config.json- Website configuration
Step 2: Generate documentation
contract-doc-generator skillを使用して、仕様書からドキュメントを作成してください。This generates the individual contract documents, seven overview pages, and sidebars.js.
Step 3: Build the website
contract-site-builder skillを使用して、Docusaurusサイトを構築してください。The skill initializes a Docusaurus project, integrates swagger-ui-react, and applies custom CSS. You can preview the site at http://localhost:3000.
Additional features
- Progress tracking
progress.jsonandprogress-docs.jsontrack progress, allowing interrupted work to resume. - Multilingual generation Supports English, Japanese, Korean, and Chinese.
- Change detection Compares existing specifications with source code and updates only the contracts that have changed.
ABI output locations vary by build tool. Build your contracts and generate their ABIs before running the generator.
forge buildGenerated website structure
The documentation website is structured as follows.
It includes system overview pages.
Individual contract documentation pages explain major features.
Each contract also has a detailed specification page.
Page structure
| Page | Path | Content |
|---|---|---|
| Home | / |
Contract cards grouped by category |
| Overview | /overview |
System description and contract list |
| Documentation | /docs/contracts/* |
Detailed Markdown documentation for each contract |
| Specification | /api/* |
OpenAPI specifications rendered using Swagger UI |
Header navigation
| Position | Element | Destination |
|---|---|---|
| Far left | Logo + project name | / |
| Second | Docs | /overview (system overview) |
| Third onward | Category dropdowns | /api/{ContractName} (specifications) |
| Far right | GitHub | Repository URL |
Home page
The home page displays contract cards grouped by category. Each card has a button for opening the corresponding detailed specification.
The hero section contains only the title and subtitle, without buttons. Category headings are centered.
API specification pages
API specification pages use swagger-ui-react to display interactive specifications. The sidebar groups functions, events, errors, and structs, allowing readers to navigate directly to the relevant section.
Using swagger-ui-react provides the following benefits:
- Support for dark and light themes.
- React 18 compatibility.
- Flexible custom styling.
- Straightforward integration with Mermaid diagrams.
Documentation pages
The documentation pages are written in Markdown and contain the following sections.
Structure
-
Title and API specification link
markdown# ContractName > **[📋 API仕様書を見る](/api/ContractName)**ContractName
📋 API仕様書を見る
-
Overview
- Contract description.
- Inheritance relationships (a list of inherited contracts).
-
Major features
- Explanations of the primary features provided by the contract.
-
Contract elements
Each category appears as a collapsible table using the
<details>tag. Detailed definitions belong in the API specification, so these tables contain only names and concise descriptions.Category Left column Content Constants Constant name Name and brief description Variables Variable name Name and brief description Mappings Mapping name Name and brief description Read functions Function name Name and brief description of a view or pure function Write functions Function name Name and brief description of a state-changing function Events Event name Name and brief description Errors Error name Name and brief description Detailed parameters and return values are kept in the API specification rather than duplicated here. This avoids maintaining the same definitions in two places and helps keep the documentation consistent.
Each documentation page begins with a link to its corresponding API specification.
Overview pages
The overview pages explain the system as a whole and list all its contracts. Each contract has links to both its documentation and its specification.
Conclusion
This article has described a workflow for generating OpenAPI/Swagger-style specifications for Solidity smart contracts.
The specifications represent contract interfaces for documentation purposes; they do not by themselves turn EVM calls into HTTP endpoints. The versions and workflow described here reflect the original December 2025 implementation.






