@websublime/vite-plugin-open-api-server 0.24.0-next.3 → 0.24.0-next.5
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 +111 -17
- package/dist/index.js +560 -525
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { App } from 'vue';
|
|
|
21
21
|
* Used across Tasks 1.2–1.4 for typed error handling.
|
|
22
22
|
* Matches TECHNICAL-SPECIFICATION-V2.md Appendix B.
|
|
23
23
|
*/
|
|
24
|
-
type ValidationErrorCode = 'SPEC_ID_MISSING' | 'SPEC_ID_DUPLICATE' | 'PROXY_PATH_MISSING' | 'PROXY_PATH_TOO_BROAD' | 'PROXY_PATH_DUPLICATE' | 'PROXY_PATH_OVERLAP' | 'SPEC_NOT_FOUND' | 'SPECS_EMPTY';
|
|
24
|
+
type ValidationErrorCode = 'SPEC_ID_MISSING' | 'SPEC_ID_DUPLICATE' | 'PROXY_PATH_MISSING' | 'PROXY_PATH_TOO_BROAD' | 'PROXY_PATH_DUPLICATE' | 'PROXY_PATH_OVERLAP' | 'PROXY_PATH_PREFIX_COLLISION' | 'SPEC_NOT_FOUND' | 'SPECS_EMPTY';
|
|
25
25
|
/**
|
|
26
26
|
* Typed validation error for configuration issues.
|
|
27
27
|
*
|
|
@@ -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
|
/**
|
|
@@ -379,21 +410,26 @@ declare function normalizeProxyPath(path: string, specId: string): string;
|
|
|
379
410
|
*
|
|
380
411
|
* Checks for:
|
|
381
412
|
* 1. Duplicate paths — two specs with the same proxyPath
|
|
382
|
-
* 2. Overlapping paths — one path is a prefix of another
|
|
383
|
-
* which would cause routing ambiguity
|
|
413
|
+
* 2. Overlapping paths — one path is a prefix of another at a segment boundary
|
|
414
|
+
* (e.g., "/api" and "/api/v1") which would cause routing ambiguity
|
|
415
|
+
* 3. String-prefix collisions — one path is a raw string prefix of another
|
|
416
|
+
* without a segment boundary (e.g., "/api" and "/api2"). Vite's internal
|
|
417
|
+
* proxy matching uses plain `url.startsWith(context)` with no segment
|
|
418
|
+
* awareness, so "/api" would incorrectly capture "/api2/users" requests.
|
|
384
419
|
*
|
|
385
420
|
* @remarks
|
|
386
421
|
* Entries with an empty or falsy `proxyPath` are silently skipped. These
|
|
387
422
|
* represent specs whose proxy path has not yet been resolved (e.g., during
|
|
388
423
|
* early option resolution before the OpenAPI document is processed). Callers
|
|
389
424
|
* should expect unresolved entries to be excluded from uniqueness checks
|
|
390
|
-
* rather than triggering false-positive
|
|
391
|
-
* PROXY_PATH_OVERLAP errors.
|
|
425
|
+
* rather than triggering false-positive errors.
|
|
392
426
|
*
|
|
393
427
|
* @param specs - Array of spec entries with id and proxyPath.
|
|
394
428
|
* Entries with empty/falsy proxyPath are skipped (unresolved).
|
|
395
429
|
* @throws {ValidationError} PROXY_PATH_DUPLICATE if duplicate paths found
|
|
396
|
-
* @throws {ValidationError} PROXY_PATH_OVERLAP if overlapping paths found
|
|
430
|
+
* @throws {ValidationError} PROXY_PATH_OVERLAP if overlapping paths found (segment boundary)
|
|
431
|
+
* @throws {ValidationError} PROXY_PATH_PREFIX_COLLISION if one path is a raw string prefix
|
|
432
|
+
* of another without a segment boundary (e.g., "/api" and "/api2")
|
|
397
433
|
*
|
|
398
434
|
* @example
|
|
399
435
|
* // Throws PROXY_PATH_DUPLICATE
|
|
@@ -408,6 +444,13 @@ declare function normalizeProxyPath(path: string, specId: string): string;
|
|
|
408
444
|
* { id: 'petstore', proxyPath: '/api' },
|
|
409
445
|
* { id: 'inventory', proxyPath: '/api/v1' },
|
|
410
446
|
* ]);
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* // Throws PROXY_PATH_PREFIX_COLLISION
|
|
450
|
+
* validateUniqueProxyPaths([
|
|
451
|
+
* { id: 'petstore', proxyPath: '/api' },
|
|
452
|
+
* { id: 'inventory', proxyPath: '/api2' },
|
|
453
|
+
* ]);
|
|
411
454
|
*/
|
|
412
455
|
declare function validateUniqueProxyPaths(specs: Array<{
|
|
413
456
|
id: string;
|
|
@@ -455,7 +498,13 @@ interface SpecInstance {
|
|
|
455
498
|
* individual spec instances, aggregated metadata, and lifecycle methods.
|
|
456
499
|
*/
|
|
457
500
|
interface OrchestratorResult {
|
|
458
|
-
/**
|
|
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
|
+
*/
|
|
459
508
|
app: Hono;
|
|
460
509
|
/** All spec instances (in config order) */
|
|
461
510
|
instances: SpecInstance[];
|
|
@@ -479,9 +528,10 @@ interface OrchestratorResult {
|
|
|
479
528
|
* 3. **Phase 3 — Build main app**: Create a single Hono app with CORS,
|
|
480
529
|
* DevTools, Internal API, and X-Spec-Id dispatch middleware.
|
|
481
530
|
*
|
|
482
|
-
* **Note**: This function
|
|
483
|
-
*
|
|
484
|
-
*
|
|
531
|
+
* **Note**: This function populates the resolved values (id, proxyPath,
|
|
532
|
+
* proxyPathSource, handlersDir, seedsDir) on each `options.specs[i]` object.
|
|
533
|
+
* Since `instances[i].config` is the same object reference, consumers should
|
|
534
|
+
* access resolved values through `instances[i].config` (the authoritative view).
|
|
485
535
|
*
|
|
486
536
|
* @param options - Resolved plugin options (from `resolveOptions()`)
|
|
487
537
|
* @param vite - Vite dev server instance (for ssrLoadModule)
|
|
@@ -490,6 +540,50 @@ interface OrchestratorResult {
|
|
|
490
540
|
*/
|
|
491
541
|
declare function createOrchestrator(options: ResolvedOptions, vite: ViteDevServer, cwd: string): Promise<OrchestratorResult>;
|
|
492
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Multi-Path Proxy Configuration
|
|
545
|
+
*
|
|
546
|
+
* What: Configures Vite proxy for multiple OpenAPI spec instances
|
|
547
|
+
* How: Generates one proxy entry per spec with path rewriting and X-Spec-Id header,
|
|
548
|
+
* plus shared service proxies for DevTools, Internal API, and WebSocket
|
|
549
|
+
* Why: Enables each spec's API requests to be routed through Vite to the shared server
|
|
550
|
+
*
|
|
551
|
+
* @module multi-proxy
|
|
552
|
+
*/
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Shared service proxy path prefixes.
|
|
556
|
+
*
|
|
557
|
+
* These constants are the single source of truth for the reserved proxy paths
|
|
558
|
+
* used by the DevTools iframe, internal API, and WebSocket connections.
|
|
559
|
+
* Both `configureMultiProxy()` and the virtual DevTools tab module in
|
|
560
|
+
* `plugin.ts` reference these to prevent divergence.
|
|
561
|
+
*/
|
|
562
|
+
declare const DEVTOOLS_PROXY_PATH = "/_devtools";
|
|
563
|
+
declare const API_PROXY_PATH = "/_api";
|
|
564
|
+
declare const WS_PROXY_PATH = "/_ws";
|
|
565
|
+
/**
|
|
566
|
+
* Configure Vite proxy for multiple spec instances and shared services.
|
|
567
|
+
*
|
|
568
|
+
* Generates:
|
|
569
|
+
* 1. **Per-spec proxy entries** — one per spec, with path rewriting (prefix
|
|
570
|
+
* stripping) and an `X-Spec-Id` header so the shared Hono server can
|
|
571
|
+
* route to the correct spec instance.
|
|
572
|
+
* 2. **Shared service proxies** — spec-agnostic entries for `/_devtools`,
|
|
573
|
+
* `/_api`, and `/_ws` that forward to the same server without path
|
|
574
|
+
* rewriting or spec headers.
|
|
575
|
+
*
|
|
576
|
+
* Uses `startsWith`/`slice` for path rewriting instead of the regex approach
|
|
577
|
+
* described in the tech spec (Section 5.7). Literal prefix matching is safer
|
|
578
|
+
* because it correctly handles regex metacharacters in proxy paths (e.g.,
|
|
579
|
+
* `/api.v3` matches literally, not as `/api<any>v3`).
|
|
580
|
+
*
|
|
581
|
+
* @param vite - Vite dev server instance
|
|
582
|
+
* @param instances - Resolved spec instances from the orchestrator
|
|
583
|
+
* @param port - Shared server port
|
|
584
|
+
*/
|
|
585
|
+
declare function configureMultiProxy(vite: ViteDevServer, instances: SpecInstance[], port: number): void;
|
|
586
|
+
|
|
493
587
|
/**
|
|
494
588
|
* Handler Loading
|
|
495
589
|
*
|
|
@@ -721,7 +815,7 @@ declare function debounce<T extends (...args: unknown[]) => unknown>(fn: T, dela
|
|
|
721
815
|
interface RegisterDevToolsOptions {
|
|
722
816
|
/**
|
|
723
817
|
* The port where the OpenAPI server is running
|
|
724
|
-
* @default
|
|
818
|
+
* @default 4000
|
|
725
819
|
*/
|
|
726
820
|
port?: number;
|
|
727
821
|
/**
|
|
@@ -763,7 +857,7 @@ interface RegisterDevToolsOptions {
|
|
|
763
857
|
*
|
|
764
858
|
* // Register OpenAPI Server DevTools
|
|
765
859
|
* if (import.meta.env.DEV) {
|
|
766
|
-
* await registerDevTools(app
|
|
860
|
+
* await registerDevTools(app);
|
|
767
861
|
* }
|
|
768
862
|
*
|
|
769
863
|
* app.mount('#app');
|
|
@@ -779,11 +873,11 @@ declare function registerDevTools(app: App, options?: RegisterDevToolsOptions):
|
|
|
779
873
|
* When running in a browser, protocol and host are automatically derived from
|
|
780
874
|
* window.location if not explicitly provided.
|
|
781
875
|
*
|
|
782
|
-
* @param port - Server port (default:
|
|
876
|
+
* @param port - Server port (default: 4000, matching OpenApiServerOptions.port)
|
|
783
877
|
* @param host - Server host (default: 'localhost' or window.location.hostname)
|
|
784
878
|
* @param protocol - Protocol to use (default: 'http' or window.location.protocol)
|
|
785
879
|
* @returns DevTools SPA URL
|
|
786
880
|
*/
|
|
787
881
|
declare function getDevToolsUrl(port?: number, host?: string, protocol?: 'http' | 'https'): string;
|
|
788
882
|
|
|
789
|
-
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, createFileWatcher, createOrchestrator, debounce, deriveProxyPath, deriveSpecId, getDevToolsUrl, getHandlerFiles, getSeedFiles, loadHandlers, loadSeeds, normalizeProxyPath, openApiServer, registerDevTools, resolveOptions, slugify, validateSpecs, validateUniqueIds, validateUniqueProxyPaths };
|
|
883
|
+
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 };
|