@stackwright-pro/openapi 0.2.2-alpha.3 → 0.3.0-alpha.11

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.mts CHANGED
@@ -1,95 +1,14 @@
1
1
  import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
2
2
  import { z, ZodSchema } from 'zod';
3
+ import { ActionConfig, EndpointFilter as EndpointFilter$1, PrebuildSecurityConfig, ValidationResult } from '@stackwright-pro/types';
4
+ export { ActionConfig, ApprovedSpec, OpenAPIConfig, PrebuildSecurityConfig, SiteConfig, ValidationResult } from '@stackwright-pro/types';
3
5
 
4
6
  /**
5
7
  * Supported OpenAPI versions
6
8
  */
7
9
  type OpenAPIDocument = OpenAPIV3.Document | OpenAPIV3_1.Document;
8
10
  /**
9
- * An approved API specification.
10
- * Used by enterprise customers to whitelist specific OpenAPI specs.
11
- */
12
- interface ApprovedSpec {
13
- /** Human-readable name for the spec */
14
- name: string;
15
- /** URL or file path to the approved spec */
16
- url: string;
17
- /** Expected SHA-256 hash of the spec content */
18
- sha256: string;
19
- }
20
- /**
21
- * Security configuration for approved specs enforcement.
22
- * Configured in stackwright.yml under `prebuild.security`.
23
- */
24
- interface PrebuildSecurityConfig {
25
- /** Enable approved-specs enforcement */
26
- enabled: boolean;
27
- /** List of approved specifications */
28
- allowlist: ApprovedSpec[];
29
- }
30
- /**
31
- * Result of validating a spec against the approved list.
32
- */
33
- interface ValidationResult {
34
- /** Whether the spec is approved */
35
- valid: boolean;
36
- /** Error code if not valid */
37
- errorCode?: 'SPEC_NOT_ON_ALLOWLIST' | 'SPEC_MODIFIED' | 'DOWNLOAD_FAILED';
38
- /** Human-readable error message */
39
- error?: string;
40
- /** URL of the spec that was validated */
41
- specUrl?: string;
42
- }
43
- /**
44
- * Extended site config with prebuild security.
45
- * Users can add this to stackwright.yml.
46
- */
47
- interface SiteConfig {
48
- /** Prebuild configuration */
49
- prebuild?: {
50
- /** Security settings for approved-specs enforcement */
51
- security?: PrebuildSecurityConfig;
52
- };
53
- }
54
- /**
55
- * Endpoint filter configuration
56
- */
57
- interface EndpointFilter$1 {
58
- /** Endpoints/patterns to include (default: all) */
59
- include?: string[];
60
- /** Endpoints/patterns to exclude */
61
- exclude?: string[];
62
- }
63
- /**
64
- * Configuration for OpenAPI integration in stackwright.yml
65
- */
66
- interface OpenAPIConfig {
67
- /** Name of this integration */
68
- name: string;
69
- /** OpenAPI spec (URL or local file path) */
70
- spec: string;
71
- /** Mock server URL for development (e.g., http://localhost:4010) */
72
- mockUrl?: string;
73
- /** Authentication configuration */
74
- auth?: {
75
- type: 'bearer' | 'apiKey' | 'oauth2';
76
- token?: string;
77
- apiKey?: string;
78
- };
79
- /** Collections to generate from endpoints */
80
- collections?: Array<{
81
- /** API endpoint path */
82
- endpoint: string;
83
- /** Field to use as slug/ID */
84
- slug_field: string;
85
- /** Optional filters */
86
- filters?: Record<string, unknown>;
87
- }>;
88
- /** Endpoint filter - only generate code for matching endpoints */
89
- endpoints?: EndpointFilter$1;
90
- }
91
- /**
92
- * Result of OpenAPI compilation
11
+ * Result of OpenAPI compilation (internal — not a public contract)
93
12
  */
