Skip to content

Commit 27ea6a4

Browse files
committed
Server to/fro implementation with composable models, routes, mocks/fakes
1 parent c98ab32 commit 27ea6a4

30 files changed

Lines changed: 2005 additions & 121 deletions

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
build:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v6
17+
- uses: actions/checkout@v7
1818
- name: Set up Python
1919
uses: actions/setup-python@v6
2020
with:
2121
python-version: '3.11'
2222
- name: Checkout Test Harness
23-
uses: actions/checkout@v6
23+
uses: actions/checkout@v7
2424
with:
2525
repository: SamuelMarks/cdd-openapi-test-harness
2626
path: cdd-openapi-test-harness
@@ -60,7 +60,7 @@ jobs:
6060
if: startsWith(github.ref, 'refs/tags/v')
6161
runs-on: ubuntu-latest
6262
steps:
63-
- uses: actions/checkout@v6
63+
- uses: actions/checkout@v7
6464
- uses: actions/download-artifact@v8
6565
with:
6666
name: python-build

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,4 @@ update_tests.py
185185
update_tests2.py
186186
update_tests3.py
187187
update_tests4.py
188+
.tmp_*

‎.pre-commit-config.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ repos:
3838
language: system
3939
pass_filenames: false
4040
always_run: true
41+
- id: swagger-2-0-generated-server-test
42+
name: Swagger 2.0 Generated Server Test
43+
entry: uv run python scripts/run_generated_server_test.py petstore.json .tmp_gen_swagger
44+
language: system
45+
pass_filenames: false
46+
always_run: true
47+
- id: openapi-3-2-0-generated-server-test
48+
name: OpenAPI 3.2.0 Generated Server Test
49+
entry: uv run python scripts/run_generated_server_test.py petstore_oas3.json .tmp_gen_oas3
50+
language: system
51+
pass_filenames: false
52+
always_run: true
4153
- id: build-wasm
4254
name: Build WASM
4355
entry: uv run python scripts/build_wasm.py

‎README.md‎

