# compeller

> A strong typescript binding for your OpenAPI Schema that doesn't need generation.

Latest version **0.0.1-alpha.0** (published 2022-01-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install compeller
pnpm add compeller
yarn add compeller
bun add compeller
```

Provides the command `compeller`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.0 |
| Published | 2022-01-27 |
| First published | 2022-01-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 12 |
| Dependencies | 4 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | simonreilly |
| Maintainers | simonreilly |
| Keywords | openapi, typescript, schema, json |

## Links

- npm: https://www.npmjs.com/package/compeller
- Repository: https://github.com/simonireilly/compeller
- Issues: https://github.com/simonireilly/compeller/issues
- npm.io page: https://npm.io/package/compeller

## Dependencies (4)

- [ajv](https://npm.io/package/ajv.md) ^8.9.0
- [hygen](https://npm.io/package/hygen.md) ^6.1.0
- [openapi3-ts](https://npm.io/package/openapi3-ts.md) ^2.0.1
- [json-schema-to-ts](https://npm.io/package/json-schema-to-ts.md) ^1.6.5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.1-alpha.0 (latest) — 2022-01-27
- 0.0.1-alpha.6 (alpha) — 2022-01-28
- 0.0.1-alpha.5 — 2022-01-28
- 0.0.1-alpha.4 — 2022-01-28
- 0.0.1-alpha.3 — 2022-01-27
- 0.0.1-alpha.2 — 2022-01-27
- 0.0.1-alpha.1 — 2022-01-27

## README

![Compeller basic logo](./assets/logo.drawio.svg)
# Compeller

A strong typescript binding for your OpenAPI Schema that doesn't need generation.

- [Compeller](#compeller)
  - [About](#about)
  - [Get started](#get-started)
    - [Usage](#usage)
  - [Shoulders](#shoulders)

## About

Compeller tries to infer your OpenAPI validations and responses, from a typed OpenAPI specification.

## Get started

You can use the CLI to start a new project, generating an OpenAPI specification.

```bash
npx compeller new
```

### Usage

Create a Schema specification for an API Model like:

```ts
// ./example/openapi/schemas/version.schema.ts

import { FromSchema } from 'json-schema-to-ts';

export const VersionSchema = {
  type: 'object',
  required: ['version'],
  additionalProperties: false,
  properties: {
    version: {
      type: 'string',
    },
  },
} as const;

export type Version = FromSchema<typeof VersionSchema>;

```

Next, bind the model into an OpenAPI specification object.

```ts
// ./example/openapi/spec.ts

import { VersionSchema } from './schemas/version.schema';

export const OpenAPISpecification = {
  info: {
    title: 'New API generated with compeller',
    version: '1.0.0',
  },
  openapi: '3.1.0',
  paths: {
    'v1//version': {
      get: {
        responses: {
          '200': {
            description: 'Get the current API version',
            content: {
              'application/json': {
                schema: VersionSchema,
              },
            },
          },
        },
      },
    },
  },
};
```

With compeller you can compile this into a typed request and response handler like:

```ts
import { OpenAPISpecification } from './spec';

// The api is inferred, and validations are generated
const api = compeller(OpenAPISpecification);

// These routes and methods are enforced
const { response } = api('/v1/version', 'get');

// The response code and body schema are bound
const resp = response('200', { name: 'Type-safe reply' });
```

## Shoulders

Compell is built on top of some great libraries, at it's core it relies on:

- [openapi3-ts](https://github.com/metadevpro/openapi3-ts)
- [json-schema-to-ts](https://github.com/ThomasAribart/json-schema-to-ts)

It also layers on request and response validation powered by:

- [ajv](https://github.com/ajv-validator/ajv)

I'm grateful for these libraries

---
_Source: https://npm.io/package/compeller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
