{"id":"6a39ba3a86dfe812bb05736c","title":"Generating A Typed Client","path":"how-to/technical-articles/2026-06-21-python-reference-server/generating-a-typed-client","contentMarkdown":"# 21-Jun-2026 — Generating a Typed Client from the OpenAPI Document\n\n_____\n\nThis is a companion to [A Python Reference Server](https://ngx-ramblers.org.uk/how-to/technical-articles/2026-06-21-python-reference-server). It answers one narrow question: if you decide to build your own implementation of the Salesforce member API, outside the reference servers we provide, how do you turn the published contract into a typed client in your language?\n\n> **You only need this if you are building your own client or server.** If you adopt the reference server we provide, the typed client and server are already built for you and there is nothing to generate here.\n\n## Where the document is\n\nThe contract package [`@ramblers/sf-contract`](https://github.com/nbarrett/ramblers-salesforce-contract) publishes a committed, static OpenAPI document, attached to each [release tag](https://github.com/nbarrett/ramblers-salesforce-contract/tags):\n\n- [`openapi/openapi.yaml`](https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/openapi/openapi.yaml)\n- [`openapi/openapi.json`](https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/openapi/openapi.json)\n\nEither file is enough. Everything below takes one of them as input. You do not need Node, npm or any TypeScript to use them - they are plain text describing the wire format.\n\n## OpenAPI Generator (any language)\n\nThe recommended general-purpose tool is **[OpenAPI Generator](https://openapi-generator.tech)**. It reads the document and emits a typed client for 50+ targets - Python, Java, C#, Go, Rust, PHP, Kotlin, Swift and more. The easiest way to run it, with nothing to install but Docker, is:\n\n```bash\ndocker run --rm -v \"$PWD:/local\" openapitools/openapi-generator-cli generate \\\n  -i /local/openapi.yaml \\\n  -g python \\\n  -o /local/sf-client-python\n```\n\nSwap `-g python` for `-g java`, `-g csharp`, `-g go` and so on to target a different language. The full [list of generators](https://openapi-generator.tech/docs/generators) is on their site.\n\n## openapi-python-client (recommended for Python)\n\nIf your target is Python, **[openapi-python-client](https://github.com/openapi-generators/openapi-python-client)** produces a cleaner, fully type-annotated client (built on [`httpx`](https://www.python-httpx.org) and [`attrs`](https://www.attrs.org)) that reads more naturally than OpenAPI Generator's Python output:\n\n```bash\npipx run openapi-python-client generate --path openapi.yaml\n```\n\nFor a Python project this is the one to reach for. Use OpenAPI Generator when you need a language it does not cover.\n\n## Proving your client agrees on the wire\n\nWhichever tool you use, the generated client is only as correct as the document it was built from - and the document is kept honest by a [CI check](https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/scripts/check-openapi-sync.ts) that fails if it ever stops matching the [builder](https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/scripts/build-openapi.ts) the servers use. The same portable [conformance check](https://github.com/nbarrett/ramblers-salesforce-server/blob/main/python/tests/test_contract_conformance.py) that the reference servers run against themselves can be pointed at your own server, so you can prove your implementation and your generated client agree on the wire before you rely on them.\n","contentHtml":"<h1>21-Jun-2026 — Generating a Typed Client from the OpenAPI Document</h1>\n<hr>\n<p>This is a companion to <a href=\"https://ngx-ramblers.org.uk/how-to/technical-articles/2026-06-21-python-reference-server\">A Python Reference Server</a>. It answers one narrow question: if you decide to build your own implementation of the Salesforce member API, outside the reference servers we provide, how do you turn the published contract into a typed client in your language?</p>\n<blockquote>\n<p><strong>You only need this if you are building your own client or server.</strong> If you adopt the reference server we provide, the typed client and server are already built for you and there is nothing to generate here.</p>\n</blockquote>\n<h2>Where the document is</h2>\n<p>The contract package <a href=\"https://github.com/nbarrett/ramblers-salesforce-contract\"><code>@ramblers/sf-contract</code></a> publishes a committed, static OpenAPI document, attached to each <a href=\"https://github.com/nbarrett/ramblers-salesforce-contract/tags\">release tag</a>:</p>\n<ul>\n<li><a href=\"https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/openapi/openapi.yaml\"><code>openapi/openapi.yaml</code></a></li>\n<li><a href=\"https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/openapi/openapi.json\"><code>openapi/openapi.json</code></a></li>\n</ul>\n<p>Either file is enough. Everything below takes one of them as input. You do not need Node, npm or any TypeScript to use them - they are plain text describing the wire format.</p>\n<h2>OpenAPI Generator (any language)</h2>\n<p>The recommended general-purpose tool is <strong><a href=\"https://openapi-generator.tech\">OpenAPI Generator</a></strong>. It reads the document and emits a typed client for 50+ targets - Python, Java, C#, Go, Rust, PHP, Kotlin, Swift and more. The easiest way to run it, with nothing to install but Docker, is:</p>\n<pre><code class=\"language-bash\">docker run --rm -v &quot;$PWD:/local&quot; openapitools/openapi-generator-cli generate \\\n  -i /local/openapi.yaml \\\n  -g python \\\n  -o /local/sf-client-python\n</code></pre>\n<p>Swap <code>-g python</code> for <code>-g java</code>, <code>-g csharp</code>, <code>-g go</code> and so on to target a different language. The full <a href=\"https://openapi-generator.tech/docs/generators\">list of generators</a> is on their site.</p>\n<h2>openapi-python-client (recommended for Python)</h2>\n<p>If your target is Python, <strong><a href=\"https://github.com/openapi-generators/openapi-python-client\">openapi-python-client</a></strong> produces a cleaner, fully type-annotated client (built on <a href=\"https://www.python-httpx.org\"><code>httpx</code></a> and <a href=\"https://www.attrs.org\"><code>attrs</code></a>) that reads more naturally than OpenAPI Generator&#39;s Python output:</p>\n<pre><code class=\"language-bash\">pipx run openapi-python-client generate --path openapi.yaml\n</code></pre>\n<p>For a Python project this is the one to reach for. Use OpenAPI Generator when you need a language it does not cover.</p>\n<h2>Proving your client agrees on the wire</h2>\n<p>Whichever tool you use, the generated client is only as correct as the document it was built from - and the document is kept honest by a <a href=\"https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/scripts/check-openapi-sync.ts\">CI check</a> that fails if it ever stops matching the <a href=\"https://github.com/nbarrett/ramblers-salesforce-contract/blob/main/scripts/build-openapi.ts\">builder</a> the servers use. The same portable <a href=\"https://github.com/nbarrett/ramblers-salesforce-server/blob/main/python/tests/test_contract_conformance.py\">conformance check</a> that the reference servers run against themselves can be pointed at your own server, so you can prove your implementation and your generated client agree on the wire before you rely on them.</p>\n"}