@websublime/vite-plugin-open-api-server 0.24.0-next.4 → 0.24.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +74 -12
- package/dist/index.js +618 -562
- package/dist/index.js.map +1 -1
- package/package.json +19 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin, ViteDevServer } from 'vite';
|
|
2
|
-
import { Logger, SpecInfo, OpenApiServer, HandlerFn, AnySeedFn } from '@websublime/vite-plugin-open-api-core';
|
|
2
|
+
import { Logger, SpecInfo, OpenApiServer, WebSocketHub, HandlerFn, AnySeedFn } from '@websublime/vite-plugin-open-api-core';
|
|
3
3
|
export { HandlerContext, HandlerDefinition, HandlerFn, HandlerReturn, SecurityContext, SeedContext, SeedDefinition, SeedFn, SeedHelper, defineHandlers, defineSeeds } from '@websublime/vite-plugin-open-api-core';
|
|
4
4
|
import { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
5
5
|
import { Hono } from 'hono';
|
|
@@ -243,13 +243,44 @@ declare function resolveOptions(options: OpenApiServerOptions): ResolvedOptions;
|
|
|
243
243
|
/**
|
|
244
244
|
* Vite Plugin Implementation
|
|
245
245
|
*
|
|
246
|
-
* What: Main Vite plugin for OpenAPI mock server
|
|
247
|
-
* How: Uses
|
|
248
|
-
* Why: Integrates OpenAPI mock
|
|
246
|
+
* What: Main Vite plugin for OpenAPI mock server (multi-spec)
|
|
247
|
+
* How: Uses orchestrator to create N spec instances, configures multi-proxy
|
|
248
|
+
* Why: Integrates multiple OpenAPI mock servers seamlessly into Vite dev workflow
|
|
249
249
|
*
|
|
250
250
|
* @module plugin
|
|
251
251
|
*/
|
|
252
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Create the OpenAPI Server Vite plugin
|
|
255
|
+
*
|
|
256
|
+
* This plugin starts mock servers based on OpenAPI specifications
|
|
257
|
+
* and configures Vite to proxy API requests to them. Supports
|
|
258
|
+
* multiple specs via the orchestrator pattern.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* // vite.config.ts
|
|
263
|
+
* import { defineConfig } from 'vite';
|
|
264
|
+
* import vue from '@vitejs/plugin-vue';
|
|
265
|
+
* import { openApiServer } from '@websublime/vite-plugin-open-api-server';
|
|
266
|
+
*
|
|
267
|
+
* export default defineConfig({
|
|
268
|
+
* plugins: [
|
|
269
|
+
* vue(),
|
|
270
|
+
* openApiServer({
|
|
271
|
+
* specs: [
|
|
272
|
+
* { spec: './openapi/petstore.yaml', proxyPath: '/api/pets' },
|
|
273
|
+
* { spec: './openapi/inventory.yaml', proxyPath: '/api/inventory' },
|
|
274
|
+
* ],
|
|
275
|
+
* port: 4000,
|
|
276
|
+
* }),
|
|
277
|
+
* ],
|
|
278
|
+
* });
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* @param options - Plugin configuration options
|
|
282
|
+
* @returns Vite plugin
|
|
283
|
+
*/
|
|
253
284
|
declare function openApiServer(options: OpenApiServerOptions): Plugin;
|
|
254
285
|
|
|
255
286
|
/**
|
|
@@ -467,12 +498,31 @@ interface SpecInstance {
|
|
|
467
498
|
* individual spec instances, aggregated metadata, and lifecycle methods.
|
|
468
499
|
*/
|
|
469
500
|
interface OrchestratorResult {
|
|
470
|
-
/**
|
|
501
|
+
/**
|
|
502
|
+
* Main Hono app with all specs mounted via X-Spec-Id dispatch.
|
|
503
|
+
*
|
|
504
|
+
* **Note**: Consumers using this property directly must have `hono`
|
|
505
|
+
* as a dependency. The `start()`/`stop()` lifecycle methods do not
|
|
506
|
+
* require direct interaction with this Hono instance.
|
|
507
|
+
*/
|
|
471
508
|
app: Hono;
|
|
472
509
|
/** All spec instances (in config order) */
|
|
473
510
|
instances: SpecInstance[];
|
|
474
511
|
/** Spec metadata array for WebSocket `connected` event */
|
|
475
512
|
specsInfo: SpecInfo[];
|
|
513
|
+
/**
|
|
514
|
+
* Shared WebSocket hub for the orchestrator.
|
|
515
|
+
*
|
|
516
|
+
* Created with `autoConnect: false` so the orchestrator controls
|
|
517
|
+
* the `connected` event (enhanced with `specs` metadata).
|
|
518
|
+
*
|
|
519
|
+
* In multi-spec mode (Epic 3, Task 3.1), this hub will be replaced by
|
|
520
|
+
* `createMultiSpecWebSocketHub()` which also wires broadcast interception
|
|
521
|
+
* and multi-spec command routing.
|
|
522
|
+
*
|
|
523
|
+
* @experimental Will be replaced by `createMultiSpecWebSocketHub()` in Epic 3.
|
|
524
|
+
*/
|
|
525
|
+
wsHub: WebSocketHub;
|
|
476
526
|
/** Start the shared HTTP server on the configured port */
|
|
477
527
|
start(): Promise<void>;
|
|
478
528
|
/** Stop the HTTP server and clean up resources */
|
|
@@ -491,9 +541,10 @@ interface OrchestratorResult {
|
|
|
491
541
|
* 3. **Phase 3 — Build main app**: Create a single Hono app with CORS,
|
|
492
542
|
* DevTools, Internal API, and X-Spec-Id dispatch middleware.
|
|
493
543
|
*
|
|
494
|
-
* **Note**: This function
|
|
495
|
-
*
|
|
496
|
-
*
|
|
544
|
+
* **Note**: This function populates the resolved values (id, proxyPath,
|
|
545
|
+
* proxyPathSource, handlersDir, seedsDir) on each `options.specs[i]` object.
|
|
546
|
+
* Since `instances[i].config` is the same object reference, consumers should
|
|
547
|
+
* access resolved values through `instances[i].config` (the authoritative view).
|
|
497
548
|
*
|
|
498
549
|
* @param options - Resolved plugin options (from `resolveOptions()`)
|
|
499
550
|
* @param vite - Vite dev server instance (for ssrLoadModule)
|
|
@@ -513,6 +564,17 @@ declare function createOrchestrator(options: ResolvedOptions, vite: ViteDevServe
|
|
|
513
564
|
* @module multi-proxy
|
|
514
565
|
*/
|
|
515
566
|
|
|
567
|
+
/**
|
|
568
|
+
* Shared service proxy path prefixes.
|
|
569
|
+
*
|
|
570
|
+
* These constants are the single source of truth for the reserved proxy paths
|
|
571
|
+
* used by the DevTools iframe, internal API, and WebSocket connections.
|
|
572
|
+
* Both `configureMultiProxy()` and the virtual DevTools tab module in
|
|
573
|
+
* `plugin.ts` reference these to prevent divergence.
|
|
574
|
+
*/
|
|
575
|
+
declare const DEVTOOLS_PROXY_PATH = "/_devtools";
|
|
576
|
+
declare const API_PROXY_PATH = "/_api";
|
|
577
|
+
declare const WS_PROXY_PATH = "/_ws";
|
|
516
578
|
/**
|
|
517
579
|
* Configure Vite proxy for multiple spec instances and shared services.
|
|
518
580
|
*
|
|
@@ -766,7 +828,7 @@ declare function debounce<T extends (...args: unknown[]) => unknown>(fn: T, dela
|
|
|
766
828
|
interface RegisterDevToolsOptions {
|
|
767
829
|
/**
|
|
768
830
|
* The port where the OpenAPI server is running
|
|
769
|
-
* @default
|
|
831
|
+
* @default 4000
|
|
770
832
|
*/
|
|
771
833
|
port?: number;
|
|
772
834
|
/**
|
|
@@ -808,7 +870,7 @@ interface RegisterDevToolsOptions {
|
|
|
808
870
|
*
|
|
809
871
|
* // Register OpenAPI Server DevTools
|
|
810
872
|
* if (import.meta.env.DEV) {
|
|
811
|
-
* await registerDevTools(app
|
|
873
|
+
* await registerDevTools(app);
|
|
812
874
|
* }
|
|
813
875
|
*
|
|
814
876
|
* app.mount('#app');
|
|
@@ -824,11 +886,11 @@ declare function registerDevTools(app: App, options?: RegisterDevToolsOptions):
|
|
|
824
886
|
* When running in a browser, protocol and host are automatically derived from
|
|
825
887
|
* window.location if not explicitly provided.
|
|
826
888
|
*
|
|
827
|
-
* @param port - Server port (default:
|
|
889
|
+
* @param port - Server port (default: 4000, matching OpenApiServerOptions.port)
|
|
828
890
|
* @param host - Server host (default: 'localhost' or window.location.hostname)
|
|
829
891
|
* @param protocol - Protocol to use (default: 'http' or window.location.protocol)
|
|
830
892
|
* @returns DevTools SPA URL
|
|
831
893
|
*/
|
|
832
894
|
declare function getDevToolsUrl(port?: number, host?: string, protocol?: 'http' | 'https'): string;
|
|
833
895
|
|
|
834
|
-
export { type DeriveProxyPathResult, type FileWatcher, type FileWatcherOptions, type LoadHandlersResult, type LoadSeedsResult, type OpenApiServerOptions, type OrchestratorResult, type ProxyPathSource, type RegisterDevToolsOptions, type ResolvedOptions, type ResolvedSpecConfig, SPEC_COLORS, type SpecConfig, type SpecInstance, ValidationError, type ValidationErrorCode, configureMultiProxy, createFileWatcher, createOrchestrator, debounce, deriveProxyPath, deriveSpecId, getDevToolsUrl, getHandlerFiles, getSeedFiles, loadHandlers, loadSeeds, normalizeProxyPath, openApiServer, registerDevTools, resolveOptions, slugify, validateSpecs, validateUniqueIds, validateUniqueProxyPaths };
|
|
896
|
+
export { API_PROXY_PATH, DEVTOOLS_PROXY_PATH, type DeriveProxyPathResult, type FileWatcher, type FileWatcherOptions, type LoadHandlersResult, type LoadSeedsResult, type OpenApiServerOptions, type OrchestratorResult, type ProxyPathSource, type RegisterDevToolsOptions, type ResolvedOptions, type ResolvedSpecConfig, SPEC_COLORS, type SpecConfig, type SpecInstance, ValidationError, type ValidationErrorCode, WS_PROXY_PATH, configureMultiProxy, createFileWatcher, createOrchestrator, debounce, deriveProxyPath, deriveSpecId, getDevToolsUrl, getHandlerFiles, getSeedFiles, loadHandlers, loadSeeds, normalizeProxyPath, openApiServer, registerDevTools, resolveOptions, slugify, validateSpecs, validateUniqueIds, validateUniqueProxyPaths };
|