94
13
  interface OpenAPICompilationResult {
95
14
  /** Generated Zod schemas as code */
@@ -100,6 +19,8 @@ interface OpenAPICompilationResult {
100
19
  provider: string;
101
20
  /** Generated API client */
102
21
  client: string;
22
+ /** Generated CollectionAction implementations */
23
+ actions: string;
103
24
  }
104
25
 
105
26
  interface ParseOptions {
@@ -164,16 +85,38 @@ type SchemaObject$1 = OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject;
164
85
  */
165
86
  declare class SchemaResolver {
166
87
  private document;
88
+ /**
89
+ * @param document - Fully dereferenced OpenAPI document. Pass the result of
90
+ * SwaggerParser.dereference() or OpenAPIParser.parse(). Passing a document
91
+ * with unresolved $ref objects will produce console warnings and undefined
92
+ * returns from schema extraction methods.
93
+ */
167
94
  constructor(document: OpenAPIV3.Document | OpenAPIV3_1.Document);
168
95
  /**
169
- * Get schema for a specific path and method
96
+ * Get schema for a specific path and method.
97
+ *
98
+ * Tries `preferredResponseCode` first (default `'200'`). If that code is
99
+ * absent or has no JSON schema, falls back through other 2xx codes in
100
+ * priority order so that REST-correct `201 Created` responses are resolved
101
+ * automatically.
170
102
  *
171
103
  * @param path - API path (e.g., '/equipment')
172
104
  * @param method - HTTP method (e.g., 'get')
173
- * @param responseCode - Response code (default: '200')
105
+ * @param preferredResponseCode - Response code to try first (default: '200')
106
+ * @returns Schema object or undefined
107
+ */
108
+ getResponseSchema(path: string, method: string, preferredResponseCode?: string): SchemaObject$1 | undefined;
109
+ /**
110
+ * Get the request body schema for a specific path and method.
111
+ *
112
+ * Extracts the application/json schema from the operation's requestBody.
113
+ * Returns undefined if the operation has no requestBody or no JSON content.
114
+ *
115
+ * @param path - API path (e.g., '/supplies/request')
116
+ * @param method - HTTP method (e.g., 'post')
174
117
  * @returns Schema object or undefined
175
118
  */
176
- getResponseSchema(path: string, method: string, responseCode?: string): SchemaObject$1 | undefined;
119
+ getRequestBodySchema(path: string, method: string): SchemaObject$1 | undefined;
177
120
  /**
178
121
  * Get all schemas defined in components
179
122
  */
@@ -377,6 +320,55 @@ declare class CollectionProviderGenerator {
377
320
  private guessTitle;
378
321
  }
379
322
 
323
+ /**
324
+ * ActionGenerator
325
+ *
326
+ * Generates typed CollectionAction implementations from OpenAPI action configs.
327
+ * Each configured action endpoint becomes a named export satisfying the
328
+ * CollectionAction<TInput, TOutput> interface from @stackwright-pro/workflow.
329
+ *
330
+ * The generated actions.ts is the bridge between:
331
+ * - stackwright.yml actions: config (what to generate)
332
+ * - workflow YAML service: refs (how it's addressed at runtime)
333
+ * - useWorkflow actions registry (where it executes)
334
+ *
335
+ * IoC note: This generator emits `import type { CollectionAction } from
336
+ * '@stackwright-pro/workflow'` as a string. The generator package itself has
337
+ * no dependency on @stackwright-pro/workflow — only the generated files do.
338
+ */
339
+ declare class ActionGenerator {
340
+ private document;
341
+ private resolver;
342
+ private zodGenerator;
343
+ constructor(document: OpenAPIDocument);
344
+ /**
345
+ * Generate the complete actions.ts file content.
346
+ *
347
+ * @param actions - Action configs from stackwright.yml
348
+ * @param integrationName - Used in the file header comment
349
+ * @param clientClassName - Name of the generated API client class to import
350
+ * @returns Complete TypeScript source for actions.ts
351
+ */
352
+ generate(actions: ActionConfig[], integrationName: string, clientClassName: string): string;
353
+ private processAction;
354
+ private generateHeader;
355
+ private generateImports;
356
+ private generateInlineSchemas;
357
+ private generateActionExports;
358
+ private generateRegistry;
359
+ private generateEmptyFile;
360
+ /** Derives the client method name from endpoint + method.
361
+ * Prefers operationId (matching ClientGenerator.getMethodName()), falls back
362
+ * to path+method derivation for specs that omit operationIds. */
363
+ private endpointToClientMethod;
364
+ /** Convert any string to camelCase — handles operationId values like
365
+ * createOrder, list_items, get-by-id, etc. */
366
+ private camelCase;
367
+ private toCamelCase;
368
+ private toPascalCase;
369
+ private capitalize;
370
+ }
371
+
380
372
  /**
381
373
  * Mapping of operationId to schema names
382
374
  */
@@ -423,6 +415,7 @@ declare class ClientGenerator {
423
415
  private schemaMapping?;
424
416
  private requiredSchemas;
425
417
  private generatedRequestSchemas;
418
+ private generatedRequestTypes;
426
419
  constructor(document: OpenAPIDocument, schemaMapping?: SchemaMapping);
427
420
  /**
428
421
  * Generate typed API client code from OpenAPI document
@@ -685,6 +678,7 @@ declare class OpenAPIPlugin implements PrebuildPlugin {
685
678
  private generateSchemas;
686
679
  private generateTypes;
687
680
  private generateProvider;
681
+ private generateActions;
688
682
  private generateClient;
689
683
  private extractComponentName;
690
684
  private getOperationTypeName;
@@ -954,4 +948,4 @@ declare class ApprovedSpecsValidator {
954
948
  clearCache(): void;
955
949
  }
956
950
 
957
- export { type ApprovedSpec, ApprovedSpecsValidator, type ClientGenerationOptions, ClientGenerator, type CollectionConfig, CollectionProviderGenerator, EndpointFilter, type OpenAPICompilationResult, type OpenAPIConfig, type OpenAPIDocument, OpenAPIParser, OpenAPIPlugin, type OpenAPISourceConfig, type ParseOptions, type ParseResult, type PrebuildSecurityConfig, type ProviderGenerationOptions, type SchemaMapping, SchemaResolver, type SiteConfig, type TypeGenerationOptions, TypeGenerator, type ValidationResult, type ZodGenerationOptions, ZodSchemaGenerator, createOpenAPIFetcher, createOpenAPIPlugin, isUrlSafe, validateUrlSafe };
951
+ export { ActionGenerator, ApprovedSpecsValidator, type ClientGenerationOptions, ClientGenerator, type CollectionConfig, CollectionProviderGenerator, EndpointFilter, type OpenAPICompilationResult, type OpenAPIDocument, OpenAPIParser, OpenAPIPlugin, type OpenAPISourceConfig, type ParseOptions, type ParseResult, type ProviderGenerationOptions, type SchemaMapping, SchemaResolver, type TypeGenerationOptions, TypeGenerator, type ZodGenerationOptions, ZodSchemaGenerator, createOpenAPIFetcher, createOpenAPIPlugin, isUrlSafe, validateUrlSafe };
package/dist/index.d.ts CHANGED
@@ -1,95 +1,14 @@
1
1
  import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
2
2
  import { z, ZodSchema } from 'zod';
3
+ import { ActionConfig, EndpointFilter as EndpointFilter$1, PrebuildSecurityConfig, ValidationResult } from '@stackwright-pro/types';
4
+ export { ActionConfig, ApprovedSpec, OpenAPIConfig, PrebuildSecurityConfig, SiteConfig, ValidationResult } from '@stackwright-pro/types';
3
5
 
4
6
  /**
5
7
  * Supported OpenAPI versions
6
8
  */
7
9
  type OpenAPIDocument = OpenAPIV3.Document | OpenAPIV3_1.Document;
8
10
  /**
9
- * An approved API specification.
10
- * Used by enterprise customers to whitelist specific OpenAPI specs.
11
- */
12
- interface ApprovedSpec {
13
- /** Human-readable name for the spec */
14
- name: string;
15
- /** URL or file path to the approved spec */
16
- url: string;
17
- /** Expected SHA-256 hash of the spec content */
18
- sha256: string;
19
- }
20
- /**
21
- * Security configuration for approved specs enforcement.
22
- * Configured in stackwright.yml under `prebuild.security`.
23
- */
24
- interface PrebuildSecurityConfig {
25
- /** Enable approved-specs enforcement */
26
- enabled: boolean;
27
- /** List of approved specifications */
28
- allowlist: ApprovedSpec[];
29
- }
30
- /**
31
- * Result of validating a spec against the approved list.
32
- */
33
- interface ValidationResult {
34
- /** Whether the spec is approved */
35
- valid: boolean;
36
- /** Error code if not valid */
37
- errorCode?: 'SPEC_NOT_ON_ALLOWLIST' | 'SPEC_MODIFIED' | 'DOWNLOAD_FAILED';
38
- /** Human-readable error message */
39
- error?: string;
40
- /** URL of the spec that was validated */
41
- specUrl?: string;
42
- }
43
- /**
44
- * Extended site config with prebuild security.
45
- * Users can add this to stackwright.yml.
46
- */
47
- interface SiteConfig {
48
- /** Prebuild configuration */
49
- prebuild?: {
50
- /** Security settings for approved-specs enforcement */
51
- security?: PrebuildSecurityConfig;
52
- };
53
- }
54
- /**
55
- * Endpoint filter configuration
56
- */
57
- interface EndpointFilter$1 {
58
- /** Endpoints/patterns to include (default: all) */
59
- include?: string[];
60
- /** Endpoints/patterns to exclude */
61
- exclude?: string[];
62
- }
63
- /**
64
- * Configuration for OpenAPI integration in stackwright.yml
65
- */
66
- interface OpenAPIConfig {
67
- /** Name of this integration */
68
- name: string;
69
- /** OpenAPI spec (URL or local file path) */
70
- spec: string;
71
- /** Mock server URL for development (e.g., http://localhost:4010) */
72
- mockUrl?: string;
73
- /** Authentication configuration */
74
- auth?: {
75
- type: 'bearer' | 'apiKey' | 'oauth2';
76
- token?: string;
77
- apiKey?: string;
78
- };
79
- /** Collections to generate from endpoints */
80
- collections?: Array<{
81
- /** API endpoint path */
82
- endpoint: string;
83
- /** Field to use as slug/ID */
84
- slug_field: string;
85
- /** Optional filters */
86
- filters?: Record<string, unknown>;
87
- }>;
88
- /** Endpoint filter - only generate code for matching endpoints */
89
- endpoints?: EndpointFilter$1;
90
- }
91
- /**
92
- * Result of OpenAPI compilation
11
+ * Result of OpenAPI compilation (internal — not a public contract)
93
12
  */
94
13
  interface OpenAPICompilationResult {
95
14
  /** Generated Zod schemas as code */
@@ -100,6 +19,8 @@ interface OpenAPICompilationResult {
100
19
  provider: string;
101
20
  /** Generated API client */
102
21
  client: string;
22
+ /** Generated CollectionAction implementations */
23
+ actions: string;
103
24
  }
104
25
 
105
26
  interface ParseOptions {
@@ -164,16 +85,38 @@ type SchemaObject$1 = OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject;
164
85
  */
165
86
  declare class SchemaResolver {
166
87
  private document;
88
+ /**
89
+ * @param document - Fully dereferenced OpenAPI document. Pass the result of
90
+ * SwaggerParser.dereference() or OpenAPIParser.parse(). Passing a document
91
+ * with unresolved $ref objects will produce console warnings and undefined
92
+ * returns from schema extraction methods.
93
+ */
167
94
  constructor(document: OpenAPIV3.Document | OpenAPIV3_1.Document);
168
95
  /**
169
- * Get schema for a specific path and method
96
+ * Get schema for a specific path and method.
97
+ *
98
+ * Tries `preferredResponseCode` first (default `'200'`). If that code is
99
+ * absent or has no JSON schema, falls back through other 2xx codes in
100
+ * priority order so that REST-correct `201 Created` responses are resolved
101
+ * automatically.
170
102
  *
171
103
  * @param path - API path (e.g., '/equipment')
172
104
  * @param method - HTTP method (e.g., 'get')
173
- * @param responseCode - Response code (default: '200')
105
+ * @param preferredResponseCode - Response code to try first (default: '200')
106
+ * @returns Schema object or undefined
107
+ */
108
+ getResponseSchema(path: string, method: string, preferredResponseCode?: string): SchemaObject$1 | undefined;
109
+ /**
110
+ * Get the request body schema for a specific path and method.
111
+ *
112
+ * Extracts the application/json schema from the operation's requestBody.
113
+ * Returns undefined if the operation has no requestBody or no JSON content.
114
+ *
115
+ * @param path - API path (e.g., '/supplies/request')
116
+ * @param method - HTTP method (e.g., 'post')
174
117
  * @returns Schema object or undefined
175
118
  */
176
- getResponseSchema(path: string, method: string, responseCode?: string): SchemaObject$1 | undefined;
119
+ getRequestBodySchema(path: string, method: string): SchemaObject$1 | undefined;
177
120
  /**
178
121
  * Get all schemas defined in components
179
122
  */
@@ -377,6 +320,55 @@ declare class CollectionProviderGenerator {
377
320
  private guessTitle;
378
321
  }
379
322
 
323
+ /**
324
+ * ActionGenerator
325
+ *
326
+ * Generates typed CollectionAction implementations from OpenAPI action configs.
327
+ * Each configured action endpoint becomes a named export satisfying the
328
+ * CollectionAction<TInput, TOutput> interface from @stackwright-pro/workflow.
329
+ *
330
+ * The generated actions.ts is the bridge between:
331
+ * - stackwright.yml actions: config (what to generate)
332
+ * - workflow YAML service: refs (how it's addressed at runtime)
333
+ * - useWorkflow actions registry (where it executes)
334
+ *
335
+ * IoC note: This generator emits `import type { CollectionAction } from
336
+ * '@stackwright-pro/workflow'` as a string. The generator package itself has
337
+ * no dependency on @stackwright-pro/workflow — only the generated files do.
338
+ */
339
+ declare class ActionGenerator {
340
+ private document;
341
+ private resolver;
342
+ private zodGenerator;
343
+ constructor(document: OpenAPIDocument);
344
+ /**
345
+ * Generate the complete actions.ts file content.
346
+ *
347
+ * @param actions - Action configs from stackwright.yml
348
+ * @param integrationName - Used in the file header comment
349
+ * @param clientClassName - Name of the generated API client class to import
350
+ * @returns Complete TypeScript source for actions.ts
351
+ */
352
+ generate(actions: ActionConfig[], integrationName: string, clientClassName: string): string;
353
+ private processAction;
354
+ private generateHeader;
355
+ private generateImports;
356
+ private generateInlineSchemas;
357
+ private generateActionExports;
358
+ private generateRegistry;
359
+ private generateEmptyFile;
360
+ /** Derives the client method name from endpoint + method.
361
+ * Prefers operationId (matching ClientGenerator.getMethodName()), falls back
362
+ * to path+method derivation for specs that omit operationIds. */
363
+ private endpointToClientMethod;
364
+ /** Convert any string to camelCase — handles operationId values like
365
+ * createOrder, list_items, get-by-id, etc. */
366
+ private camelCase;
367
+ private toCamelCase;
368
+ private toPascalCase;
369
+ private capitalize;
370
+ }
371
+
380
372
  /**
381
373
  * Mapping of operationId to schema names
382
374
  */
@@ -423,6 +415,7 @@ declare class ClientGenerator {
423
415
  private schemaMapping?;
424
416
  private requiredSchemas;
425
417
  private generatedRequestSchemas;
418
+ private generatedRequestTypes;
426
419
  constructor(document: OpenAPIDocument, schemaMapping?: SchemaMapping);
427
420
  /**
428
421
  * Generate typed API client code from OpenAPI document
@@ -685,6 +678,7 @@ declare class OpenAPIPlugin implements PrebuildPlugin {
685
678
  private generateSchemas;
686
679
  private generateTypes;
687
680
  private generateProvider;
681
+ private generateActions;
688
682
  private generateClient;
689
683
  private extractComponentName;
690
684
  private getOperationTypeName;
@@ -954,4 +948,4 @@ declare class ApprovedSpecsValidator {
954
948
  clearCache(): void;
955
949
  }
956
950
 
957
- export { type ApprovedSpec, ApprovedSpecsValidator, type ClientGenerationOptions, ClientGenerator, type CollectionConfig, CollectionProviderGenerator, EndpointFilter, type OpenAPICompilationResult, type OpenAPIConfig, type OpenAPIDocument, OpenAPIParser, OpenAPIPlugin, type OpenAPISourceConfig, type ParseOptions, type ParseResult, type PrebuildSecurityConfig, type ProviderGenerationOptions, type SchemaMapping, SchemaResolver, type SiteConfig, type TypeGenerationOptions, TypeGenerator, type ValidationResult, type ZodGenerationOptions, ZodSchemaGenerator, createOpenAPIFetcher, createOpenAPIPlugin, isUrlSafe, validateUrlSafe };
951
+ export { ActionGenerator, ApprovedSpecsValidator, type ClientGenerationOptions, ClientGenerator, type CollectionConfig, CollectionProviderGenerator, EndpointFilter, type OpenAPICompilationResult, type OpenAPIDocument, OpenAPIParser, OpenAPIPlugin, type OpenAPISourceConfig, type ParseOptions, type ParseResult, type ProviderGenerationOptions, type SchemaMapping, SchemaResolver, type TypeGenerationOptions, TypeGenerator, type ZodGenerationOptions, ZodSchemaGenerator, createOpenAPIFetcher, createOpenAPIPlugin, isUrlSafe, validateUrlSafe };