Lines changed: 144 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,174 @@
11
cdd-python-all
2-
==============
2+
============
3+
34
[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)
45
[![interactive WASM web demo](https://img.shields.io/badge/interactive-WASM_web_demo-blue.svg)](https://offscale.io/wasm_web_demo)
56
[![CI](https://github.com/offscale/cdd-python-all/actions/workflows/ci.yml/badge.svg)](https://github.com/offscale/cdd-python-all/actions)
6-
[![Test Coverage](https://img.shields.io/badge/test_coverage-99%25-brightgreen.svg)](#)
7+
[![Test Coverage](https://img.shields.io/badge/test_coverage-100%25-brightgreen.svg)](#)
78
[![Doc Coverage](https://img.shields.io/badge/doc_coverage-100%25-brightgreen.svg)](#)
89

9-
----
10+
**Compiler Driven Development (CDD)** is a development approach designed to eradicate the disconnect between: API specifications; server implementations; client SDKs; and command-line tooling.
1011

11-
OpenAPI ↔ Python. This is one compiler in a suite, all focussed on the same task: Compiler Driven Development (CDD).
12+
Unlike traditional code generators—that treat outputs as disposable or read-only—CDD provides a **complete, standalone compiler** for each supported language. These compilers are fully CST-aware (Concreate Syntax Tree is a whitespace+comment aware Abstract Syntax Tree), allowing true bidirectional synchronization between existing hand-edited source code and OpenAPI specifications.
1213

13-
Each compiler is written in its target language, is whitespace and comment sensitive, and has both an SDK and CLI.
14+
---
1415

15-
The core philosophy of Compiler Driven Development (CDD) is synchronization without compromise. Where traditional generators silo your API boundaries into read-only files, this compiler natively merges changes into your codebase via a robust, [whitespace and comment aware] Abstract Syntax Tree (AST) driven parser & emitter. It bridges the gap between design and implementation, allowing you to seamlessly generate SDKs from a spec or extract a spec from existing code. By keeping your APIs, SDKs, and tests in continuous, automated alignment, it drastically improves both delivery speed and software reliability.
16+
## 🏗️ The Standalone Compiler Architecture
1617

17-
The CLI—at a minimum—has:
18+
Traditional tools use naïve templating—if you regenerate, your custom code is overwritten.
1819

19-
- `cdd-python-all --help`
20-
- `cdd-python-all --version`
21-
- `cdd-python-all from_openapi to_sdk_cli --mcp -i spec.json`
22-
- `cdd-python-all from_openapi to_sdk -i spec.json`
23-
- `cdd-python-all from_openapi to_server -i spec.json`
24-
- `cdd-python-all to_openapi -f path/to/code`
25-
- `cdd-python-all to_docs_json --no-imports --no-wrapping -i spec.json`
26-
- `cdd-python-all serve_json_rpc --port 8080 --listen 0.0.0.0`
20+
The CDD ecosystem is fundamentally different. It utilizes language-specific, standalone compilers capable of full AST parsing, semantic diffing, and surgical patching.
2721

28-
## SDK Example
22+
**The Core Guarantee:** Every part of the generated codebase is fully editable.
23+
You are encouraged to open the generated routing files, model definitions, and CLI structures, and directly inject your business logic.
2924

30-
```py
31-
from cdd import generate_sdk, Config
25+
- **When your specification changes**, the CDD compiler reads your code, builds an AST, diffs it against the new spec, and safely patches in new endpoints or fields without touching your custom logic.
26+
- **When your codebase changes**, the compiler reverse-engineers your structural updates back into a 100% accurate, authoritative OpenAPI specification.
3227

33-
if __name__ == '__main__':
34-
config = Config(input_path='spec.json', output_dir='src/models')
35-
generate_sdk(config)
36-
print("SDK generation complete.")
37-
```
28+
---
3829

39-
## Installation
30+
## 🔄 The Bidirectional Synchronization Loop
4031

41-
```bash
42-
python3 -m pip install -e .
43-
```
32+
```mermaid
33+
flowchart TD
34+
OAS["📄 OpenAPI v3 Spec"] <--> CDD{"⚙️ CDD Compiler"}
4435
45-
## Development
46-
47-
You can use standard tooling commands or the included cross-platform Makefiles to fetch dependencies, build, and test:
48-
49-
```bash
50-
python3 -m pip install -e .
51-
python3 -m pytest
52-
# or
53-
make deps
54-
make build
55-
make test
56-
# or on Windows
57-
.\make.bat deps
58-
.\make.bat build
59-
.\make.bat test
60-
```
36+
CDD <--> Codebase
6137
62-
See [PUBLISH.md](PUBLISH.md) for packaging and releasing.
38+
subgraph Codebase ["💻 Application Codebase"]
39+
direction TB
6340
64-
## Features
41+
subgraph Outputs ["📦 Primary Outputs"]
42+
direction TB
43+
CLI["⌨️ CLI Tooling"]
44+
SDK["📦 Client SDK"]
45+
Server["🖥️ Server"]
6546
66-
The `cdd-python-all` compiler leverages a unified architecture to support various facets of API and code lifecycle management. For a deep dive into the compiler's design, see [ARCHITECTURE.md](ARCHITECTURE.md).
47+
%% Force vertical stacking inside the subgraph
48+
CLI ~~~ SDK ~~~ Server
49+
end
6750
68-
- **Compilation**:
69-
- **OpenAPI → `Python`**: Generate idiomatic native models, network routes, client SDKs, and boilerplate directly from OpenAPI (`.json` / `.yaml`) specifications.
70-
- **`Python` → OpenAPI**: Statically parse existing `Python` source code and emit compliant OpenAPI specifications.
71-
- **Model Context Protocol (MCP)**: Generate and run MCP clients and servers, exposing your APIs seamlessly to AI models.
72-
- **AST-Driven & Safe**: Employs static analysis instead of unsafe dynamic execution or reflection, allowing it to safely parse and emit code even for incomplete or un-compilable project states.
73-
- **Seamless Sync**: Keep your docs, tests, database, clients, and routing in perfect harmony. Update your code, and generate the docs; or update the docs, and generate the code.
51+
subgraph Core ["🔗 Core Architecture"]
52+
direction TB
53+
Models["🔗 Data Models"]
54+
Routes["🔀 API Routes"]
55+
Tests["🧪 Tests"]
7456
75-
**Uncommon Features:**
57+
%% Force vertical stacking inside the subgraph
58+
Models ~~~ Routes ~~~ Tests
59+
end
7660
77-
`cdd-python-all` supports standard CDD features.
61+
Mocks["🎭 API Mocks / Fakes"]
7862
79-
## CLI Options
63+
%% Simple dependency flow down the page
64+
Outputs --> Core
65+
Tests --> Mocks
66+
end
8067
81-
```text
82-
Usage: cdd-python-all [OPTIONS] <COMMAND>
68+
style OAS fill:#e3f2fd,stroke:#1e88e5,stroke-width:2px
69+
style CDD fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px
70+
style Codebase fill:#fafafa,stroke:#9e9e9e,stroke-width:2px,stroke-dasharray: 5 5
71+
style Outputs fill:#e8f5e9,stroke:#43a047,stroke-width:2px
72+
style Core fill:#fff3e0,stroke:#f57c00,stroke-width:2px
8373
```
8474

75+
The CDD lifecycle supports continuous evolution from any starting point:
76+
1. **Generate**: Scaffold servers, SDKs, or CLIs from a central specification.
77+
2. **Edit**: Developers write real, unconstrained code directly in the generated files.
78+
3. **Extract**: Reverse-compile the edited code to produce an updated OpenAPI spec.
79+
4. **Sync**: Apply new specification changes seamlessly into the existing, hand-edited codebase.
80+
81+
---
82+
83+
## 🌐 The Global Language Ecosystem
84+
85+
Every supported language operates on the same core CDD philosophies but is powered by a dedicated, native compiler tailored to that language's specific AST, idioms, and package management.
86+
87+
All implementations share a standardized CLI interface (`cdd [subcommand]`), acting as a universal toolchain.
88+
89+
| Repository | Language | Client; Client CLI; Server | Extra features | Standards | CI Status |
90+
|---|---|---|---|---|---|
91+
| [`cdd-c`](https://github.com/SamuelMarks/cdd-c) | C (C89) | Client; Client CLI; Server | FFI | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-c/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-c/actions/workflows/ci.yml) |
92+
| [`cdd-cpp`](https://github.com/SamuelMarks/cdd-cpp) | C++ | Client; Client CLI; Server | Upgrades Swagger & Google Discovery to OpenAPI 3.2.0 | Google Discovery; Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-cpp/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-cpp/actions/workflows/ci.yml) |
93+
| [`cdd-csharp`](https://github.com/SamuelMarks/cdd-csharp) | C# | Client; Client CLI; Server | CLR | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-csharp/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-csharp/actions/workflows/ci.yml) |
94+
| [`cdd-go`](https://github.com/SamuelMarks/cdd-go) | Go | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-go/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-go/actions/workflows/ci.yml) |
95+
| [`cdd-java`](https://github.com/SamuelMarks/cdd-java) | Java | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-java/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-java/actions/workflows/ci.yml) |
96+
| [`cdd-kotlin`](https://github.com/offscale/cdd-kotlin) | Kotlin (ktor for Multiplatform) | Client; Client CLI; Server | Auto-Admin UI | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/offscale/cdd-kotlin/actions/workflows/ci.yml/badge.svg)](https://github.com/offscale/cdd-kotlin/actions/workflows/ci.yml) |
97+
| [`cdd-php`](https://github.com/SamuelMarks/cdd-php) | PHP | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-php/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-php/actions/workflows/ci.yml) |
98+
| [`cdd-python`](https://github.com/offscale/cdd-python) | Python | N/A (server building blocks) | CLI ↔ SQL ↔ Pydantic ↔ docs ↔ JSON-schema | N/A | [![Linting, testing, coverage, and release](https://github.com/offscale/cdd-python/workflows/Linting,%20testing,%20coverage,%20and%20release/badge.svg)](https://github.com/offscale/cdd-python/actions) |
99+
| [`cdd-python-all`](https://github.com/offscale/cdd-python-all) | Python | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/offscale/cdd-python-client/actions/workflows/ci.yml/badge.svg)](https://github.com/offscale/cdd-python-all/actions/workflows/ci.yml) |
100+
| [`cdd-ruby`](https://github.com/SamuelMarks/cdd-ruby) | Ruby | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-ruby/actions/workflows/ci.yml) |
101+
| [`cdd-rust`](https://github.com/SamuelMarks/cdd-rust) | Rust | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/offscale/cdd-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/offscale/cdd-rust/actions/workflows/ci.yml) |
102+
| [`cdd-sh`](https://github.com/SamuelMarks/cdd-sh) | Shell (/bin/sh) | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-sh/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-sh/actions/workflows/ci.yml) |
103+
| [`cdd-swift`](https://github.com/SamuelMarks/cdd-swift) | Swift | Client; Client CLI; Server | | Swagger 2.0 & OpenAPI 3.2.0 | [![CI](https://github.com/SamuelMarks/cdd-swift/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-swift/actions/workflows/ci.yml) |
104+
| [`cdd-ts`](https://github.com/offscale/cdd-ts) | TypeScript | Client; Client CLI; Server | Auto-Admin UI; Angular; React; Vue; fetch; Axios; Node.js | Swagger 2.0 & OpenAPI 3.2.0 | [![Tests and coverage](https://github.com/offscale/cdd-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/offscale/cdd-ts/actions/workflows/ci.yml) |
105+
106+
---
107+
108+
## 🛠️ Universal CLI Toolchain
109+
110+
A true ecosystem requires standardized tooling. Once a developer learns the CDD toolchain, they can synchronize architecture across the entire polyglot stack.
111+
112+
### Global Arguments
113+
114+
- `--help`: Print help information.
115+
- `--version`: Print version information.
116+
- `--input, -i` (or `-f`): Target file, directory, or OpenAPI spec.
117+
- `--output, -o`: Destination path for generation or sync.
118+
119+
### Core Subcommands
120+
121+
#### `from_openapi to_sdk_cli`
122+
Generate a client SDK and a corresponding command-line interface (CLI) from an OpenAPI specification.
123+
- `--input, -i <spec>`: Path to the OpenAPI specification file.
124+
125+
#### `from_openapi to_sdk`
126+
Generate a client SDK from an OpenAPI specification.
127+
- `--input, -i <spec>`: Path to the OpenAPI specification file.
128+
129+
#### `from_openapi to_server`
130+
Generate server boilerplate, models, and routing logic from an OpenAPI specification.
131+
- `--input, -i <spec>`: Path to the OpenAPI specification file.
132+
133+
#### `to_openapi`
134+
Parse the existing codebase and extract an authoritative OpenAPI specification.
135+
- `--input, -i <path>` (or `-f <path>`): Path to the source code directory or file to parse.
136+
137+
#### `to_docs_json`
138+
Convert an OpenAPI specification into a localized, documentation-optimized JSON format.
139+
- `--input, -i <spec>`: Path to the OpenAPI specification file.
140+
- `--no-imports`: Disable import statements in the generated documentation.
141+
- `--no-wrapping`: Disable line wrapping in the generated documentation.
142+
143+
#### `serve_json_rpc`
144+
Launch a JSON-RPC server for editor and tool integrations.
145+
- `--port <port>` (or `-p`): Port to listen on (e.g., `8080`).
146+
- `--listen <address>` (or `-l`): Address to bind to (e.g., `0.0.0.0`).
147+
148+
#### `mcp`
149+
Run the Model Context Protocol server via stdio.
150+
151+
#### `sync`
152+
Sync a directory containing client.py, mock_server.py, test_client.py, cli_main.py
153+
- `--dir <dir>`: Path to directory containing Python files to sync.
154+
- `--truth {class,sqlalchemy,function,openapi}`: Designate a single source of truth for synchronization.
155+
156+
### Detail Features Beyond Common Subset
157+
158+
- **Model Context Protocol (MCP)**: Native support to generate an MCP server and adapter (`--mcp`), and run the MCP server over stdio.
159+
- **Directory Synchronization**: Uniquely features a `sync` command to harmonize `client.py`, `mock_server.py`, `test_client.py`, and `cli_main.py` with configurable sources of truth (`class`, `sqlalchemy`, `function`, `openapi`).
160+
- **Comprehensive Scaffolding**: Optionally generates GitHub Actions pipelines and installable Python package scaffolding automatically.
161+
- **Integration Testing & Mocks**: Emits full integration tests and mock servers during generation (`--tests`).
162+
- **Batch Processing**: Capable of reading from an entire directory of OpenAPI specifications (`--input-dir`) simultaneously.
163+
164+
---
165+
166+
## 🚀 The End of "Spec Drift"
167+
168+
With Compiler Driven Development, specifications and code are no longer loosely coupled artifacts. They are strict, isomorphic reflections of one another, maintained by dedicated standalone compilers.
169+
170+
Choose your language ecosystem above and start treating your architecture as a seamlessly compiled, endlessly editable whole.
171+
85172
---
86173

87174
## License

0 commit comments

Comments
 (0)