lib/openapi.ts is the machine-readable spec (served at /api/openapi) per AGENTS.md; info.version sourced from package.json. Unit tests pin the spec shape and version sync.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import pkg from '@/package.json';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { openApiSpec } from './openapi';
|
|
|
|
describe('OpenAPI spec', () => {
|
|
it('documents exactly the one public endpoint (scaffold stage)', () => {
|
|
expect(Object.keys(openApiSpec.paths).sort()).toEqual(['/api/version']);
|
|
});
|
|
|
|
it('keeps info.version in sync with package.json', () => {
|
|
expect(openApiSpec.info.title).toBe('SpaceWanderer API');
|
|
expect(openApiSpec.info.version).toBe(pkg.version);
|
|
});
|
|
|
|
it('uses an empty server url so "try it" targets the current origin', () => {
|
|
expect(openApiSpec.servers).toEqual([{ url: '' }]);
|
|
});
|
|
|
|
it('describes /api/version as { version } with a string version', () => {
|
|
const schema = openApiSpec.paths['/api/version'].get.responses[200].content['application/json'].schema;
|
|
expect(schema.$ref).toBe('#/components/schemas/AppVersion');
|
|
|
|
const appVersion = openApiSpec.components.schemas.AppVersion.properties;
|
|
expect(Object.keys(appVersion)).toEqual(['version']);
|
|
expect(appVersion.version.type).toBe('string');
|
|
});
|
|
});
|