# lapis-spec

Convert OpenAPI 3.0/3.1 specifications to [LAPIS](https://github.com/cr0hn/LAPIS) format.

LAPIS (Lightweight API Specification for Intelligent Systems) is a compact API description format designed for LLM consumption, achieving 70-80% token reduction compared to OpenAPI YAML.

## Installation

```bash
pip install lapis-spec
```

Or with [uv](https://docs.astral.sh/uv/):

```bash
uv pip install lapis-spec
```

## Usage

```bash
# Convert OpenAPI YAML to LAPIS
lapis -i openapi.yaml -o api.lapis

# Convert OpenAPI JSON to LAPIS
lapis -i openapi.json -o api.lapis

# Skip OpenAPI validation (useful for partial specs)
lapis -i openapi.yaml -o api.lapis --no-validate
```

### CLI Options

| Option | Description |
|---|---|
| `-i`, `--input` | Path to OpenAPI file (.json, .yaml, .yml) |
| `-o`, `--output` | Path to output .lapis file |
| `--no-validate` | Skip OpenAPI schema validation |
| `--version` | Show version and exit |
| `-h`, `--help` | Show help message |

## Supported Features

- OpenAPI 3.0.x and 3.1.x
- JSON and YAML input formats
- Full `$ref` resolution (including circular references)
- `allOf`/`oneOf`/`anyOf` flattening
- All LAPIS sections: `[meta]`, `[types]`, `[ops]`, `[webhooks]`, `[errors]`, `[limits]`, `[flows]`
- Automatic schema deduplication (inline vs named types)
- Security scheme interpretation (bearer, apikey, basic, oauth2)
- Operation modifier detection (`+deprecated`, `+paginated`, `+idempotent`, `+stream`)
- Error response collection and deduplication

## Development

```bash
# Install dependencies
uv sync

# Run tests
uv run pytest

# Run tests with coverage report
uv run pytest --cov-report=html

# Lint
uv run ruff check src/ tests/

# Type check
uv run mypy
```

## License

MIT
