Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/openapi-version-in-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'seamless-auth-api': patch
---

`openapi.json` and `adapter-manifest.json` now carry the package version. The release version step regenerates both, and the contract test fails when either file drifts from the route definitions or from `package.json`. Both said 0.17.0 through the 0.18.0 release.
2 changes: 1 addition & 1 deletion adapter-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"apiVersion": "0.17.0",
"apiVersion": "0.18.0",
"session": {
"subject": "sub",
"token": "token",
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"openapi": "3.0.3",
"info": { "title": "Seamless Auth API", "version": "0.17.0" },
"info": { "title": "Seamless Auth API", "version": "0.18.0" },
"components": {
"schemas": {},
"parameters": {},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"format:check": "prettier --check .",
"changeset": "changeset",
"check:changeset-bump": "node ./src/scripts/checkChangesetBump.mjs",
"version-packages": "changeset version",
"version-packages": "changeset version && npm run generate:api",
"db:create": "env-cmd -f .env sequelize-cli db:create || sequelize-cli db:create",
"db:drop": "env-cmd -f .env sequelize-cli db:drop || sequelize-cli db:drop",
"db:refresh": "env-cmd -f .env sequelize-cli db:drop && sequelize-cli db:create",
Expand Down
19 changes: 16 additions & 3 deletions tests/unit/openapi/generatedContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';

import { describe, expect, it } from 'vitest';

import { getAdapterManifest } from '../../../src/lib/adapterManifest.js';
import { buildOpenApiDocument } from '../../../src/scripts/generateApiTypes.js';

const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '../../..');
Expand All @@ -12,14 +13,26 @@ function readCommitted(relativePath: string) {
return readFileSync(join(repoRoot, relativePath), 'utf8');
}

const packageVersion = JSON.parse(readCommitted('package.json')).version;

describe('generated API contract', () => {
it('keeps openapi.json in step with the route definitions', async () => {
const generated = await buildOpenApiDocument();
const committed = JSON.parse(readCommitted('openapi.json'));

// The version tracks package.json, which Changesets bumps on release without
// regenerating. Everything else must match.
expect({ ...generated, info: undefined }).toEqual({ ...committed, info: undefined });
expect(committed).toEqual(generated);
});

it('versions openapi.json with the package', () => {
expect(JSON.parse(readCommitted('openapi.json')).info.version).toBe(packageVersion);
});

it('keeps adapter-manifest.json in step with the route definitions', async () => {
await buildOpenApiDocument();
const committed = JSON.parse(readCommitted('adapter-manifest.json'));

expect(committed).toEqual(JSON.parse(JSON.stringify(getAdapterManifest())));
expect(committed.apiVersion).toBe(packageVersion);
});

it('ships non-empty generated types', () => {
Expand Down
Loading