Skip to content

Commit

Permalink
Chore: Packaging and publishing canaries (#3)
Browse files Browse the repository at this point in the history
* v1.0.1-1

* Add examples and pre-publish
  • Loading branch information
simonireilly authored Jan 25, 2022
1 parent c0a2ef0 commit 1a4f3c1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ jobs:
- run: yarn

- run: yarn test

- run: yarn pack
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const { response } = stuff('/test', 'get');
const resp = response('200', { name: 'Type-safe reply' });
```

Compel will tell you want `statusCode`'s are acceptable for the path, and it will bind the response body type to that `statusCode`.
Compeller will tell you what combinations of status codes and bodies are compatible when building responses.

When you need to make changes, you will be compelled to keep them in your central `spec.ts` file, maintaining parity between your OpenAPI and your code.

Expand Down
8 changes: 8 additions & 0 deletions examples/with-json-schema-to-ts/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { compeller } from '../../src';
import { OpenAPISpecification } from './specification';

const specification = compeller(OpenAPISpecification);

const { response } = specification('/pet', 'get');

response('200', { age: 11, name: 'Bobby' });
21 changes: 21 additions & 0 deletions examples/with-json-schema-to-ts/pet.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FromSchema } from 'json-schema-to-ts';

export const Schema = {
type: 'object',
required: ['age', 'name'],
additionalProperties: false,
properties: {
name: {
type: 'string',
minLength: 3,
maxLength: 12,
},
age: {
type: 'number',
maximum: 120,
minimum: 0,
},
},
} as const;

export type Pet = FromSchema<typeof Schema>;
25 changes: 25 additions & 0 deletions examples/with-json-schema-to-ts/specification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Schema } from './pet.schema';

export const OpenAPISpecification = {
info: {
title: 'AJV Schema Example',
version: '1.0.0',
},
openapi: '3.1.0',
paths: {
'/pet': {
get: {
responses: {
'200': {
description: 'Get the pet',
content: {
'application/json': {
schema: Schema,
},
},
},
},
},
},
},
};
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ module.exports = {
},
testEnvironment: 'node',
modulePathIgnorePatterns: ['<rootDir>/.*/fixtures/'],
moduleNameMapper: {
'^compeller/(.*)$': '<rootDir>/src/$1',
},
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "compeller",
"version": "1.0.0",
"version": "1.0.1-1",
"description": "",
"main": "dist/index.js",
"scripts": {
"test": "jest",
"build": "tsc --build",
"clean": "tsc --build --clean",
"prepare": "husky install",
"prepack": "yarn clean && yarn build"
"prepack": "yarn clean && yarn build",
"canary": "yarn publish --prerelease --dist-tag canary"
},
"keywords": [],
"author": "simon",
Expand Down

0 comments on commit 1a4f3c1

Please sign in to comment.