|
| 1 | +# Connexions Codegen Template |
| 2 | + |
| 3 | +Generate a Go mock server from OpenAPI specs with [Connexions](https://github.com/mockzilla/connexions). |
| 4 | + |
| 5 | +Each service is a Go package with generated handlers, embedded OpenAPI specs, and optional custom logic. |
| 6 | +Includes an API Explorer UI at `/api-explorer`. |
| 7 | + |
| 8 | +## Quick start |
| 9 | + |
| 10 | +1. Click [**Use this template**](https://github.com/mockzilla/connexions-codegen-template/generate) to create your own repository |
| 11 | +2. Add services (see below) |
| 12 | +3. Regenerate and discover: |
| 13 | + ```bash |
| 14 | + make generate && make discover |
| 15 | + ``` |
| 16 | +4. Push to main - binaries for Linux, macOS, and Windows are built automatically and published to **Releases** |
| 17 | + |
| 18 | +## Adding services |
| 19 | + |
| 20 | +### From an OpenAPI spec |
| 21 | + |
| 22 | +```bash |
| 23 | +make service name=my-api |
| 24 | +``` |
| 25 | + |
| 26 | +This creates `pkg/my_api/` with a scaffold. Replace `pkg/my_api/setup/openapi.yml` with your spec, then run: |
| 27 | + |
| 28 | +```bash |
| 29 | +make generate && make discover |
| 30 | +``` |
| 31 | + |
| 32 | +### From static responses |
| 33 | + |
| 34 | +```bash |
| 35 | +make service-from-static name=my-api |
| 36 | +``` |
| 37 | + |
| 38 | +Add response files under `pkg/my_api/setup/data/` organized by method and path: |
| 39 | + |
| 40 | +``` |
| 41 | +pkg/my_api/setup/data/ |
| 42 | + get/ |
| 43 | + users/ |
| 44 | + index.json -> GET /users |
| 45 | + users/{id}/ |
| 46 | + index.json -> GET /users/{id} |
| 47 | + post/ |
| 48 | + users/ |
| 49 | + index.json -> POST /users |
| 50 | +``` |
| 51 | + |
| 52 | +Then regenerate: |
| 53 | + |
| 54 | +```bash |
| 55 | +make generate && make discover |
| 56 | +``` |
| 57 | + |
| 58 | +## Service structure |
| 59 | + |
| 60 | +Each service lives in `pkg/{service_name}/` with: |
| 61 | + |
| 62 | +``` |
| 63 | +pkg/petstore/ |
| 64 | + setup/ |
| 65 | + openapi.yml # OpenAPI specification |
| 66 | + config.yml # Latency, errors, upstream, caching |
| 67 | + codegen.yml # Code generation settings |
| 68 | + context.yml # Custom values for mock data |
| 69 | + generate.go # go:generate directive |
| 70 | + gen.go # Generated handler (do not edit) |
| 71 | + service.go # Custom logic (optional overrides) |
| 72 | +``` |
| 73 | + |
| 74 | +## API Explorer UI |
| 75 | + |
| 76 | +The built-in UI is available at `/` (configurable in `resources/data/app.yml`). |
| 77 | +It lets you browse services, view specs, test endpoints, and inspect request/response history. |
| 78 | + |
| 79 | +## Local development |
| 80 | + |
| 81 | +```bash |
| 82 | +make build |
| 83 | +.build/server/server |
| 84 | +``` |
| 85 | + |
| 86 | +See the [Connexions docs](https://github.com/mockzilla/connexions) for more options. |
0 commit comments