Leyr
Guides

Code Generation

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.

Generate a typed API client from the Leyr OpenAPI spec

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.

Leyr uses OpenAPI Generator 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.

OpenAPI Spec URL

The Leyr OpenAPI specification is available at:

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

You can also browse it interactively:

  • Redoc - clean, readable API reference
  • Swagger UI - 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):
    docker pull openapitools/openapi-generator-cli:v7.10.0
    
  • npm:
    npm install -g @openapitools/openapi-generator-cli
    
  • Homebrew (macOS):
    brew install openapi-generator
    

For other options, see the official installation guide.

Quick Start - Python Example

1. Generate the client

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:

pip install -r leyr-client/requirements.txt

3. Use the client

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:

Language / FrameworkGenerator flag
TypeScript (Axios)typescript-axios
TypeScript (Fetch)typescript-fetch
Javajava
C#csharp
Kotlinkotlin
Gogo
Rubyruby
Swiftswift5
Dartdart
Rustrust

For the full list of 40+ supported languages, see the OpenAPI Generator documentation.

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.
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.

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:

Getting Started