Code Generation
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.
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 / Framework | Generator flag |
|---|---|
| TypeScript (Axios) | typescript-axios |
| TypeScript (Fetch) | typescript-fetch |
| Java | java |
| C# | csharp |
| Kotlin | kotlin |
| Go | go |
| Ruby | ruby |
| Swift | swift5 |
| Dart | dart |
| Rust | rust |
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 thanlatesthelps 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=falseto avoid generating placeholder test files. - You may want to post-process with your linter - running your language's formatter (e.g.
rufffor Python,prettierfor 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
--configto keep your generate command clean and version-controllable.
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 StartedResource IDs
It is possible to use different types of resource IDs in requests to Leyr API. Get resource details, book appointments, create medical notes and documents using EHR IDs, HSA IDs and more.
Test Data for our EHRs
Here we have prepared some test data for you to try out integration with our EHRs in Leyr Sandbox. It is first and foremost applicable when using Leyr credentials, as described in the EHR configuration guide.