---
title: "Code Generation"
description: "Generate a fully typed API client in your language of choice from Leyr's published OpenAPI 3.x specification."
canonical_url: "https://docs.leyr.io/api/guides/code-generation"
---
# Code Generation

> Generate a fully typed API client in your language of choice from Leyr's published OpenAPI 3.x specification.

Leyr publishes a full OpenAPI 3.x specification for its API. You can feed this spec into any OpenAPI-compatible code generator to produce a fully typed client library in your language of choice - Python, TypeScript, Java, C#, Go, Kotlin, Ruby, Swift, and [many more](https://openapi-generator.tech/docs/generators/#client-generators).

<u-alert color="primary" icon="heroicons:check-badge" variant="subtle">
<template v-slot:description="">

Leyr uses [OpenAPI Generator](https://openapi-generator.tech) internally to produce its own client libraries. The workflow described below is the same approach we use, so you can be confident the spec is well-suited for code generation.

</template>
</u-alert>

## OpenAPI Spec URL

The Leyr OpenAPI specification is available at:

```text
https://api.leyr.io/openapi.json
```

You can also browse it interactively:

- [Redoc](https://api.leyr.io/docs) - clean, readable API reference
- [Swagger UI](https://api.leyr.io/swagger) - interactive "try it out" interface

## Prerequisites

You need the **OpenAPI Generator CLI**. Pick whichever installation method suits your environment:

- **Docker** (recommended, no local install needed):
```bash
docker pull openapitools/openapi-generator-cli:v7.10.0
```
- **npm**:
```bash
npm install -g @openapitools/openapi-generator-cli
```
- **Homebrew** (macOS):
```bash
brew install openapi-generator
```

For other options, see the [official installation guide](https://openapi-generator.tech/docs/installation).

## Quick Start - Python Example

### 1. Generate the client

```bash
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.10.0 generate \
  -i https://api.leyr.io/openapi.json \
  -g python \
  -o /local/leyr-client \
  --skip-validate-spec \
  -p packageName=leyr_client
```

This produces a `leyr-client/` directory containing a fully typed Python package.

### 2. Install dependencies

The generated client will include a `requirements.txt` with the necessary dependencies. Install them with:

```bash
pip install -r leyr-client/requirements.txt
```

### 3. Use the client

```python
import os
import leyr_client
from leyr_client.rest import ApiException

configuration = leyr_client.Configuration(
    host="https://api.leyr.io"
)

configuration.api_key["leyr-client-id"] = os.environ["LEYR_CLIENT_ID"]
configuration.api_key["leyr-client-secret"] = os.environ["LEYR_CLIENT_SECRET"]

with leyr_client.ApiClient(configuration) as api_client:
    care_units_api = leyr_client.CareUnitsApi(api_client)

    try:
        response = care_units_api.care_units_get_care_units(
            emr="webdoc",
        )
        print(response)
    except ApiException as e:
        print(f"API error: {e}")
```

All request/response models are fully typed, giving you autocompletion and validation out of the box.

## Other Languages

Replace `-g python` with any supported generator. Popular choices:

<table>
<thead>
  <tr>
    <th>
      Language / Framework
    </th>
    
    <th>
      Generator flag
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      TypeScript (Axios)
    </td>
    
    <td>
      <code>
        typescript-axios
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      TypeScript (Fetch)
    </td>
    
    <td>
      <code>
        typescript-fetch
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Java
    </td>
    
    <td>
      <code>
        java
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      C#
    </td>
    
    <td>
      <code>
        csharp
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Kotlin
    </td>
    
    <td>
      <code>
        kotlin
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Go
    </td>
    
    <td>
      <code>
        go
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Ruby
    </td>
    
    <td>
      <code>
        ruby
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Swift
    </td>
    
    <td>
      <code>
        swift5
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Dart
    </td>
    
    <td>
      <code>
        dart
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Rust
    </td>
    
    <td>
      <code>
        rust
      </code>
    </td>
  </tr>
</tbody>
</table>

For the full list of 40+ supported languages, see the [OpenAPI Generator documentation](https://openapi-generator.tech/docs/generators/#client-generators).

## Tips & Recommendations

- **Consider using --skip-validate-spec** - the Leyr spec uses some advanced OpenAPI features that may trigger warnings in the validator but generate correctly.
- **Consider pinning the generator version** - using a specific version tag (e.g. `v7.10.0`) rather than `latest` helps ensure reproducible builds across your team.
- **Re-generate when needed** - when Leyr releases new endpoints or models, re-running the generator will pick them up.
- **If you want to skip test scaffolding** - you can pass `--global-property apiTests=false,modelTests=false` to avoid generating placeholder test files.
- **You may want to post-process with your linter** - running your language's formatter (e.g. `ruff` for Python, `prettier` for TypeScript) on the generated code helps keep a consistent style.
- **For complex setups, consider using a config file** - put your options in a YAML file and pass it with `--config` to keep your generate command clean and version-controllable.

<u-alert color="warning" icon="heroicons:exclamation-triangle" variant="subtle">
<template v-slot:description="">

The generated client is a snapshot of the API at the time of generation. If Leyr adds new endpoints or changes models, you will need to re-generate to get the updates.

</template>
</u-alert>

## Authentication

The generated client will include support for the `x-leyr-client-id` and `x-leyr-client-secret` headers used by Leyr API. You need to configure these with your application credentials.

If you haven't set up your developer application yet, follow the Getting Started guide:

<u-button to="https://docs.leyr.io/api/getting-started" trailing-icon="i-heroicons-outline-arrow-right">

Getting Started

</u-button>

## Next steps

<card-group>
<card icon="i-heroicons-rocket-launch" title="Quickstart" to="https://docs.leyr.io/api/quickstart">

Follow the end-to-end quickstart workflows for common scenarios.

</card>

<card icon="i-heroicons-exclamation-triangle" title="Error Handling" to="https://docs.leyr.io/api/error-handling">

Understand Leyr error codes and how to respond to them.

</card>
</card-group>


## Sitemap

See the full [sitemap](https://docs.leyr.io/sitemap.md) for all pages.
