Skip to content

Commit f999767

Browse files
committed
fix log-server openapi file loading
log-api now exports a json file instead of a yaml file
1 parent e234e37 commit f999767

File tree

7 files changed

+17
-24
lines changed

7 files changed

+17
-24
lines changed

packages/log-api/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dist/
88
# Dependency directories
99
node_modules/
1010

11-
openapi.yaml
11+
openapi.yaml
12+
openapi.json

packages/log-api/tspconfig.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ emit:
33
options:
44
'@typespec/openapi3':
55
emitter-output-dir: '{output-dir}'
6-
output-file: 'openapi.yaml'
7-
file-type: 'yaml'
6+
output-file: 'openapi.json'
7+
file-type: 'json'
88
seal-object-schemas: true
99
openapi-versions:
1010
- '3.1.0'

packages/log-client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
},
3535
"scripts": {
3636
"test": "cross-env NODE_ENV=test vitest",
37-
"generate-api-types": "openapi-typescript node_modules/@lightmill/log-api/openapi.yaml --empty-objects-unknown --output ./generated/api.d.ts",
38-
"watch:generate-api-types": "pnpm run generate-api-types && onchange 'node_modules/@lightmill/log-api/openapi.yaml' --no-exclude -- pnpm run generate-api-types",
37+
"generate-api-types": "openapi-typescript node_modules/@lightmill/log-api/openapi.json --empty-objects-unknown --output ./generated/api.d.ts",
38+
"watch:generate-api-types": "pnpm run generate-api-types && onchange 'node_modules/@lightmill/log-api/openapi.json' --no-exclude -- pnpm run generate-api-types",
3939
"build": "pnpm run generate-api-types && tsc -b tsconfig.build.json",
4040
"prepublish": "pnpm run build"
4141
},

packages/log-server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"build": "pnpm run generate-api-types && rm -rf dist && tsc -b tsconfig.build.json",
2424
"prepublish": "pnpm run build",
2525
"test": "cross-env NODE_ENV=test vitest --typecheck",
26-
"generate-api-types": "openapi-typescript node_modules/@lightmill/log-api/openapi.yaml --empty-objects-unknown --output ./generated/api.d.ts",
27-
"watch:generate-api-types": "pnpm run generate-api-types && onchange 'node_modules/@lightmill/log-api/openapi.yaml' --no-exclude -- pnpm run generate-api-types",
26+
"generate-api-types": "openapi-typescript node_modules/@lightmill/log-api/openapi.json --empty-objects-unknown --output ./generated/api.d.ts",
27+
"watch:generate-api-types": "pnpm run generate-api-types && onchange 'node_modules/@lightmill/log-api/openapi.json' --no-exclude -- pnpm run generate-api-types",
2828
"cli": "tsx ./src/cli.ts",
2929
"cli-watch": "tsx --watch ./src/cli.ts"
3030
},

packages/log-server/src/app.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { match, P } from '@gabriel/ts-pattern';
2-
import { parse } from '@std/yaml';
2+
import apiSpecModule from '@lightmill/log-api/openapi.json' with { type: 'json' };
33
import cookieParser from 'cookie-parser';
44
import express, { type NextFunction } from 'express';
55
import * as OpenApiValidator from 'express-openapi-validator';
@@ -10,8 +10,6 @@ import {
1010
import session, { Store as SessionStore } from 'express-session';
1111
import log from 'loglevel';
1212
import MemorySessionStoreModule from 'memorystore';
13-
import { readFileSync } from 'node:fs';
14-
import path from 'node:path';
1513
import type { components } from '../generated/api.js';
1614
import { experimentHandlers } from './app-experiments-handlers.js';
1715
import { logHandlers } from './app-logs-handlers.js';
@@ -23,10 +21,7 @@ import { createTypedExpressServer } from './typed-server.js';
2321
import { firstStrict } from './utils.js';
2422

2523
const SESSION_COOKIE_NAME = 'lightmill-session-id';
26-
const OPEN_API_SPEC = path.join(
27-
import.meta.dirname,
28-
'../node_modules/@lightmill/log-api/openapi.yaml',
29-
);
24+
const apiSpec = apiSpecModule as OpenAPIV3.DocumentV3;
3025

3126
const MemorySessionStore = MemorySessionStoreModule(session);
3227

@@ -76,13 +71,9 @@ export function LogServer({
7671
}),
7772
);
7873

79-
const apiSpecFile = readFileSync(OPEN_API_SPEC, 'utf8');
80-
const apiSpec = parse(apiSpecFile) as OpenAPIV3.DocumentV3;
81-
apiSpec.servers = [{ url: baseUrl }];
82-
8374
app.use(
8475
OpenApiValidator.middleware({
85-
apiSpec,
76+
apiSpec: { ...apiSpec, servers: [{ url: baseUrl }] },
8677
validateApiSpec: mode !== 'production',
8778
validateRequests: { allErrors: mode !== 'production' },
8879
validateResponses: mode !== 'production',

packages/log-server/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"extends": "../../tsconfig.json",
44
"compilerOptions": {
55
"allowSyntheticDefaultImports": true,
6-
"noUncheckedIndexedAccess": true
6+
"noUncheckedIndexedAccess": true,
7+
"resolveJsonModule": true
78
},
89
"include": [
910
"./src/**/*.ts",

tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"compilerOptions": {
4-
"target": "es2022",
5-
"lib": ["es2022"],
6-
"module": "Node16",
7-
"moduleResolution": "Node16",
4+
"target": "ESNext",
5+
"lib": ["ESNext"],
6+
"module": "NodeNext",
7+
"moduleResolution": "NodeNext",
88
"noImplicitAny": true,
99
"strict": true,
1010
"sourceMap": true,

0 commit comments

Comments
 (0)