compeller v0.0.1-alpha.0
Compeller
🚨 Alpha software 🚨
A strong typescript binding for your OpenAPI Schema that doesn't need generation.
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.
npx compeller new
Usage
Create a Schema specification for an API Model like:
// ./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.
// ./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:
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:
It also layers on request and response validation powered by:
I'm grateful for these libraries
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago