openapi-sync 2.1.9 → 2.1.10
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/README.md +146 -16
- package/db.json +1 -1
- package/dist/Openapi-sync/index.js +106 -20
- package/dist/index.js +0 -2
- package/dist/openapi.sync.sample.js +34 -0
- package/dist/types.d.ts +20 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
### 🔧 **Highly Configurable**
|
|
36
36
|
|
|
37
37
|
- Customizable naming conventions for types and endpoints
|
|
38
|
+
- Exclude/include endpoints by exact path or regex patterns
|
|
39
|
+
- Tag-based filtering, method-specific filtering, and pattern matching
|
|
38
40
|
- Flexible output directory structure
|
|
39
41
|
- URL transformation and text replacement rules
|
|
40
42
|
- Configurable documentation generation
|
|
@@ -201,6 +203,34 @@ const config: IConfig = {
|
|
|
201
203
|
disable: false,
|
|
202
204
|
showCurl: true, // Include cURL examples in documentation
|
|
203
205
|
},
|
|
206
|
+
exclude: {
|
|
207
|
+
// Exclude endpoints by tags
|
|
208
|
+
tags: ["deprecated", "internal"],
|
|
209
|
+
// Exclude individual endpoints by path and method
|
|
210
|
+
endpoints: [
|
|
211
|
+
// Exact path match
|
|
212
|
+
{ path: "/admin/users", method: "DELETE" },
|
|
213
|
+
// Regex pattern match
|
|
214
|
+
{ regex: "^/internal/.*", method: "GET" },
|
|
215
|
+
{ regex: ".*/debug$", method: "GET" },
|
|
216
|
+
// Don't specify method to exclude all methods
|
|
217
|
+
{ path: "/debug/logs" },
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
include: {
|
|
221
|
+
// Include endpoints by tags
|
|
222
|
+
tags: ["public"],
|
|
223
|
+
// Include individual endpoints by path and method
|
|
224
|
+
endpoints: [
|
|
225
|
+
// Exact path match
|
|
226
|
+
{ path: "/public/users", method: "GET" },
|
|
227
|
+
// Regex pattern match
|
|
228
|
+
{ regex: "^/public/.*", method: "GET" },
|
|
229
|
+
{ regex: ".*/logs$", method: "GET" },
|
|
230
|
+
// Don't specify method to include all methods
|
|
231
|
+
{ path: "/public/logs" },
|
|
232
|
+
],
|
|
233
|
+
},
|
|
204
234
|
},
|
|
205
235
|
};
|
|
206
236
|
|
|
@@ -220,24 +250,39 @@ export default config;
|
|
|
220
250
|
|
|
221
251
|
#### Type Configuration (`types`)
|
|
222
252
|
|
|
223
|
-
| Property
|
|
224
|
-
|
|
|
225
|
-
| `name.prefix`
|
|
226
|
-
| `name.
|
|
227
|
-
| `
|
|
253
|
+
| Property | Type | Description |
|
|
254
|
+
| --------------------- | ---------- | ------------------------------------------------------- |
|
|
255
|
+
| `name.prefix` | `string` | Prefix for generated type names |
|
|
256
|
+
| `name.useOperationId` | `boolean` | Use OpenAPI operationId for type naming when available |
|
|
257
|
+
| `name.format` | `function` | Custom naming function with source context and metadata |
|
|
258
|
+
| `doc.disable` | `boolean` | Disable JSDoc generation for types |
|
|
259
|
+
|
|
260
|
+
**OperationId-based Type Naming:**
|
|
261
|
+
|
|
262
|
+
When `useOperationId` is set to `true`, the system will use the OpenAPI `operationId` for type naming:
|
|
263
|
+
|
|
264
|
+
- **Query Types**: `{operationId}Query` (e.g., `getUserByIdQuery`)
|
|
265
|
+
- **DTO Types**: `{operationId}DTO` (e.g., `createUserDTO`)
|
|
266
|
+
- **Response Types**: `{operationId}{code}Response` (e.g., `getUserById200Response`)
|
|
267
|
+
|
|
268
|
+
If `operationId` is not available, the system falls back to the default path-based naming convention.
|
|
228
269
|
|
|
229
270
|
#### Endpoint Configuration (`endpoints`)
|
|
230
271
|
|
|
231
|
-
| Property | Type
|
|
232
|
-
| --------------------- |
|
|
233
|
-
| `value.replaceWords` | `IConfigReplaceWord[]`
|
|
234
|
-
| `value.includeServer` | `boolean`
|
|
235
|
-
| `value.type` | `"string" \| "object"`
|
|
236
|
-
| `name.prefix` | `string`
|
|
237
|
-
| `name.useOperationId` | `boolean`
|
|
238
|
-
| `name.format` | `function`
|
|
239
|
-
| `doc.disable` | `boolean`
|
|
240
|
-
| `doc.showCurl` | `boolean`
|
|
272
|
+
| Property | Type | Description |
|
|
273
|
+
| --------------------- | --------------------------------------------------------- | --------------------------------------------------------- |
|
|
274
|
+
| `value.replaceWords` | `IConfigReplaceWord[]` | URL transformation rules |
|
|
275
|
+
| `value.includeServer` | `boolean` | Include server URL in endpoints |
|
|
276
|
+
| `value.type` | `"string" \| "object"` | Output format for endpoints |
|
|
277
|
+
| `name.prefix` | `string` | Prefix for endpoint names |
|
|
278
|
+
| `name.useOperationId` | `boolean` | Use OpenAPI operationId for naming |
|
|
279
|
+
| `name.format` | `function` | Custom naming function for endpoints |
|
|
280
|
+
| `doc.disable` | `boolean` | Disable JSDoc generation for endpoints |
|
|
281
|
+
| `doc.showCurl` | `boolean` | Include cURL examples in documentation |
|
|
282
|
+
| `exclude.tags` | `string[]` | Exclude endpoints by tags |
|
|
283
|
+
| `exclude.endpoints` | `Array<{path?: string, regex?: string, method?: Method}>` | Exclude specific endpoints by exact path or regex pattern |
|
|
284
|
+
| `include.tags` | `string[]` | Include endpoints by tags |
|
|
285
|
+
| `include.endpoints` | `Array<{path?: string, regex?: string, method?: Method}>` | Include specific endpoints by exact path or regex pattern |
|
|
241
286
|
|
|
242
287
|
## Usage
|
|
243
288
|
|
|
@@ -512,6 +557,9 @@ import {
|
|
|
512
557
|
IOpenApiSpec,
|
|
513
558
|
IOpenApSchemaSpec,
|
|
514
559
|
IConfigReplaceWord,
|
|
560
|
+
IConfigExclude,
|
|
561
|
+
IConfigInclude,
|
|
562
|
+
IConfigDoc,
|
|
515
563
|
} from "openapi-sync/types";
|
|
516
564
|
```
|
|
517
565
|
|
|
@@ -570,17 +618,33 @@ export default getConfig;
|
|
|
570
618
|
### Custom Type Formatting
|
|
571
619
|
|
|
572
620
|
```typescript
|
|
573
|
-
// Advanced type name formatting
|
|
621
|
+
// Advanced type name formatting with operationId support
|
|
574
622
|
const config: IConfig = {
|
|
575
623
|
// ... other config
|
|
576
624
|
types: {
|
|
577
625
|
name: {
|
|
578
626
|
prefix: "",
|
|
627
|
+
useOperationId: true, // Use operationId when available
|
|
579
628
|
format: (source, data, defaultName) => {
|
|
580
629
|
if (source === "shared") {
|
|
581
630
|
// Shared types: UserProfile, OrderStatus, etc.
|
|
582
631
|
return `${data.name}`;
|
|
583
632
|
} else if (source === "endpoint") {
|
|
633
|
+
// Use operationId if available and configured
|
|
634
|
+
if (data.operationId) {
|
|
635
|
+
switch (data.type) {
|
|
636
|
+
case "query":
|
|
637
|
+
return `${data.operationId}Query`;
|
|
638
|
+
case "dto":
|
|
639
|
+
return `${data.operationId}DTO`;
|
|
640
|
+
case "response":
|
|
641
|
+
return `${data.operationId}${data.code}Response`;
|
|
642
|
+
default:
|
|
643
|
+
return defaultName;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// Fallback to path-based naming
|
|
584
648
|
const method = data.method?.toUpperCase();
|
|
585
649
|
const cleanPath = data.path
|
|
586
650
|
?.replace(/[{}\/]/g, "_")
|
|
@@ -604,6 +668,72 @@ const config: IConfig = {
|
|
|
604
668
|
};
|
|
605
669
|
```
|
|
606
670
|
|
|
671
|
+
### Endpoint Filtering and Selection
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
// Advanced endpoint filtering configuration
|
|
675
|
+
const config: IConfig = {
|
|
676
|
+
// ... other config
|
|
677
|
+
endpoints: {
|
|
678
|
+
// ... other endpoint config
|
|
679
|
+
exclude: {
|
|
680
|
+
// Exclude endpoints by tags
|
|
681
|
+
tags: ["deprecated", "internal", "admin"],
|
|
682
|
+
// Exclude specific endpoints by exact path or regex pattern
|
|
683
|
+
endpoints: [
|
|
684
|
+
// Exact path matches
|
|
685
|
+
{ path: "/admin/users", method: "DELETE" },
|
|
686
|
+
{ path: "/admin/settings", method: "PUT" },
|
|
687
|
+
// Regex pattern matches
|
|
688
|
+
{ regex: "^/internal/.*", method: "GET" },
|
|
689
|
+
{ regex: ".*/debug$", method: "POST" },
|
|
690
|
+
// Exclude all methods for a specific path
|
|
691
|
+
{ path: "/debug/logs" },
|
|
692
|
+
],
|
|
693
|
+
},
|
|
694
|
+
include: {
|
|
695
|
+
// Include only public endpoints
|
|
696
|
+
tags: ["public", "user"],
|
|
697
|
+
// Include specific endpoints by exact path or regex pattern
|
|
698
|
+
endpoints: [
|
|
699
|
+
// Exact path matches
|
|
700
|
+
{ path: "/public/users", method: "GET" },
|
|
701
|
+
{ path: "/public/profile", method: "PUT" },
|
|
702
|
+
// Regex pattern matches
|
|
703
|
+
{ regex: "^/public/.*", method: "GET" },
|
|
704
|
+
{ regex: ".*/health$", method: "GET" },
|
|
705
|
+
],
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
### Path vs Regex Filtering
|
|
712
|
+
|
|
713
|
+
```typescript
|
|
714
|
+
// Demonstrating the difference between path and regex filtering
|
|
715
|
+
const config: IConfig = {
|
|
716
|
+
// ... other config
|
|
717
|
+
endpoints: {
|
|
718
|
+
exclude: {
|
|
719
|
+
endpoints: [
|
|
720
|
+
// Exact path match - only excludes exactly "/api/users"
|
|
721
|
+
{ path: "/api/users", method: "GET" },
|
|
722
|
+
|
|
723
|
+
// Regex match - excludes all paths starting with "/api/users"
|
|
724
|
+
{ regex: "^/api/users.*", method: "GET" },
|
|
725
|
+
|
|
726
|
+
// Regex match - excludes all paths ending with "/debug"
|
|
727
|
+
{ regex: ".*/debug$", method: "GET" },
|
|
728
|
+
|
|
729
|
+
// Regex match - excludes paths with specific pattern
|
|
730
|
+
{ regex: "^/internal/.*/admin$", method: "POST" },
|
|
731
|
+
],
|
|
732
|
+
},
|
|
733
|
+
},
|
|
734
|
+
};
|
|
735
|
+
```
|
|
736
|
+
|
|
607
737
|
### URL Transformation Rules
|
|
608
738
|
|
|
609
739
|
```typescript
|