<p align="center">
<svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="@xemahq/api-client-generator">
  <rect width="680" height="120" rx="14" fill="#0B1020"/>
  <g transform="translate(28,34)">
    <path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="#F59E0B" opacity="0.18"/>
    <path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#F59E0B"/>
  </g>
  <text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="22" fill="#F8FAFC" font-weight="700">@xemahq/api-client-generator</text>
  <text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">Central OpenAPI + Orval client generator for Xema services.</text>
  <text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>
</svg>
</p>

<p align="center">
  <a href="https://xema.dev">Website</a> &middot;
  <a href="https://www.npmjs.com/package/@xemahq/api-client-generator">npm</a>
</p>

<p align="center">
  <img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Fapi-client-generator?color=2563eb&label=npm">
  <img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Fapi-client-generator?color=10b981">
  <img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Fapi-client-generator?color=3178c6">
</p>

# @xemahq/api-client-generator

> Central OpenAPI + Orval client generator for Xema services.

## Overview

The single, shared generator that produces typed API clients for every Xema
NestJS service. It extracts one OpenAPI document per API surface
(public / internal / operator) from decorator metadata, then generates one
Orval client package per non-empty surface, each sharing the owning service's
version. Provenance metadata is stamped deterministically into every generated
client's `package.json`. A route ships in a surface only when it — or its
controller — is explicitly classified; there is no heuristic inference.

## When to use it

- Use it to extract a service's OpenAPI document and generate its client
  packages instead of maintaining per-service generator scripts.
- Reach for the `xema-openapi` and `xema-client-generate` bins to wire client
  generation into a service's build.

## Installation

```bash
pnpm add -D @xemahq/api-client-generator
```

## Usage

```bash
# Extract one OpenAPI document per classified API surface:
xema-openapi

# Generate one Orval client package per non-empty surface:
xema-client-generate
```

### Version movement

Every surface client of a service lands on one derived version. When
regeneration changes the generated output, the version advances by a **bump
class** the generator works out from the published surface: an export removed is
a break, exports added only is additive, and bytes moving without any declaration
moving is a fix. On a `0.x` package the levels shift down by one, because `^0.9.6`
admits `>=0.9.6 <0.10.0` — a break has to move the minor to leave that range and
an addition is a patch because that is what stays inside it.

When the change cannot be classified — a retained export whose declaration
moved, where a request type and a response type have opposite variance — the run
**refuses** rather than guessing the smallest bump, and names what it could not
decide. State the class and re-run:

```bash
xema-client-generate --bump-class=minor
# or, for a whole-repo refresh that reaches each service through turbo:
XEMA_CLIENT_BUMP_CLASS=minor pnpm refresh
```

The flag wins over the environment variable. A stated class below one the
comparison proved is refused, not silently raised; a higher one is always
honoured. Decide it from the PUBLISHED tarball of the current version rather
than from the source tree.

## Peer requirements

- `@nestjs/common`, `@nestjs/core`, `@nestjs/swagger`, `@nestjs/testing` — the
  service is bootstrapped to read its route metadata.
- `@xemahq/xema-decorators` — supplies the API-surface classification metadata.
- `orval` — drives client code generation.
- `reflect-metadata`, `ts-node`, `tsconfig-paths`, `typescript` — runtime and
  TypeScript toolchain for extraction.

## License

Apache-2.0 &copy; Xema — [xema.dev](https://xema.dev)
