Skip to content

Commit 672b0d9

Browse files
committed
Rename module and main entrypoint API
1 parent 3963b8a commit 672b0d9

21 files changed

Lines changed: 76 additions & 66 deletions

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) openapi-library
3+
Copyright (c) 2025 OASprey Contributors
4+
Copyright (c) 2019-2022 openapi-library (original OpenAPIValidators)
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OpenAPI Validators
1+
# OASprey
22

33
Use Jest to assert that HTTP responses satisfy an OpenAPI spec.
44

@@ -9,7 +9,7 @@ to correct your server, your documentation, or both. The sooner you know the bet
99

1010
## Solution 😄
1111

12-
This plugin lets you automatically test whether your server's behaviour and
12+
This plugin lets you automatically test whether your server's behavior and
1313
documentation match. It adds Jest matchers that support the
1414
[OpenAPI standard](https://swagger.io/docs/specification/about/) for
1515
documenting REST APIs. In your JavaScript tests, you can simply assert
@@ -32,27 +32,31 @@ Features:
3232
[npm](http://npmjs.org)
3333

3434
```bash
35-
npm install --save-dev jest-openapi
35+
npm install --save-dev oasprey
3636
```
3737

3838
[yarn](https://yarnpkg.com/)
3939

4040
```bash
41-
yarn add --dev jest-openapi
41+
yarn add --dev oasprey
4242
```
4343

4444
## Importing
4545

4646
ES6 / TypeScript
4747

4848
```typescript
49-
import jestOpenAPI from 'jest-openapi';
49+
import { loadSpec } from 'oasprey';
50+
// or
51+
import loadSpec from 'oasprey';
5052
```
5153

5254
CommonJS / JavaScript
5355

5456
```javascript
55-
const jestOpenAPI = require('jest-openapi').default;
57+
const { loadSpec } = require('oasprey');
58+
// or
59+
const loadSpec = require('oasprey').default;
5660
```
5761

5862
## Usage
@@ -63,10 +67,10 @@ const jestOpenAPI = require('jest-openapi').default;
6367

6468
```javascript
6569
// Import this plugin
66-
import jestOpenAPI from 'jest-openapi';
70+
import { loadSpec } from 'oasprey';
6771

6872
// Load an OpenAPI file (YAML or JSON) into this plugin
69-
jestOpenAPI('path/to/openapi.yml');
73+
loadSpec('path/to/openapi.yml');
7074

7175
// Write your test
7276
describe('GET /example/endpoint', () => {
@@ -173,11 +177,11 @@ The '200' response defined for endpoint 'GET /example/endpoint' in API spec: {
173177

174178
```javascript
175179
// Import this plugin and the function you want to test
176-
import jestOpenAPI from 'jest-openapi';
180+
import { loadSpec } from 'oasprey';
177181
import { functionToTest } from 'path/to/your/code';
178182
179183
// Load an OpenAPI file (YAML or JSON) into this plugin
180-
jestOpenAPI('path/to/openapi.yml');
184+
loadSpec('path/to/openapi.yml');
181185
182186
// Write your test
183187
describe('functionToTest()', () => {
@@ -281,7 +285,7 @@ The 'ExampleSchemaObject' schema in API spec: {
281285

282286
```javascript
283287
// Import this plugin
284-
import jestOpenAPI from 'jest-openapi';
288+
import { loadSpec } from 'oasprey';
285289
286290
// Get an object representing your OpenAPI spec
287291
const openApiSpec = {
@@ -311,7 +315,7 @@ const openApiSpec = {
311315
};
312316
313317
// Load that OpenAPI object into this plugin
314-
jestOpenAPI(openApiSpec);
318+
loadSpec(openApiSpec);
315319
316320
// Write your test
317321
describe('GET /example/endpoint', () => {
@@ -331,7 +335,7 @@ describe('GET /example/endpoint', () => {
331335

332336
```javascript
333337
// Import this plugin and an HTTP client (e.g. axios)
334-
import jestOpenAPI from 'jest-openapi';
338+
import { loadSpec } from 'oasprey';
335339
import axios from 'axios';
336340
337341
// Write your test
@@ -340,7 +344,7 @@ describe('GET /example/endpoint', () => {
340344
beforeAll(async () => {
341345
const response = await axios.get('url/to/openapi/spec');
342346
const openApiSpec = response.data; // e.g. { openapi: '3.0.0', ... };
343-
jestOpenAPI(openApiSpec);
347+
loadSpec(openApiSpec);
344348
});
345349
346350
it('should satisfy OpenAPI spec', async () => {
@@ -357,11 +361,13 @@ describe('GET /example/endpoint', () => {
357361

358362
## Origin and Changes
359363

360-
This package is forked from [OpenAPIValidators](https://github.com/openapi-library/OpenAPIValidators).
364+
This package is a hard fork from [OpenAPIValidators](https://github.com/openapi-library/OpenAPIValidators).
361365
We have:
362366

363367
- Updated and removed dependencies to modern, supported tooling
364368
- Removed support for Chai and SuperAgent
369+
- Renamed the package to OASprey for ongoing maintenance
370+
- Renamed the `jestOpenAPI()` function to `loadSpec()`
365371

366372
Otherwise, we have preserved the original functionality as-is. All credit to
367373
the folks who contributed to that package!

jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
44
moduleNameMapper: {
5-
'^jest-openapi$': '<rootDir>/src/jest-openapi',
5+
'^oasprey$': '<rootDir>/src/oasprey',
66
},
77
transform: {
88
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.json' }],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "module",
33
"private": true,
4-
"name": "jest-openapi",
4+
"name": "oasprey",
55
"main": "dist/index.js",
66
"files": [
77
"dist/",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './jest-openapi/index.js';
1+
export { default, loadSpec } from './oasprey/index.js';
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ declare global {
88
interface Matchers<R> {
99
/**
1010
* Check the HTTP response object satisfies a response defined in your OpenAPI spec.
11-
* [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)
11+
* [See usage example](https://github.com/dachary-carey/OASprey#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)
1212
*/
1313
toSatisfyApiSpec(): R;
1414
/**
1515
* Check the object satisfies a schema defined in your OpenAPI spec.
16-
* [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)
16+
* [See usage example](https://github.com/dachary-carey/OASprey#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)
1717
*/
1818
toSatisfySchemaInApiSpec(schemaName: string): R;
1919
}
2020
}
2121
}
2222

23-
export default function (filepathOrObject: string | OpenAPISpecObject): void {
23+
export function loadSpec(filepathOrObject: string | OpenAPISpecObject): void {
2424
const openApiSpec = makeApiSpec(filepathOrObject);
2525

2626
const jestMatchers: jest.ExpectExtendMap = {
@@ -47,10 +47,13 @@ export default function (filepathOrObject: string | OpenAPISpecObject): void {
4747
console.error(
4848
[
4949
"Unable to find Jest's global expect.",
50-
'Please check you have configured jest-openapi correctly.',
51-
'See https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#usage for help.',
50+
'Please check you have configured OASprey correctly.',
51+
'See https://github.com/dachary-carey/OASprey#usage for help.',
5252
].join('\n'),
5353
);
5454
}
5555
/* istanbul ignore next */
5656
}
57+
58+
// Export as both named export and default export for flexibility
59+
export default loadSpec;
File renamed without changes.
File renamed without changes.

tests/jest-openapi/bugRecreationTemplate.test.ts renamed to tests/oasprey/bugRecreationTemplate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import { inspect } from 'util';
33

4-
import jestOpenAPI from '../../src/jest-openapi';
4+
import { loadSpec } from '../../src/oasprey';
55

66
const dirContainingApiSpec = path.resolve(
77
path.resolve(
@@ -13,7 +13,7 @@ const dirContainingApiSpec = path.resolve(
1313
describe('recreate bug (issue #XX)', () => {
1414
beforeAll(() => {
1515
const pathToApiSpec = path.join(dirContainingApiSpec, 'openapi.yml');
16-
jestOpenAPI(pathToApiSpec);
16+
loadSpec(pathToApiSpec);
1717
});
1818

1919
const res = {

0 commit comments

Comments
 (0)