11import { match , P } from '@gabriel/ts-pattern' ;
2- import { parse } from '@std/yaml' ;
2+ import apiSpecModule from '@lightmill/log-api/openapi.json' with { type : 'json' } ;
33import cookieParser from 'cookie-parser' ;
44import express , { type NextFunction } from 'express' ;
55import * as OpenApiValidator from 'express-openapi-validator' ;
@@ -10,8 +10,6 @@ import {
1010import session , { Store as SessionStore } from 'express-session' ;
1111import log from 'loglevel' ;
1212import MemorySessionStoreModule from 'memorystore' ;
13- import { readFileSync } from 'node:fs' ;
14- import path from 'node:path' ;
1513import type { components } from '../generated/api.js' ;
1614import { experimentHandlers } from './app-experiments-handlers.js' ;
1715import { logHandlers } from './app-logs-handlers.js' ;
@@ -23,10 +21,7 @@ import { createTypedExpressServer } from './typed-server.js';
2321import { firstStrict } from './utils.js' ;
2422
2523const 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
3126const 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' ,
0 commit comments