openapi-sync 2.1.16 → 3.0.0

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 CHANGED
@@ -12,6 +12,7 @@
12
12
  - [Configuration](#configuration)
13
13
  - [Usage](#usage)
14
14
  - [Generated Output](#generated-output)
15
+ - [Custom Code Injection](#custom-code-injection)
15
16
  - [API Reference](#api-reference)
16
17
  - [Advanced Examples](#advanced-examples)
17
18
  - [Troubleshooting](#troubleshooting)
@@ -44,6 +45,7 @@
44
45
  - URL transformation and text replacement rules
45
46
  - Configurable documentation generation
46
47
  - Support for multiple API specifications
48
+ - Custom code injection, preserve your custom code between regenerations
47
49
 
48
50
  ### 🛡️ **Enterprise Ready**
49
51
 
@@ -606,6 +608,250 @@ export type IPet = {
606
608
  };
607
609
  ```
608
610
 
611
+ ## Custom Code Injection
612
+
613
+ OpenAPI Sync supports preserving custom code between regenerations using special comment markers. This allows you to add your own custom endpoints, types, or utility functions that will survive when the generated code is updated.
614
+
615
+ ### How It Works
616
+
617
+ Custom code is preserved using special comment markers in the generated files. Any code you add between these markers will be preserved when the files are regenerated.
618
+
619
+ ### Configuration
620
+
621
+ Add the `customCode` configuration to your `openapi.sync.ts` file:
622
+
623
+ ```typescript
624
+ import { IConfig } from "openapi-sync/types";
625
+
626
+ export default {
627
+ refetchInterval: 5000,
628
+ folder: "./src/api",
629
+ api: {
630
+ petstore: "https://petstore3.swagger.io/api/v3/openapi.json",
631
+ },
632
+ customCode: {
633
+ enabled: true, // Enable custom code preservation (default: true)
634
+ position: "bottom", // Position of custom code: "top", "bottom", or "both"
635
+ markerText: "CUSTOM CODE", // Custom marker text (default: "CUSTOM CODE")
636
+ includeInstructions: true, // Include helpful instructions (default: true)
637
+ },
638
+ } as IConfig;
639
+ ```
640
+
641
+ ### Configuration Options
642
+
643
+ | Option | Type | Default | Description |
644
+ | --------------------- | ----------------------------- | --------------- | ------------------------------------------ |
645
+ | `enabled` | `boolean` | `true` | Enable or disable custom code preservation |
646
+ | `position` | `"top" \| "bottom" \| "both"` | `"bottom"` | Where to place custom code markers |
647
+ | `markerText` | `string` | `"CUSTOM CODE"` | Custom text for markers |
648
+ | `includeInstructions` | `boolean` | `true` | Include helpful instructions in markers |
649
+
650
+ ### Usage Example
651
+
652
+ After running OpenAPI Sync for the first time, your generated files will include custom code markers:
653
+
654
+ **endpoints.ts**
655
+
656
+ ```typescript
657
+ // AUTO-GENERATED FILE - DO NOT EDIT OUTSIDE CUSTOM CODE MARKERS
658
+ export const getPet = (petId: string) => `/pet/${petId}`;
659
+ export const createPet = "/pet";
660
+ export const updatePet = (petId: string) => `/pet/${petId}`;
661
+
662
+ // ============================================================
663
+ // 🔒 CUSTOM CODE START
664
+ // Add your custom code above this line
665
+ // This section will be preserved during regeneration
666
+ // ============================================================
667
+
668
+ // ============================================================
669
+ // 🔒 CUSTOM CODE END
670
+ // ============================================================
671
+ ```
672
+
673
+ ### Adding Custom Code
674
+
675
+ Simply add your custom code between the markers:
676
+
677
+ **endpoints.ts**
678
+
679
+ ```typescript
680
+ export const getPet = (petId: string) => `/pet/${petId}`;
681
+ export const createPet = "/pet";
682
+
683
+ // ============================================================
684
+ // 🔒 CUSTOM CODE START
685
+ // ============================================================
686
+
687
+ // Custom endpoints for legacy API
688
+ export const legacyGetPet = (petId: string) => `/api/v1/pet/${petId}`;
689
+ export const customSearch = "/api/search";
690
+
691
+ // Custom utility function
692
+ export const buildPetUrl = (petId: string, includePhotos: boolean) => {
693
+ const base = getPet(petId);
694
+ return includePhotos ? `${base}?include=photos` : base;
695
+ };
696
+
697
+ // ============================================================
698
+ // 🔒 CUSTOM CODE END
699
+ // ============================================================
700
+
701
+ export const updatePet = (petId: string) => `/pet/${petId}`;
702
+ ```
703
+
704
+ ### Custom Types
705
+
706
+ You can also add custom types in the `types.ts` and `shared.ts` files:
707
+
708
+ **types.ts**
709
+
710
+ ```typescript
711
+ import * as Shared from "./shared";
712
+
713
+ export type IGetPetByIdResponse = Shared.IPet;
714
+ export type ICreatePetDTO = {
715
+ name: string;
716
+ status?: "available" | "pending" | "sold";
717
+ };
718
+
719
+ // ============================================================
720
+ // 🔒 CUSTOM CODE START
721
+ // ============================================================
722
+
723
+ // Custom type extending generated types
724
+ export interface IPetWithMetadata extends Shared.IPet {
725
+ fetchedAt: Date;
726
+ cached: boolean;
727
+ }
728
+
729
+ // Custom utility type
730
+ export type PartialPet = Partial<Shared.IPet>;
731
+
732
+ // Custom enum
733
+ export enum PetStatus {
734
+ Available = "available",
735
+ Pending = "pending",
736
+ Sold = "sold",
737
+ }
738
+
739
+ // ============================================================
740
+ // 🔒 CUSTOM CODE END
741
+ // ============================================================
742
+ ```
743
+
744
+ ### Position Options
745
+
746
+ #### Bottom Position (Default)
747
+
748
+ Custom code markers appear at the bottom of the file:
749
+
750
+ ```typescript
751
+ // Generated code...
752
+ export const endpoint1 = "/api/v1";
753
+
754
+ // 🔒 CUSTOM CODE START
755
+ // Your custom code here
756
+ // 🔒 CUSTOM CODE END
757
+ ```
758
+
759
+ #### Top Position
760
+
761
+ Custom code markers appear at the top of the file:
762
+
763
+ ```typescript
764
+ // 🔒 CUSTOM CODE START
765
+ // Your custom code here
766
+ // 🔒 CUSTOM CODE END
767
+
768
+ // Generated code...
769
+ export const endpoint1 = "/api/v1";
770
+ ```
771
+
772
+ #### Both Positions
773
+
774
+ Custom code markers appear at both top and bottom:
775
+
776
+ ```typescript
777
+ // 🔒 CUSTOM CODE START (TOP)
778
+ // Top custom code
779
+ // 🔒 CUSTOM CODE END
780
+
781
+ // Generated code...
782
+
783
+ // 🔒 CUSTOM CODE START (BOTTOM)
784
+ // Bottom custom code
785
+ // 🔒 CUSTOM CODE END
786
+ ```
787
+
788
+ ### Best Practices
789
+
790
+ 1. **Don't Edit Outside Markers**: Only add code between the custom code markers. Code outside these markers will be overwritten.
791
+
792
+ 2. **Use Descriptive Names**: Use clear, descriptive names for your custom code to avoid conflicts with generated code.
793
+
794
+ 3. **Keep It Organized**: Group related custom code together and add comments explaining its purpose.
795
+
796
+ 4. **Test After Regeneration**: After regenerating, verify your custom code is still present and working correctly.
797
+
798
+ 5. **Version Control**: Commit your custom code changes separately from regeneration to track what's custom vs generated.
799
+
800
+ ### Use Cases
801
+
802
+ #### Legacy API Support
803
+
804
+ ```typescript
805
+ // 🔒 CUSTOM CODE START
806
+ // Support for legacy v1 API that's not in OpenAPI spec
807
+ export const legacyLogin = "/api/v1/auth/login";
808
+ export const legacyLogout = "/api/v1/auth/logout";
809
+ // 🔒 CUSTOM CODE END
810
+ ```
811
+
812
+ #### Custom Utilities
813
+
814
+ ```typescript
815
+ // 🔒 CUSTOM CODE START
816
+ // Utility functions for working with generated endpoints
817
+ export const isPublicEndpoint = (endpoint: string): boolean => {
818
+ return endpoint.startsWith("/public/");
819
+ };
820
+
821
+ export const requiresAuth = (endpoint: string): boolean => {
822
+ return !isPublicEndpoint(endpoint);
823
+ };
824
+ // 🔒 CUSTOM CODE END
825
+ ```
826
+
827
+ #### Type Extensions
828
+
829
+ ```typescript
830
+ // 🔒 CUSTOM CODE START
831
+ // Extended types with additional client-side fields
832
+ export interface IUserWithUI extends Shared.IUser {
833
+ isLoading?: boolean;
834
+ hasError?: boolean;
835
+ lastFetched?: Date;
836
+ }
837
+ // 🔒 CUSTOM CODE END
838
+ ```
839
+
840
+ ### Disabling Custom Code Preservation
841
+
842
+ If you want to disable custom code preservation (not recommended for most use cases):
843
+
844
+ ```typescript
845
+ export default {
846
+ // ... other config
847
+ customCode: {
848
+ enabled: false, // Disables custom code preservation
849
+ },
850
+ } as IConfig;
851
+ ```
852
+
853
+ ⚠️ **Warning**: When disabled, all files will be completely overwritten on each regeneration.
854
+
609
855
  ## API Reference
610
856
 
611
857
  ### Exported Functions
@@ -1157,28 +1403,6 @@ The tool maintains state in `db.json` to track changes:
1157
1403
 
1158
1404
  ## Changelog
1159
1405
 
1160
- ### v2.1.11 (Latest)
1161
-
1162
- - **NEW**: Folder splitting configuration for organized code generation
1163
- - `folderSplit.byTags` - Create folders based on endpoint tags
1164
- - `folderSplit.customFolder` - Custom function for folder structure logic
1165
- - Enhanced folder organization with priority-based assignment
1166
- - Improved code organization for large APIs
1167
-
1168
- ### v2.1.10
1169
-
1170
- - OperationId-based naming for types and endpoints
1171
- - `types.name.useOperationId` - Use OpenAPI operationId for type naming
1172
- - `endpoints.name.useOperationId` - Use operationId for endpoint naming
1173
- - Enhanced endpoint filtering capabilities
1174
- - Improved tag-based filtering
1175
- - Better regex pattern matching
1176
- - More flexible include/exclude rules
1177
- - Enhanced JSONStringify function with array serialization support
1178
- - Improved endpoint tags support in generated documentation
1179
-
1180
- ### Previous Versions
1181
-
1182
1406
  - v2.1.13: Fix dts type fixes and Clean up tsup build config and introduction of unit testing
1183
1407
  - v2.1.12: Add automatic sync support for function-based config, improved handling of missing OpenAPI urls
1184
1408
  - v2.1.11: Folder splitting configuration for organized code generation
package/dist/index.d.mts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { Method } from 'axios';
2
- export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson } from './helpers.mjs';
3
- export { variableName, variableNameChar } from './regex.mjs';
4
2
 
5
3
  type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
6
4
  type IOpenApSchemaSpec = {
@@ -86,6 +84,16 @@ type IConfigFolderSplit = {
86
84
  responses?: IOpenApiResponseSpec;
87
85
  }) => string | null;
88
86
  };
87
+ type IConfigCustomCode = {
88
+ /** Enable custom code preservation (default: true) */
89
+ enabled?: boolean;
90
+ /** Position of custom code block in generated files (default: "bottom") */
91
+ position?: "top" | "bottom" | "both";
92
+ /** Custom marker text to use for identifying custom code sections (default: "CUSTOM CODE") */
93
+ markerText?: string;
94
+ /** Add helpful instructions in markers (default: true) */
95
+ includeInstructions?: boolean;
96
+ };
89
97
  type IConfig = {
90
98
  refetchInterval?: number;
91
99
  folder?: string;
@@ -93,6 +101,8 @@ type IConfig = {
93
101
  server?: number | string;
94
102
  /** Configuration for splitting generated code into folders */
95
103
  folderSplit?: IConfigFolderSplit;
104
+ /** Configuration for preserving custom code between regenerations */
105
+ customCode?: IConfigCustomCode;
96
106
  /** Configuration for excluding endpoints from code generation */
97
107
  types?: {
98
108
  name?: {
@@ -151,8 +161,55 @@ type IOpenApiSecuritySchemes = {
151
161
  };
152
162
  };
153
163
 
164
+ declare const isJson: (value: any) => boolean;
165
+ declare const isYamlString: (fileContent: string) => boolean;
166
+ declare const yamlStringToJson: (fileContent: string) => any;
167
+ declare const capitalize: (text: string) => string;
168
+ declare const getEndpointDetails: (path: string, method: string) => {
169
+ name: string;
170
+ variables: string[];
171
+ pathParts: string[];
172
+ };
173
+ declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
174
+ declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
175
+ declare function getNestedValue<T>(obj: object, path: string): T | undefined;
176
+ interface ExtractedCustomCode {
177
+ beforeGenerated: string;
178
+ afterGenerated: string;
179
+ }
180
+ /**
181
+ * Extract custom code from existing file using comment markers
182
+ * @param fileContent - The content of the existing file
183
+ * @param markerText - The marker text to look for (default: "CUSTOM CODE")
184
+ * @returns Object containing custom code sections before and after generated code
185
+ */
186
+ declare const extractCustomCode: (fileContent: string, markerText?: string) => ExtractedCustomCode;
187
+ /**
188
+ * Create an empty custom code marker section
189
+ * @param position - Position of the marker ("top" or "bottom")
190
+ * @param markerText - The marker text (default: "CUSTOM CODE")
191
+ * @param includeInstructions - Whether to include helpful instructions
192
+ * @returns The marker section as a string
193
+ */
194
+ declare const createCustomCodeMarker: (position: "top" | "bottom", markerText?: string, includeInstructions?: boolean) => string;
195
+ /**
196
+ * Merge generated content with preserved custom code
197
+ * @param generatedContent - The newly generated content
198
+ * @param existingFileContent - The existing file content (null if file doesn't exist)
199
+ * @param config - Configuration options
200
+ * @returns The merged content with custom code preserved
201
+ */
202
+ declare const mergeCustomCode: (generatedContent: string, existingFileContent: string | null, config?: {
203
+ position?: "top" | "bottom" | "both";
204
+ markerText?: string;
205
+ includeInstructions?: boolean;
206
+ }) => string;
207
+
208
+ declare const variableName: RegExp;
209
+ declare const variableNameChar: RegExp;
210
+
154
211
  declare const Init: (options?: {
155
212
  refetchInterval?: number;
156
213
  }) => Promise<void>;
157
214
 
158
- export { type IConfig, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init };
215
+ export { type ExtractedCustomCode, type IConfig, type IConfigCustomCode, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, createCustomCodeMarker, extractCustomCode, getEndpointDetails, getNestedValue, isJson, isYamlString, mergeCustomCode, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { Method } from 'axios';
2
- export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson } from './helpers.js';
3
- export { variableName, variableNameChar } from './regex.js';
4
2
 
5
3
  type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
6
4
  type IOpenApSchemaSpec = {
@@ -86,6 +84,16 @@ type IConfigFolderSplit = {
86
84
  responses?: IOpenApiResponseSpec;
87
85
  }) => string | null;
88
86
  };
87
+ type IConfigCustomCode = {
88
+ /** Enable custom code preservation (default: true) */
89
+ enabled?: boolean;
90
+ /** Position of custom code block in generated files (default: "bottom") */
91
+ position?: "top" | "bottom" | "both";
92
+ /** Custom marker text to use for identifying custom code sections (default: "CUSTOM CODE") */
93
+ markerText?: string;
94
+ /** Add helpful instructions in markers (default: true) */
95
+ includeInstructions?: boolean;
96
+ };
89
97
  type IConfig = {
90
98
  refetchInterval?: number;
91
99
  folder?: string;
@@ -93,6 +101,8 @@ type IConfig = {
93
101
  server?: number | string;
94
102
  /** Configuration for splitting generated code into folders */
95
103
  folderSplit?: IConfigFolderSplit;
104
+ /** Configuration for preserving custom code between regenerations */
105
+ customCode?: IConfigCustomCode;
96
106
  /** Configuration for excluding endpoints from code generation */
97
107
  types?: {
98
108
  name?: {
@@ -151,8 +161,55 @@ type IOpenApiSecuritySchemes = {
151
161
  };
152
162
  };
153
163
 
164
+ declare const isJson: (value: any) => boolean;
165
+ declare const isYamlString: (fileContent: string) => boolean;
166
+ declare const yamlStringToJson: (fileContent: string) => any;
167
+ declare const capitalize: (text: string) => string;
168
+ declare const getEndpointDetails: (path: string, method: string) => {
169
+ name: string;
170
+ variables: string[];
171
+ pathParts: string[];
172
+ };
173
+ declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
174
+ declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
175
+ declare function getNestedValue<T>(obj: object, path: string): T | undefined;
176
+ interface ExtractedCustomCode {
177
+ beforeGenerated: string;
178
+ afterGenerated: string;
179
+ }
180
+ /**
181
+ * Extract custom code from existing file using comment markers
182
+ * @param fileContent - The content of the existing file
183
+ * @param markerText - The marker text to look for (default: "CUSTOM CODE")
184
+ * @returns Object containing custom code sections before and after generated code
185
+ */
186
+ declare const extractCustomCode: (fileContent: string, markerText?: string) => ExtractedCustomCode;
187
+ /**
188
+ * Create an empty custom code marker section
189
+ * @param position - Position of the marker ("top" or "bottom")
190
+ * @param markerText - The marker text (default: "CUSTOM CODE")
191
+ * @param includeInstructions - Whether to include helpful instructions
192
+ * @returns The marker section as a string
193
+ */
194
+ declare const createCustomCodeMarker: (position: "top" | "bottom", markerText?: string, includeInstructions?: boolean) => string;
195
+ /**
196
+ * Merge generated content with preserved custom code
197
+ * @param generatedContent - The newly generated content
198
+ * @param existingFileContent - The existing file content (null if file doesn't exist)
199
+ * @param config - Configuration options
200
+ * @returns The merged content with custom code preserved
201
+ */
202
+ declare const mergeCustomCode: (generatedContent: string, existingFileContent: string | null, config?: {
203
+ position?: "top" | "bottom" | "both";
204
+ markerText?: string;
205
+ includeInstructions?: boolean;
206
+ }) => string;
207
+
208
+ declare const variableName: RegExp;
209
+ declare const variableNameChar: RegExp;
210
+
154
211
  declare const Init: (options?: {
155
212
  refetchInterval?: number;
156
213
  }) => Promise<void>;
157
214
 
158
- export { type IConfig, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init };
215
+ export { type ExtractedCustomCode, type IConfig, type IConfigCustomCode, type IConfigDoc, type IConfigExclude, type IConfigFolderSplit, type IConfigInclude, type IConfigReplaceWord, type IOpenApSchemaSpec, type IOpenApiMediaTypeSpec, type IOpenApiParameterSpec, type IOpenApiRequestBodySpec, type IOpenApiResponseSpec, type IOpenApiSecuritySchemes, type IOpenApiSpec, Init, JSONStringify, capitalize, createCustomCodeMarker, extractCustomCode, getEndpointDetails, getNestedValue, isJson, isYamlString, mergeCustomCode, renderTypeRefMD, variableName, variableNameChar, yamlStringToJson };
package/dist/index.js CHANGED
@@ -1,56 +1,65 @@
1
- 'use strict';var M=require('fs'),F=require('path'),g=require('js-yaml'),pt=require('lodash.isequal'),_e=require('lodash.get'),lt=require('axios'),mt=require('axios-retry'),dt=require('@apidevtools/swagger-parser'),curlGenerator=require('curl-generator');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var M__default=/*#__PURE__*/_interopDefault(M);var F__default=/*#__PURE__*/_interopDefault(F);var g__namespace=/*#__PURE__*/_interopNamespace(g);var pt__default=/*#__PURE__*/_interopDefault(pt);var _e__default=/*#__PURE__*/_interopDefault(_e);var lt__default=/*#__PURE__*/_interopDefault(lt);var mt__default=/*#__PURE__*/_interopDefault(mt);var dt__default=/*#__PURE__*/_interopDefault(dt);var D=(o=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(o,{get:(m,e)=>(typeof require!="undefined"?require:m)[e]}):o)(function(o){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var ne=(o,m,e)=>new Promise((C,A)=>{var b=O=>{try{h(e.next(O));}catch(R){A(R);}},u=O=>{try{h(e.throw(O));}catch(R){A(R);}},h=O=>O.done?C(O.value):Promise.resolve(O.value).then(b,u);h((e=e.apply(o,m)).next());});var ft=/^[A-Za-z_$][A-Za-z0-9_$]*$/,We=/[A-Za-z0-9_$]/;var Ye=o=>["object"].includes(typeof o)&&!(o instanceof Blob),ot=o=>{try{return g__namespace.load(o),!0}catch(m){let e=m;if(e instanceof g__namespace.YAMLException)return false;throw e}},Ge=o=>{if(ot(o)){let m=g__namespace.load(o),e=JSON.stringify(m,null,2);return JSON.parse(e)}},V=o=>o.substring(0,1).toUpperCase()+o.substring(1),Qe=(o,m)=>{let e=o.split("/"),C=`${V(m)}`,A=[];return e.forEach(b=>{if(b[0]==="{"&&b[b.length-1]==="}"){let h=b.replace(/{/,"").replace(/}/,"");A.push(h),b=`$${h}`;}else if(b[0]==="<"&&b[b.length-1]===">"){let h=b.replace(/</,"").replace(/>/,"");A.push(h),b=`$${h}`;}else if(b[0]===":"){let h=b.replace(/:/,"");A.push(h),b=`$${h}`;}let u="";b.split("").forEach(h=>{let O=h;We.test(h)||(O="/"),u+=O;}),u.split("/").forEach(h=>{C+=V(h);});}),{name:C,variables:A,pathParts:e}},_=(o,m=1)=>{let e="{",C=Object.keys(o);for(let A=0;A<C.length;A++){let b=C[A],u=o[b];if(e+=`
2
- `+" ".repeat(m)+b+": ",Array.isArray(u)){e+="[";for(let h=0;h<u.length;h++){let O=u[h];typeof O=="object"&&O!==null?e+=_(O,m+1):e+=typeof O=="string"?`"${O}"`:O,h<u.length-1&&(e+=", ");}e+="]";}else typeof u=="object"&&u!==null?e+=""+_(u,m+1):e+=u.split(`
3
- `).filter(h=>h.trim()!=="").join(`
4
- ${" ".repeat(m)}`);A<C.length-1&&(e+=", ");}return e+=`
5
- ${" ".repeat(m-1)}}`,e},ae=(o,m=1)=>`
1
+ 'use strict';var L=require('fs'),B=require('path'),ee=require('js-yaml'),ut=require('lodash.isequal'),rt=require('lodash.get'),yt=require('axios'),ct=require('axios-retry'),ht=require('@apidevtools/swagger-parser'),curlGenerator=require('curl-generator');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var L__default=/*#__PURE__*/_interopDefault(L);var B__default=/*#__PURE__*/_interopDefault(B);var ee__namespace=/*#__PURE__*/_interopNamespace(ee);var ut__default=/*#__PURE__*/_interopDefault(ut);var rt__default=/*#__PURE__*/_interopDefault(rt);var yt__default=/*#__PURE__*/_interopDefault(yt);var ct__default=/*#__PURE__*/_interopDefault(ct);var ht__default=/*#__PURE__*/_interopDefault(ht);var X=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(i,e)=>(typeof require!="undefined"?require:i)[e]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var g=(n,i,e)=>new Promise((O,$)=>{var C=f=>{try{p(e.next(f));}catch(E){$(E);}},o=f=>{try{p(e.throw(f));}catch(E){$(E);}},p=f=>f.done?O(f.value):Promise.resolve(f.value).then(C,o);p((e=e.apply(n,i)).next());});var Ot=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Ye=/[A-Za-z0-9_$]/;var Ze=n=>["object"].includes(typeof n)&&!(n instanceof Blob),pt=n=>{try{return ee__namespace.load(n),!0}catch(i){let e=i;if(e instanceof ee__namespace.YAMLException)return false;throw e}},De=n=>{if(pt(n)){let i=ee__namespace.load(n),e=JSON.stringify(i,null,2);return JSON.parse(e)}},W=n=>n.substring(0,1).toUpperCase()+n.substring(1),He=(n,i)=>{let e=n.split("/"),O=`${W(i)}`,$=[];return e.forEach(C=>{if(C[0]==="{"&&C[C.length-1]==="}"){let p=C.replace(/{/,"").replace(/}/,"");$.push(p),C=`$${p}`;}else if(C[0]==="<"&&C[C.length-1]===">"){let p=C.replace(/</,"").replace(/>/,"");$.push(p),C=`$${p}`;}else if(C[0]===":"){let p=C.replace(/:/,"");$.push(p),C=`$${p}`;}let o="";C.split("").forEach(p=>{let f=p;Ye.test(p)||(f="/"),o+=f;}),o.split("/").forEach(p=>{O+=W(p);});}),{name:O,variables:$,pathParts:e}},_=(n,i=1)=>{let e="{",O=Object.keys(n);for(let $=0;$<O.length;$++){let C=O[$],o=n[C];if(e+=`
2
+ `+" ".repeat(i)+C+": ",Array.isArray(o)){e+="[";for(let p=0;p<o.length;p++){let f=o[p];typeof f=="object"&&f!==null?e+=_(f,i+1):e+=typeof f=="string"?`"${f}"`:f,p<o.length-1&&(e+=", ");}e+="]";}else typeof o=="object"&&o!==null?e+=""+_(o,i+1):e+=o.split(`
3
+ `).filter(p=>p.trim()!=="").join(`
4
+ ${" ".repeat(i)}`);$<O.length-1&&(e+=", ");}return e+=`
5
+ ${" ".repeat(i-1)}}`,e},le=(n,i=1)=>`
6
6
  \`\`\`typescript
7
- ${" ".repeat(m)} ${o.split(`
7
+ ${" ".repeat(i)} ${n.split(`
8
8
  `).filter(e=>e.trim()!=="").join(`
9
- ${" ".repeat(m)} `)}
10
- \`\`\``;function Ot(o,m){return m.split(".").reduce((C,A)=>C&&C[A]!==void 0?C[A]:void 0,o)}var oe=F__default.default.join(__dirname,"../","../db.json");M__default.default.existsSync(oe)||M__default.default.writeFileSync(oe,"{}");var le={};try{le=D(oe);}catch(o){le={};}var ee=le||{},Ze=o=>{M__default.default.writeFileSync(oe,JSON.stringify(o));},He=(o,m)=>{ee[o]=m,Ze(ee);},Xe=o=>ee[o],De=()=>{ee={},Ze(ee);};var te=process.cwd(),me={},ge=lt__default.default.create({timeout:6e4});mt__default.default(ge,{retries:20,retryCondition:o=>o.code==="ECONNABORTED"||o.message.includes("Network Error"),retryDelay:o=>o*1e3});var et=(o,m,e,C)=>ne(null,null,function*(){var fe,he,ce,Oe,Ie,je;let A=yield ge.get(o),b=Ye(A.data)?A.data:Ge(A.data),u;try{u=yield dt__default.default.parse(b);}catch(s){let r=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${m}: ${r}`)}let h=F__default.default.join((e==null?void 0:e.folder)||"",m),O={},R=s=>{var r,I;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let f=e.folderSplit.customFolder(s);if(console.log("customFolder",f),f)return f}return (I=e==null?void 0:e.folderSplit)!=null&&I.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},G=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((he=(fe=u==null?void 0:u.servers)==null?void 0:fe[(e==null?void 0:e.server)||0])==null?void 0:he.url)||"",k=typeof((Oe=(ce=e==null?void 0:e.types)==null?void 0:ce.name)==null?void 0:Oe.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",rt=typeof((je=(Ie=e==null?void 0:e.endpoints)==null?void 0:Ie.name)==null?void 0:je.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",ye=(s,r)=>{var f,n;let I=V(s);if((n=(f=e==null?void 0:e.types)==null?void 0:f.name)!=null&&n.format){let p=e==null?void 0:e.types.name.format("shared",{name:s},I);if(p)return `${k}${p}`}return `${k}${I}`},J=(s,r,I,f,n,p=0)=>{let c="",a="",i="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let l=(r.$ref||"").split("/");l.shift(),[...l].pop();let w=_e__default.default(s,l,null);if(w){w!=null&&w.name&&(c=w.name),a=l[l.length-1];let S=ye(a);S.includes(".")&&(S=S.split(".").map((U,K)=>K===0?U:`["${U}"]`).join("")),i+=`${n!=null&&n.noSharedImport?"":"Shared."}${S}`;}}else i+="";else if(r.anyOf)i+=`(${r.anyOf.map(l=>J(s,l,"",f,n)).filter(l=>!!l).join("|")})`;else if(r.oneOf)i+=`(${r.oneOf.map(l=>J(s,l,"",f,n)).filter(l=>!!l).join("|")})`;else if(r.allOf)i+=`(${r.allOf.map(l=>J(s,l,"",f,n)).filter(l=>!!l).join("&")})`;else if(r.items)i+=`${J(s,r.items,"",false,n)}[]`;else if(r.properties){let l=Object.keys(r.properties),j=r.required||[],T="";l.forEach(w=>{var Z,U,K,Y,re,H;let S="";!((U=(Z=e==null?void 0:e.types)==null?void 0:Z.doc)!=null&&U.disable)&&((Y=(K=r.properties)==null?void 0:K[w])!=null&&Y.description)&&(S=" * "+((re=r.properties)==null?void 0:re[w].description.split(`
11
- `).filter(se=>se.trim()!=="").join(`
12
- *${" ".repeat(1)}`))),T+=(S?`/**
13
- ${S}
9
+ ${" ".repeat(i)} `)}
10
+ \`\`\``;function xt(n,i){return i.split(".").reduce((O,$)=>O&&O[$]!==void 0?O[$]:void 0,n)}var dt=(n,i="CUSTOM CODE")=>{let e=`// \u{1F512} ${i} START`,O=`// \u{1F512} ${i} END`,$={beforeGenerated:"",afterGenerated:""},C=0,o=[];for(;C<n.length;){let p=n.indexOf(e,C);if(p===-1)break;let f=n.indexOf(O,p);if(f===-1)break;let E=f+O.length,k=p,ne=n.substring(Math.max(0,p-200),p).lastIndexOf("// ==========");ne!==-1&&(k=Math.max(0,p-200)+ne);let oe=n.substring(k,E);o.push({start:k,end:E,content:oe}),C=E;}return o.length>0&&(n.substring(0,o[0].start).split(`
11
+ `).filter(E=>{let k=E.trim();return k.length>0&&!k.startsWith("//")}).join("").length===0?($.beforeGenerated=o[0].content,o.length>1&&($.afterGenerated=o[1].content)):($.afterGenerated=o[0].content,o.length>1&&!$.beforeGenerated&&($.beforeGenerated=o[1].content))),$},Qe=(n,i="CUSTOM CODE",e=true)=>{let O=e?`// ${n==="top"?"Add your custom code below this line":"Add your custom code above this line"}
12
+ // This section will be preserved during regeneration
13
+ `:"";return `// ${"=".repeat(60)}
14
+ // \u{1F512} ${i} START
15
+ ${O}// ${"=".repeat(60)}
16
+
17
+ // \u{1F512} ${i} END
18
+ // ${"=".repeat(60)}`},Xe=(n,i,e={})=>{let{position:O="bottom",markerText:$="CUSTOM CODE",includeInstructions:C=true}=e,o={beforeGenerated:"",afterGenerated:""};i&&(o=dt(i,$)),!o.beforeGenerated&&!o.afterGenerated&&((O==="top"||O==="both")&&(o.beforeGenerated=Qe("top",$,C)),(O==="bottom"||O==="both")&&(o.afterGenerated=Qe("bottom",$,C)));let p=[];return o.beforeGenerated&&(p.push(o.beforeGenerated),p.push("")),p.push(n),o.afterGenerated&&(p.push(""),p.push(o.afterGenerated)),p.join(`
19
+ `)};var pe=B__default.default.join(__dirname,"../","../db.json");L__default.default.existsSync(pe)||L__default.default.writeFileSync(pe,"{}");var ue={};try{ue=X(pe);}catch(n){ue={};}var te=ue||{},ge=n=>{L__default.default.writeFileSync(pe,JSON.stringify(n));},_e=(n,i)=>{te[n]=i,ge(te);},et=n=>te[n],tt=()=>{te={},ge(te);};var re=process.cwd(),ye={},st=yt__default.default.create({timeout:6e4});ct__default.default(st,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});var se=(n,i,e)=>g(null,null,function*(){var o,p,f,E;if(!(((o=e==null?void 0:e.customCode)==null?void 0:o.enabled)!==false)){yield L__default.default.promises.writeFile(n,i);return}let $=null;try{$=yield L__default.default.promises.readFile(n,"utf-8");}catch(k){}let C=Xe(i,$,{position:((p=e==null?void 0:e.customCode)==null?void 0:p.position)||"bottom",markerText:(f=e==null?void 0:e.customCode)==null?void 0:f.markerText,includeInstructions:(E=e==null?void 0:e.customCode)==null?void 0:E.includeInstructions});yield L__default.default.promises.writeFile(n,C);}),nt=(n,i,e,O)=>g(null,null,function*(){var fe,be,Oe,Ce,Ie,xe;let $=yield st.get(n),C=Ze($.data)?$.data:De($.data),o;try{o=yield ht__default.default.parse(C);}catch(s){let r=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${i}: ${r}`)}let p=B__default.default.join((e==null?void 0:e.folder)||"",i),f={},E=s=>{var r,x;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let b=e.folderSplit.customFolder(s);if(console.log("customFolder",b),b)return b}return (x=e==null?void 0:e.folderSplit)!=null&&x.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},k=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((be=(fe=o==null?void 0:o.servers)==null?void 0:fe[(e==null?void 0:e.server)||0])==null?void 0:be.url)||"",M=typeof((Ce=(Oe=e==null?void 0:e.types)==null?void 0:Oe.name)==null?void 0:Ce.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",ne=typeof((xe=(Ie=e==null?void 0:e.endpoints)==null?void 0:Ie.name)==null?void 0:xe.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",oe=(s,r)=>{var b,a;let x=W(s);if((a=(b=e==null?void 0:e.types)==null?void 0:b.name)!=null&&a.format){let m=e==null?void 0:e.types.name.format("shared",{name:s},x);if(m)return `${M}${m}`}return `${M}${x}`},q=(s,r,x,b,a,m=0)=>{let I="",l="",d="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let u=(r.$ref||"").split("/");u.shift(),[...u].pop();let w=rt__default.default(s,u,null);if(w){w!=null&&w.name&&(I=w.name),l=u[u.length-1];let N=oe(l);N.includes(".")&&(N=N.split(".").map((U,K)=>K===0?U:`["${U}"]`).join("")),d+=`${a!=null&&a.noSharedImport?"":"Shared."}${N}`;}}else d+="";else if(r.anyOf)d+=`(${r.anyOf.map(u=>q(s,u,"",b,a)).filter(u=>!!u).join("|")})`;else if(r.oneOf)d+=`(${r.oneOf.map(u=>q(s,u,"",b,a)).filter(u=>!!u).join("|")})`;else if(r.allOf)d+=`(${r.allOf.map(u=>q(s,u,"",b,a)).filter(u=>!!u).join("&")})`;else if(r.items)d+=`${q(s,r.items,"",false,a)}[]`;else if(r.properties){let u=Object.keys(r.properties),j=r.required||[],S="";u.forEach(w=>{var Z,U,K,Y,ae,D;let N="";!((U=(Z=e==null?void 0:e.types)==null?void 0:Z.doc)!=null&&U.disable)&&((Y=(K=r.properties)==null?void 0:K[w])!=null&&Y.description)&&(N=" * "+((ae=r.properties)==null?void 0:ae[w].description.split(`
20
+ `).filter(ie=>ie.trim()!=="").join(`
21
+ *${" ".repeat(1)}`))),S+=(N?`/**
22
+ ${N}
14
23
  */
15
- `:"")+`${J(s,(H=r.properties)==null?void 0:H[w],w,j.includes(w),n,p+1)}`;}),T.length>0?i+=`{
16
- ${" ".repeat(p)}${T}${" ".repeat(p)}}`:i+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(i+="("),r.enum.map(l=>JSON.stringify(l)).filter(l=>!!l).forEach((l,j)=>{i+=`${j===0?"":"|"}${l}`;}),r.enum.length>1&&(i+=")");else if(r.type){let l=j=>{let T="";if(typeof j=="string")["string","integer","number","array","boolean","null"].includes(j)?["integer","number"].includes(j)?T+="number":j==="array"?T+="any[]":T+=j:j==="object"&&(r.additionalProperties?T+=`{[k: string]: ${J(s,r.additionalProperties,"",true,n)||"any"}}`:T+="{[k: string]: any}");else if(Array.isArray(j)){let w=j.map(S=>l(S));w.filter(S=>S!==""),w.length>1&&(T+="("+w.join("|")+")");}else T+="any";return T};i=l(r.type);}}else i="string";let y=c||I;n!=null&&n.useComponentName&&!y&&(y=a);let E=y?` "${y}"${f?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return i.length>0?`${E}${i}${t}${y?`;
17
- `:""}`:""},z=(s,r)=>{let n="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let p=(r.$ref||"").split("/");p.shift();let a=_e__default.default(s,p,null);a&&(a!=null&&a.name&&(a.name),p[p.length-1],n+=z(s,a));}else n+="";else if(r.anyOf)n+=z(s,r.anyOf[0]);else if(r.oneOf)n+=z(s,r.oneOf[0]);else if(r.allOf)n+=`{${r.allOf.map(p=>`...(${z(s,p)})`).join(",")}}`;else if(r.items)n+=`[${z(s,r.items)}]`;else if(r.properties){let a=Object.keys(r.properties).map(i=>{var y;return ` "${i}": ${z(s,(y=r.properties)==null?void 0:y[i])}`}).join(`,
18
- `);a.length>0?n+=`{
19
- ${a}
20
- }`:n+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(n+=r.enum[0]);else if(r.type)if(r.example)n+=JSON.stringify(r.example);else {let p=c=>{let a="";if(typeof c=="string")["string","integer","number","array","boolean","null"].includes(c)?["integer","number"].includes(c)?a+="123":c==="array"?a+="[]":c==="boolean"?a+="true":c==="null"?a+="null":a+=`"${c}"`:c==="object"&&(a+="{}");else if(Array.isArray(c)){let i=c.map(y=>p(y));i.filter(y=>y!==""),i.length>1&&(a+=i.join("|"));}else a+="any";return a};n=p(r.type);}}else n="string";return n};C&&!isNaN(C)&&C>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(me[m]&&clearTimeout(me[m]),me[m]=setTimeout(()=>et(o,m,e,C),C)));let st=Xe(m);if(pt__default.default(st,u))return;He(m,u);let ie="",Q="",W={};u.components&&Object.keys(u.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=u.components[s],I={},f={};Object.keys(r).forEach(p=>{var i;let c=(i=r[p])!=null&&i.schema?r[p].schema:r[p],a=`${J(u,c,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(s)})}`;if(a){let y=p.split("."),E=I,t=f;for(let l=0;l<y.length;l++){let j=y[l];l<y.length-1?(j in E||(E[j]={},t[j]={}),E=E[j],t=t[j]):(E[j]=a,t[j]=c);}}}),Object.keys(I).forEach(p=>{var y,E,t,l;let c=ye(p),a=I[p],i="";!((E=(y=e==null?void 0:e.types)==null?void 0:y.doc)!=null&&E.disable)&&p in r&&((t=r[p])!=null&&t.description)&&(i=" * "+r[p].description.split(`
24
+ `:"")+`${q(s,(D=r.properties)==null?void 0:D[w],w,j.includes(w),a,m+1)}`;}),S.length>0?d+=`{
25
+ ${" ".repeat(m)}${S}${" ".repeat(m)}}`:d+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(d+="("),r.enum.map(u=>JSON.stringify(u)).filter(u=>!!u).forEach((u,j)=>{d+=`${j===0?"":"|"}${u}`;}),r.enum.length>1&&(d+=")");else if(r.type){let u=j=>{let S="";if(typeof j=="string")["string","integer","number","array","boolean","null"].includes(j)?["integer","number"].includes(j)?S+="number":j==="array"?S+="any[]":S+=j:j==="object"&&(r.additionalProperties?S+=`{[k: string]: ${q(s,r.additionalProperties,"",true,a)||"any"}}`:S+="{[k: string]: any}");else if(Array.isArray(j)){let w=j.map(N=>u(N));w.filter(N=>N!==""),w.length>1&&(S+="("+w.join("|")+")");}else S+="any";return S};d=u(r.type);}}else d="string";let c=I||x;a!=null&&a.useComponentName&&!c&&(c=l);let T=c?` "${c}"${b?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return d.length>0?`${T}${d}${t}${c?`;
26
+ `:""}`:""},z=(s,r)=>{let a="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let m=(r.$ref||"").split("/");m.shift();let l=rt__default.default(s,m,null);l&&(l!=null&&l.name&&(l.name),m[m.length-1],a+=z(s,l));}else a+="";else if(r.anyOf)a+=z(s,r.anyOf[0]);else if(r.oneOf)a+=z(s,r.oneOf[0]);else if(r.allOf)a+=`{${r.allOf.map(m=>`...(${z(s,m)})`).join(",")}}`;else if(r.items)a+=`[${z(s,r.items)}]`;else if(r.properties){let l=Object.keys(r.properties).map(d=>{var c;return ` "${d}": ${z(s,(c=r.properties)==null?void 0:c[d])}`}).join(`,
27
+ `);l.length>0?a+=`{
28
+ ${l}
29
+ }`:a+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else {let m=I=>{let l="";if(typeof I=="string")["string","integer","number","array","boolean","null"].includes(I)?["integer","number"].includes(I)?l+="123":I==="array"?l+="[]":I==="boolean"?l+="true":I==="null"?l+="null":l+=`"${I}"`:I==="object"&&(l+="{}");else if(Array.isArray(I)){let d=I.map(c=>m(c));d.filter(c=>c!==""),d.length>1&&(l+=d.join("|"));}else l+="any";return l};a=m(r.type);}}else a="string";return a};O&&!isNaN(O)&&O>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(ye[i]&&clearTimeout(ye[i]),ye[i]=setTimeout(()=>nt(n,i,e,O),O)));let at=et(i);if(ut__default.default(at,o))return;_e(i,o);let de="",Q="",V={};o.components&&Object.keys(o.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=o.components[s],x={},b={};Object.keys(r).forEach(m=>{var d;let I=(d=r[m])!=null&&d.schema?r[m].schema:r[m],l=`${q(o,I,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(s)})}`;if(l){let c=m.split("."),T=x,t=b;for(let u=0;u<c.length;u++){let j=c[u];u<c.length-1?(j in T||(T[j]={},t[j]={}),T=T[j],t=t[j]):(T[j]=l,t[j]=I);}}}),Object.keys(x).forEach(m=>{var c,T,t,u;let I=oe(m),l=x[m],d="";!((T=(c=e==null?void 0:e.types)==null?void 0:c.doc)!=null&&T.disable)&&m in r&&((t=r[m])!=null&&t.description)&&(d=" * "+r[m].description.split(`
21
30
  `).filter(j=>j.trim()!=="").join(`
22
- *${" ".repeat(1)}`)),W[p]=((l=W[p])!=null?l:"")+(i?`/**
23
- ${i}
31
+ *${" ".repeat(1)}`)),V[m]=((u=V[m])!=null?u:"")+(d?`/**
32
+ ${d}
24
33
  */
25
- `:"")+"export type "+c+" = "+(typeof a=="string"?a:_(a))+`;
26
- `;});}});let $e=s=>{let r="";if(s.content){let I=Object.keys(s.content);I[0]&&s.content[I[0]].schema&&(r+=`${J(u,s.content[I[0]].schema,"")}`);}return r},nt=s=>{var r,I,f,n,p;if((I=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&I.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let c=s;return (p=(n=(f=e==null?void 0:e.endpoints)==null?void 0:f.value)==null?void 0:n.replaceWords)==null||p.forEach((a,i)=>{let y=new RegExp(a.replace,"g");c=c.replace(y,a.with||"");}),c}else return s},at=(s,r,I=[])=>{var p,c;let f=(p=e==null?void 0:e.endpoints)==null?void 0:p.exclude,n=(c=e==null?void 0:e.endpoints)==null?void 0:c.include;if(n){let a=n.tags&&n.tags.length>0?I.some(y=>n.tags.includes(y)):true,i=n.endpoints&&n.endpoints.length>0?n.endpoints.some(y=>{let E=!y.method||y.method.toLowerCase()===r.toLowerCase();return y.path?s===y.path&&E:y.regex?new RegExp(y.regex).test(s)&&E:false}):true;if(!a||!i)return true}return !!(f&&(f.tags&&f.tags.length>0&&I.some(i=>f.tags.includes(i))||f.endpoints&&f.endpoints.length>0&&f.endpoints.some(i=>{let y=!i.method||i.method.toLowerCase()===r.toLowerCase();return i.path?s===i.path&&y:i.regex?new RegExp(i.regex).test(s)&&y:false})))};if(Object.keys(u.paths||{}).forEach(s=>{let r=u.paths[s];Object.keys(r).forEach(f=>{var se,be,xe,Ce,Ae,Ee,Te,we,Se,Ne,Re,ve,Fe,Pe,ke,qe,Be,Me,Je,Ue,Le,ze,Ke,Ve;let n=f,p=Qe(s,n),c=((se=r[n])==null?void 0:se.tags)||[];if(at(s,n,c))return;let a=r[n],i=R({method:n,path:s,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:c,parameters:a==null?void 0:a.parameters,requestBody:a==null?void 0:a.requestBody,responses:a==null?void 0:a.responses});O[i]||(O[i]={endpoints:"",types:""});let y=((xe=(be=e==null?void 0:e.endpoints)==null?void 0:be.value)!=null&&xe.includeServer?G:"")+p.pathParts.map($=>($[0]==="{"&&$[$.length-1]==="}"?$=`\${${$.replace(/{/,"").replace(/}/,"")}}`:$[0]==="<"&&$[$.length-1]===">"?$=`\${${$.replace(/</,"").replace(/>/,"")}}`:$[0]===":"&&($=`\${${$.replace(/:/,"")}}`),$)).join("/"),E=`"${y}"`;p.variables.length>0&&(E=`(${p.variables.map(d=>`${d}:string`).join(",")})=> \`${y}\``),E=nt(E);let t=r[n],l="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((d,N)=>{(d.$ref||d.in==="query"&&d.name)&&(l+=`${J(u,d.$ref?d:d.schema,d.name||"",d.required)}`);}),l)){l=`{
27
- ${l}}`;let d=`${p.name}Query`;if((Ae=(Ce=e==null?void 0:e.types)==null?void 0:Ce.name)!=null&&Ae.useOperationId&&(t!=null&&t.operationId)&&(d=`${t.operationId}Query`),d=V(`${k}${d}`),(Te=(Ee=e==null?void 0:e.types)==null?void 0:Ee.name)!=null&&Te.format){let q=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},d);q&&(d=`${k}${q}`);}let N=`export type ${d} = ${l};
28
- `;e!=null&&e.folderSplit?O[i].types+=N:Q+=N;}let j=t==null?void 0:t.requestBody,T="";if(j&&(T=$e(j),T)){let $=`${p.name}DTO`;if((Se=(we=e==null?void 0:e.types)==null?void 0:we.name)!=null&&Se.useOperationId&&(t!=null&&t.operationId)&&($=`${t.operationId}DTO`),$=V(`${k}${$}`),(Re=(Ne=e==null?void 0:e.types)==null?void 0:Ne.name)!=null&&Re.format){let N=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},$);N&&($=`${k}${N}`);}let d=`export type ${$} = ${T};
29
- `;e!=null&&e.folderSplit?O[i].types+=d:Q+=d;}let w={},S="";if(t!=null&&t.responses){let $=t==null?void 0:t.responses;Object.keys($).forEach(N=>{var q,B,v,P;if(S=$e($[N]),w[N]=S,S){let x=`${p.name}${N}Response`;if((B=(q=e==null?void 0:e.types)==null?void 0:q.name)!=null&&B.useOperationId&&(t!=null&&t.operationId)&&(x=`${t.operationId}${N}Response`),x=V(`${k}${x}`),(P=(v=e==null?void 0:e.types)==null?void 0:v.name)!=null&&P.format){let X=e==null?void 0:e.types.name.format("endpoint",{code:N,type:"response",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},x);X&&(x=`${k}${X}`);}let L=`export type ${x} = ${S};
30
- `;e!=null&&e.folderSplit?O[i].types+=L:Q+=L;}});}let Z=$=>!$||!$.length?"":$.map(d=>Object.entries(d).map(([q,B])=>{let v=q,P="";return Array.isArray(B)&&B.length&&(P=`
31
- - Scopes: [\`${B.join("`, `")}\`]`,v=`**${v}**`),`
32
- - ${v}${P}`}).join("")).join(`
33
- `),U=t!=null&&t.security?Z(t.security):"",K="";if(!((Fe=(ve=e==null?void 0:e.endpoints)==null?void 0:ve.doc)!=null&&Fe.disable)){let $="";if((ke=(Pe=e==null?void 0:e.endpoints)==null?void 0:Pe.doc)!=null&&ke.showCurl){let d={},N="",q="";(qe=t.requestBody)!=null&&qe.content&&Object.keys(t.requestBody.content).forEach(P=>{let x=t.requestBody.content[P].schema;if(x){Array.isArray(d["Content-type"])?d["Content-type"].push(P):d["Content-type"]=[P];let L=z(u,x);L&&(N=L);}}),t!=null&&t.security&&t.security.forEach(v=>{Object.keys(v).forEach(P=>{var L,X;let x=(X=(L=u.components)==null?void 0:L.securitySchemes)==null?void 0:X[P];x&&(x.type==="mutualTLS"?q+=`
34
- --cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:x.type==="apiKey"?d[(x==null?void 0:x.name)||"X-API-KEY"]="{API_KEY_VALUE}":d.Authorization=`${(x==null?void 0:x.scheme)==="basic"?"Basic":"Bearer"} {${(x==null?void 0:x.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let B={};Object.keys(d).forEach(v=>{Array.isArray(d[v])?B[v]=d[v].join("; "):B[v]=d[v];}),$=`
34
+ `:"")+"export type "+I+" = "+(typeof l=="string"?l:_(l))+`;
35
+ `;});}});let $e=s=>{let r="";if(s.content){let x=Object.keys(s.content);x[0]&&s.content[x[0]].schema&&(r+=`${q(o,s.content[x[0]].schema,"")}`);}return r},it=s=>{var r,x,b,a,m;if((x=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&x.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let I=s;return (m=(a=(b=e==null?void 0:e.endpoints)==null?void 0:b.value)==null?void 0:a.replaceWords)==null||m.forEach((l,d)=>{let c=new RegExp(l.replace,"g");I=I.replace(c,l.with||"");}),I}else return s},lt=(s,r,x=[])=>{var m,I;let b=(m=e==null?void 0:e.endpoints)==null?void 0:m.exclude,a=(I=e==null?void 0:e.endpoints)==null?void 0:I.include;if(a){let l=a.tags&&a.tags.length>0?x.some(c=>a.tags.includes(c)):true,d=a.endpoints&&a.endpoints.length>0?a.endpoints.some(c=>{let T=!c.method||c.method.toLowerCase()===r.toLowerCase();return c.path?s===c.path&&T:c.regex?new RegExp(c.regex).test(s)&&T:false}):true;if(!l||!d)return true}return !!(b&&(b.tags&&b.tags.length>0&&x.some(d=>b.tags.includes(d))||b.endpoints&&b.endpoints.length>0&&b.endpoints.some(d=>{let c=!d.method||d.method.toLowerCase()===r.toLowerCase();return d.path?s===d.path&&c:d.regex?new RegExp(d.regex).test(s)&&c:false})))};if(Object.keys(o.paths||{}).forEach(s=>{let r=o.paths[s];Object.keys(r).forEach(b=>{var ie,je,Ee,Ae,Te,Se,we,Ne,ve,Re,ke,Be,Me,Fe,Ge,Pe,qe,Ue,Je,Le,ze,Ke,We,Ve;let a=b,m=He(s,a),I=((ie=r[a])==null?void 0:ie.tags)||[];if(lt(s,a,I))return;let l=r[a],d=E({method:a,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId,tags:I,parameters:l==null?void 0:l.parameters,requestBody:l==null?void 0:l.requestBody,responses:l==null?void 0:l.responses});f[d]||(f[d]={endpoints:"",types:""});let c=((Ee=(je=e==null?void 0:e.endpoints)==null?void 0:je.value)!=null&&Ee.includeServer?k:"")+m.pathParts.map(h=>(h[0]==="{"&&h[h.length-1]==="}"?h=`\${${h.replace(/{/,"").replace(/}/,"")}}`:h[0]==="<"&&h[h.length-1]===">"?h=`\${${h.replace(/</,"").replace(/>/,"")}}`:h[0]===":"&&(h=`\${${h.replace(/:/,"")}}`),h)).join("/"),T=`"${c}"`;m.variables.length>0&&(T=`(${m.variables.map(y=>`${y}:string`).join(",")})=> \`${c}\``),T=it(T);let t=r[a],u="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((y,v)=>{(y.$ref||y.in==="query"&&y.name)&&(u+=`${q(o,y.$ref?y:y.schema,y.name||"",y.required)}`);}),u)){u=`{
36
+ ${u}}`;let y=`${m.name}Query`;if((Te=(Ae=e==null?void 0:e.types)==null?void 0:Ae.name)!=null&&Te.useOperationId&&(t!=null&&t.operationId)&&(y=`${t.operationId}Query`),y=W(`${M}${y}`),(we=(Se=e==null?void 0:e.types)==null?void 0:Se.name)!=null&&we.format){let G=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},y);G&&(y=`${M}${G}`);}let v=`export type ${y} = ${u};
37
+ `;e!=null&&e.folderSplit?f[d].types+=v:Q+=v;}let j=t==null?void 0:t.requestBody,S="";if(j&&(S=$e(j),S)){let h=`${m.name}DTO`;if((ve=(Ne=e==null?void 0:e.types)==null?void 0:Ne.name)!=null&&ve.useOperationId&&(t!=null&&t.operationId)&&(h=`${t.operationId}DTO`),h=W(`${M}${h}`),(ke=(Re=e==null?void 0:e.types)==null?void 0:Re.name)!=null&&ke.format){let v=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},h);v&&(h=`${M}${v}`);}let y=`export type ${h} = ${S};
38
+ `;e!=null&&e.folderSplit?f[d].types+=y:Q+=y;}let w={},N="";if(t!=null&&t.responses){let h=t==null?void 0:t.responses;Object.keys(h).forEach(v=>{var G,P,R,F;if(N=$e(h[v]),w[v]=N,N){let A=`${m.name}${v}Response`;if((P=(G=e==null?void 0:e.types)==null?void 0:G.name)!=null&&P.useOperationId&&(t!=null&&t.operationId)&&(A=`${t.operationId}${v}Response`),A=W(`${M}${A}`),(F=(R=e==null?void 0:e.types)==null?void 0:R.name)!=null&&F.format){let H=e==null?void 0:e.types.name.format("endpoint",{code:v,type:"response",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},A);H&&(A=`${M}${H}`);}let J=`export type ${A} = ${N};
39
+ `;e!=null&&e.folderSplit?f[d].types+=J:Q+=J;}});}let Z=h=>!h||!h.length?"":h.map(y=>Object.entries(y).map(([G,P])=>{let R=G,F="";return Array.isArray(P)&&P.length&&(F=`
40
+ - Scopes: [\`${P.join("`, `")}\`]`,R=`**${R}**`),`
41
+ - ${R}${F}`}).join("")).join(`
42
+ `),U=t!=null&&t.security?Z(t.security):"",K="";if(!((Me=(Be=e==null?void 0:e.endpoints)==null?void 0:Be.doc)!=null&&Me.disable)){let h="";if((Ge=(Fe=e==null?void 0:e.endpoints)==null?void 0:Fe.doc)!=null&&Ge.showCurl){let y={},v="",G="";(Pe=t.requestBody)!=null&&Pe.content&&Object.keys(t.requestBody.content).forEach(F=>{let A=t.requestBody.content[F].schema;if(A){Array.isArray(y["Content-type"])?y["Content-type"].push(F):y["Content-type"]=[F];let J=z(o,A);J&&(v=J);}}),t!=null&&t.security&&t.security.forEach(R=>{Object.keys(R).forEach(F=>{var J,H;let A=(H=(J=o.components)==null?void 0:J.securitySchemes)==null?void 0:H[F];A&&(A.type==="mutualTLS"?G+=`
43
+ --cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:A.type==="apiKey"?y[(A==null?void 0:A.name)||"X-API-KEY"]="{API_KEY_VALUE}":y.Authorization=`${(A==null?void 0:A.scheme)==="basic"?"Basic":"Bearer"} {${(A==null?void 0:A.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let P={};Object.keys(y).forEach(R=>{Array.isArray(y[R])?P[R]=y[R].join("; "):P[R]=y[R];}),h=`
35
44
  \`\`\`bash
36
- ${curlGenerator.CurlGenerator({url:G+s,method:n.toUpperCase(),headers:B,body:N})}${q}
45
+ ${curlGenerator.CurlGenerator({url:k+s,method:a.toUpperCase(),headers:P,body:v})}${G}
37
46
  \`\`\``;}K=`/**${t!=null&&t.description?`
38
47
  * ${t==null?void 0:t.description} `:""}
39
- * **Method**: \`${n.toUpperCase()}\`
48
+ * **Method**: \`${a.toUpperCase()}\`
40
49
  * **Summary**: ${(t==null?void 0:t.summary)||""}
41
- * **Tags**: [${((Be=t==null?void 0:t.tags)==null?void 0:Be.join(", "))||""}]
42
- * **OperationId**: ${(t==null?void 0:t.operationId)||""} ${l?`
43
- * **Query**: ${ae(l)} `:""}${T?`
44
- * **DTO**: ${ae(T)} `:""}${S?`
45
- * **Response**: ${Object.entries(w).map(([d,N])=>`
46
- - **${d}**: ${ae(N,2)} `).join("")}`:""}${U?`
50
+ * **Tags**: [${((qe=t==null?void 0:t.tags)==null?void 0:qe.join(", "))||""}]
51
+ * **OperationId**: ${(t==null?void 0:t.operationId)||""} ${u?`
52
+ * **Query**: ${le(u)} `:""}${S?`
53
+ * **DTO**: ${le(S)} `:""}${N?`
54
+ * **Response**: ${Object.entries(w).map(([y,v])=>`
55
+ - **${y}**: ${le(v,2)} `).join("")}`:""}${U?`
47
56
  * **Security**: ${U}
48
- `:""}${$}
57
+ `:""}${h}
49
58
  */
50
- `;}let Y=(Je=(Me=e==null?void 0:e.endpoints)==null?void 0:Me.name)!=null&&Je.useOperationId&&((Ue=t==null?void 0:t.operationId)==null?void 0:Ue.length)>0?t.operationId:`${p.name}`;if((ze=(Le=e==null?void 0:e.endpoints)==null?void 0:Le.name)!=null&&ze.format){let $=e==null?void 0:e.endpoints.name.format({method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},Y);$&&(Y=$);}let re={method:`"${n}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:E,tags:(t==null?void 0:t.tags)||[]},H=`${K}export const ${rt}${Y} = ${((Ve=(Ke=e==null?void 0:e.endpoints)==null?void 0:Ke.value)==null?void 0:Ve.type)==="object"?_(re):E};
51
- `;e!=null&&e.folderSplit?O[i].endpoints+=H:ie+=H;});}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(O))if(r.endpoints||r.types){let I=F__default.default.join(h,s);if(r.endpoints){let f=F__default.default.join(te,I,"endpoints.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(f),{recursive:true}),yield M__default.default.promises.writeFile(f,r.endpoints);}if(r.types){let f=F__default.default.join(te,I,"types.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(f),{recursive:true});let n=Object.values(W).length>0?`import * as Shared from "../shared";
59
+ `;}let Y=(Je=(Ue=e==null?void 0:e.endpoints)==null?void 0:Ue.name)!=null&&Je.useOperationId&&((Le=t==null?void 0:t.operationId)==null?void 0:Le.length)>0?t.operationId:`${m.name}`;if((Ke=(ze=e==null?void 0:e.endpoints)==null?void 0:ze.name)!=null&&Ke.format){let h=e==null?void 0:e.endpoints.name.format({method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},Y);h&&(Y=h);}let ae={method:`"${a}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:T,tags:(t==null?void 0:t.tags)||[]},D=`${K}export const ${ne}${Y} = ${((Ve=(We=e==null?void 0:e.endpoints)==null?void 0:We.value)==null?void 0:Ve.type)==="object"?_(ae):T};
60
+ `;e!=null&&e.folderSplit?f[d].endpoints+=D:de+=D;});}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(f))if(r.endpoints||r.types){let x=B__default.default.join(p,s);if(r.endpoints){let b=B__default.default.join(re,x,"endpoints.ts");yield L__default.default.promises.mkdir(B__default.default.dirname(b),{recursive:true}),yield se(b,r.endpoints,e);}if(r.types){let b=B__default.default.join(re,x,"types.ts");yield L__default.default.promises.mkdir(B__default.default.dirname(b),{recursive:true});let a=Object.values(V).length>0?`import * as Shared from "../shared";
52
61
 
53
- ${r.types}`:r.types;yield M__default.default.promises.writeFile(f,n);}}}if(ie.length>0){let s=F__default.default.join(te,h,"endpoints.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield M__default.default.promises.writeFile(s,ie);}if(Object.values(W).length>0){let s=F__default.default.join(te,h,e!=null&&e.folderSplit?"":"types","shared.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield M__default.default.promises.writeFile(s,Object.values(W).join(`
54
- `));}if(Q.length>0){let s=F__default.default.join(te,h,"types","index.ts");yield M__default.default.promises.mkdir(F__default.default.dirname(s),{recursive:true}),yield M__default.default.promises.writeFile(s,`${Object.values(W).length>0?`import * as Shared from "./shared";
62
+ ${r.types}`:r.types;yield se(b,a,e);}}}if(de.length>0){let s=B__default.default.join(re,p,"endpoints.ts");yield L__default.default.promises.mkdir(B__default.default.dirname(s),{recursive:true}),yield se(s,de,e);}if(Object.values(V).length>0){let s=B__default.default.join(re,p,e!=null&&e.folderSplit?"":"types","shared.ts");yield L__default.default.promises.mkdir(B__default.default.dirname(s),{recursive:true}),yield se(s,Object.values(V).join(`
63
+ `),e);}if(Q.length>0){let s=B__default.default.join(re,p,"types","index.ts");yield L__default.default.promises.mkdir(B__default.default.dirname(s),{recursive:true}),yield se(s,`${Object.values(V).length>0?`import * as Shared from "./shared";
55
64
 
56
- `:""}${Q}`);}}),tt=et;var ue=process.cwd(),zt=o=>ne(null,null,function*(){let m;try{D("esbuild-register");}catch(R){throw R}let e=F__default.default.join(ue,"openapi.sync.js"),C=F__default.default.join(ue,"openapi.sync.ts"),A=F__default.default.join(ue,"openapi.sync.json"),b=[e,C,A];try{for(let R of b)M__default.default.existsSync(R)&&(m=D(R),Object.keys(m).length===1&&m.default&&(m=m.default));}catch(R){console.log(R);}typeof m=="function"&&(m=m());let u=m;if(!u)throw new Error("No config found");let h=Object.keys(u.api),O=o&&"refetchInterval"in o&&!isNaN(o==null?void 0:o.refetchInterval)?o.refetchInterval:u.refetchInterval;De();for(let R=0;R<h.length;R+=1){let G=h[R],k=u.api[G];tt(k,G,u,O);}});exports.Init=zt;exports.JSONStringify=_;exports.capitalize=V;exports.getEndpointDetails=Qe;exports.getNestedValue=Ot;exports.isJson=Ye;exports.isYamlString=ot;exports.renderTypeRefMD=ae;exports.variableName=ft;exports.variableNameChar=We;exports.yamlStringToJson=Ge;
65
+ `:""}${Q}`,e);}}),ot=nt;var he=process.cwd(),Vt=n=>g(null,null,function*(){let i;try{X("esbuild-register");}catch(E){throw E}let e=B__default.default.join(he,"openapi.sync.js"),O=B__default.default.join(he,"openapi.sync.ts"),$=B__default.default.join(he,"openapi.sync.json"),C=[e,O,$];try{for(let E of C)L__default.default.existsSync(E)&&(i=X(E),Object.keys(i).length===1&&i.default&&(i=i.default));}catch(E){console.log(E);}typeof i=="function"&&(i=i());let o=i;if(!o)throw new Error("No config found");let p=Object.keys(o.api),f=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:o.refetchInterval;tt();for(let E=0;E<p.length;E+=1){let k=p[E],M=o.api[k];ot(M,k,o,f);}});exports.Init=Vt;exports.JSONStringify=_;exports.capitalize=W;exports.createCustomCodeMarker=Qe;exports.extractCustomCode=dt;exports.getEndpointDetails=He;exports.getNestedValue=xt;exports.isJson=Ze;exports.isYamlString=pt;exports.mergeCustomCode=Xe;exports.renderTypeRefMD=le;exports.variableName=Ot;exports.variableNameChar=Ye;exports.yamlStringToJson=De;
package/dist/index.mjs CHANGED
@@ -1,47 +1,65 @@
1
- import {a as a$1,c,f,e,d,g}from'./chunk-ALDCDVEN.mjs';export{f as JSONStringify,d as capitalize,e as getEndpointDetails,h as getNestedValue,a as isJson,b as isYamlString,g as renderTypeRefMD,c as yamlStringToJson}from'./chunk-ALDCDVEN.mjs';import {a,b}from'./chunk-6GQNHE6A.mjs';export{c as variableName,d as variableNameChar}from'./chunk-6GQNHE6A.mjs';import F from'fs';import w from'path';import at from'lodash.isequal';import Ze from'lodash.get';import ot from'axios';import pt from'axios-retry';import it from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var se=w.join(__dirname,"../","../db.json");F.existsSync(se)||F.writeFileSync(se,"{}");var ie={};try{ie=a(se);}catch(I){ie={};}var D=ie||{},ze=I=>{F.writeFileSync(se,JSON.stringify(I));},Ye=(I,j)=>{D[I]=j,ze(D);},He=I=>D[I],Xe=()=>{D={},ze(D);};var _=process.cwd(),le={},De=ot.create({timeout:6e4});pt(De,{retries:20,retryCondition:I=>I.code==="ECONNABORTED"||I.message.includes("Network Error"),retryDelay:I=>I*1e3});var _e=(I,j,e$1,M)=>b(null,null,function*(){var $e,he,fe,Oe,Ie,je;let W=yield De.get(I),ne=a$1(W.data)?W.data:c(W.data),f$1;try{f$1=yield it.parse(ne);}catch(s){let r=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${j}: ${r}`)}let U=w.join((e$1==null?void 0:e$1.folder)||"",j),P={},T=s=>{var r,$;if((r=e$1==null?void 0:e$1.folderSplit)!=null&&r.customFolder){let u=e$1.folderSplit.customFolder(s);if(console.log("customFolder",u),u)return u}return ($=e$1==null?void 0:e$1.folderSplit)!=null&&$.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},G=typeof(e$1==null?void 0:e$1.server)=="string"?e$1==null?void 0:e$1.server:((he=($e=f$1==null?void 0:f$1.servers)==null?void 0:$e[(e$1==null?void 0:e$1.server)||0])==null?void 0:he.url)||"",R=typeof((Oe=(fe=e$1==null?void 0:e$1.types)==null?void 0:fe.name)==null?void 0:Oe.prefix)=="string"?e$1==null?void 0:e$1.types.name.prefix:"I",et=typeof((je=(Ie=e$1==null?void 0:e$1.endpoints)==null?void 0:Ie.name)==null?void 0:je.prefix)=="string"?e$1==null?void 0:e$1.endpoints.name.prefix:"",ue=(s,r)=>{var u,n;let $=d(s);if((n=(u=e$1==null?void 0:e$1.types)==null?void 0:u.name)!=null&&n.format){let p=e$1==null?void 0:e$1.types.name.format("shared",{name:s},$);if(p)return `${R}${p}`}return `${R}${$}`},q=(s,r,$,u,n,p=0)=>{let y="",a="",o="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let i=(r.$ref||"").split("/");i.shift(),[...i].pop();let c=Ze(s,i,null);if(c){c!=null&&c.name&&(y=c.name),a=i[i.length-1];let A=ue(a);A.includes(".")&&(A=A.split(".").map((k,K)=>K===0?k:`["${k}"]`).join("")),o+=`${n!=null&&n.noSharedImport?"":"Shared."}${A}`;}}else o+="";else if(r.anyOf)o+=`(${r.anyOf.map(i=>q(s,i,"",u,n)).filter(i=>!!i).join("|")})`;else if(r.oneOf)o+=`(${r.oneOf.map(i=>q(s,i,"",u,n)).filter(i=>!!i).join("|")})`;else if(r.allOf)o+=`(${r.allOf.map(i=>q(s,i,"",u,n)).filter(i=>!!i).join("&")})`;else if(r.items)o+=`${q(s,r.items,"",false,n)}[]`;else if(r.properties){let i=Object.keys(r.properties),h=r.required||[],C="";i.forEach(c=>{var z,k,K,V,g,Y;let A="";!((k=(z=e$1==null?void 0:e$1.types)==null?void 0:z.doc)!=null&&k.disable)&&((V=(K=r.properties)==null?void 0:K[c])!=null&&V.description)&&(A=" * "+((g=r.properties)==null?void 0:g[c].description.split(`
2
- `).filter(ee=>ee.trim()!=="").join(`
3
- *${" ".repeat(1)}`))),C+=(A?`/**
4
- ${A}
1
+ import L from'fs';import B from'path';import*as ee from'js-yaml';import ut from'lodash.isequal';import rt from'lodash.get';import yt from'axios';import ct from'axios-retry';import ht from'@apidevtools/swagger-parser';import {CurlGenerator}from'curl-generator';var X=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(i,e)=>(typeof require!="undefined"?require:i)[e]}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var g=(n,i,e)=>new Promise((O,$)=>{var C=f=>{try{p(e.next(f));}catch(E){$(E);}},o=f=>{try{p(e.throw(f));}catch(E){$(E);}},p=f=>f.done?O(f.value):Promise.resolve(f.value).then(C,o);p((e=e.apply(n,i)).next());});var Ot=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Ye=/[A-Za-z0-9_$]/;var Ze=n=>["object"].includes(typeof n)&&!(n instanceof Blob),pt=n=>{try{return ee.load(n),!0}catch(i){let e=i;if(e instanceof ee.YAMLException)return false;throw e}},De=n=>{if(pt(n)){let i=ee.load(n),e=JSON.stringify(i,null,2);return JSON.parse(e)}},W=n=>n.substring(0,1).toUpperCase()+n.substring(1),He=(n,i)=>{let e=n.split("/"),O=`${W(i)}`,$=[];return e.forEach(C=>{if(C[0]==="{"&&C[C.length-1]==="}"){let p=C.replace(/{/,"").replace(/}/,"");$.push(p),C=`$${p}`;}else if(C[0]==="<"&&C[C.length-1]===">"){let p=C.replace(/</,"").replace(/>/,"");$.push(p),C=`$${p}`;}else if(C[0]===":"){let p=C.replace(/:/,"");$.push(p),C=`$${p}`;}let o="";C.split("").forEach(p=>{let f=p;Ye.test(p)||(f="/"),o+=f;}),o.split("/").forEach(p=>{O+=W(p);});}),{name:O,variables:$,pathParts:e}},_=(n,i=1)=>{let e="{",O=Object.keys(n);for(let $=0;$<O.length;$++){let C=O[$],o=n[C];if(e+=`
2
+ `+" ".repeat(i)+C+": ",Array.isArray(o)){e+="[";for(let p=0;p<o.length;p++){let f=o[p];typeof f=="object"&&f!==null?e+=_(f,i+1):e+=typeof f=="string"?`"${f}"`:f,p<o.length-1&&(e+=", ");}e+="]";}else typeof o=="object"&&o!==null?e+=""+_(o,i+1):e+=o.split(`
3
+ `).filter(p=>p.trim()!=="").join(`
4
+ ${" ".repeat(i)}`);$<O.length-1&&(e+=", ");}return e+=`
5
+ ${" ".repeat(i-1)}}`,e},le=(n,i=1)=>`
6
+ \`\`\`typescript
7
+ ${" ".repeat(i)} ${n.split(`
8
+ `).filter(e=>e.trim()!=="").join(`
9
+ ${" ".repeat(i)} `)}
10
+ \`\`\``;function xt(n,i){return i.split(".").reduce((O,$)=>O&&O[$]!==void 0?O[$]:void 0,n)}var dt=(n,i="CUSTOM CODE")=>{let e=`// \u{1F512} ${i} START`,O=`// \u{1F512} ${i} END`,$={beforeGenerated:"",afterGenerated:""},C=0,o=[];for(;C<n.length;){let p=n.indexOf(e,C);if(p===-1)break;let f=n.indexOf(O,p);if(f===-1)break;let E=f+O.length,k=p,ne=n.substring(Math.max(0,p-200),p).lastIndexOf("// ==========");ne!==-1&&(k=Math.max(0,p-200)+ne);let oe=n.substring(k,E);o.push({start:k,end:E,content:oe}),C=E;}return o.length>0&&(n.substring(0,o[0].start).split(`
11
+ `).filter(E=>{let k=E.trim();return k.length>0&&!k.startsWith("//")}).join("").length===0?($.beforeGenerated=o[0].content,o.length>1&&($.afterGenerated=o[1].content)):($.afterGenerated=o[0].content,o.length>1&&!$.beforeGenerated&&($.beforeGenerated=o[1].content))),$},Qe=(n,i="CUSTOM CODE",e=true)=>{let O=e?`// ${n==="top"?"Add your custom code below this line":"Add your custom code above this line"}
12
+ // This section will be preserved during regeneration
13
+ `:"";return `// ${"=".repeat(60)}
14
+ // \u{1F512} ${i} START
15
+ ${O}// ${"=".repeat(60)}
16
+
17
+ // \u{1F512} ${i} END
18
+ // ${"=".repeat(60)}`},Xe=(n,i,e={})=>{let{position:O="bottom",markerText:$="CUSTOM CODE",includeInstructions:C=true}=e,o={beforeGenerated:"",afterGenerated:""};i&&(o=dt(i,$)),!o.beforeGenerated&&!o.afterGenerated&&((O==="top"||O==="both")&&(o.beforeGenerated=Qe("top",$,C)),(O==="bottom"||O==="both")&&(o.afterGenerated=Qe("bottom",$,C)));let p=[];return o.beforeGenerated&&(p.push(o.beforeGenerated),p.push("")),p.push(n),o.afterGenerated&&(p.push(""),p.push(o.afterGenerated)),p.join(`
19
+ `)};var pe=B.join(__dirname,"../","../db.json");L.existsSync(pe)||L.writeFileSync(pe,"{}");var ue={};try{ue=X(pe);}catch(n){ue={};}var te=ue||{},ge=n=>{L.writeFileSync(pe,JSON.stringify(n));},_e=(n,i)=>{te[n]=i,ge(te);},et=n=>te[n],tt=()=>{te={},ge(te);};var re=process.cwd(),ye={},st=yt.create({timeout:6e4});ct(st,{retries:20,retryCondition:n=>n.code==="ECONNABORTED"||n.message.includes("Network Error"),retryDelay:n=>n*1e3});var se=(n,i,e)=>g(null,null,function*(){var o,p,f,E;if(!(((o=e==null?void 0:e.customCode)==null?void 0:o.enabled)!==false)){yield L.promises.writeFile(n,i);return}let $=null;try{$=yield L.promises.readFile(n,"utf-8");}catch(k){}let C=Xe(i,$,{position:((p=e==null?void 0:e.customCode)==null?void 0:p.position)||"bottom",markerText:(f=e==null?void 0:e.customCode)==null?void 0:f.markerText,includeInstructions:(E=e==null?void 0:e.customCode)==null?void 0:E.includeInstructions});yield L.promises.writeFile(n,C);}),nt=(n,i,e,O)=>g(null,null,function*(){var fe,be,Oe,Ce,Ie,xe;let $=yield st.get(n),C=Ze($.data)?$.data:De($.data),o;try{o=yield ht.parse(C);}catch(s){let r=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse OpenAPI spec for ${i}: ${r}`)}let p=B.join((e==null?void 0:e.folder)||"",i),f={},E=s=>{var r,x;if((r=e==null?void 0:e.folderSplit)!=null&&r.customFolder){let b=e.folderSplit.customFolder(s);if(console.log("customFolder",b),b)return b}return (x=e==null?void 0:e.folderSplit)!=null&&x.byTags&&s.tags&&s.tags.length>0?s.tags[0].toLowerCase().replace(/\s+/g,"-"):"default"},k=typeof(e==null?void 0:e.server)=="string"?e==null?void 0:e.server:((be=(fe=o==null?void 0:o.servers)==null?void 0:fe[(e==null?void 0:e.server)||0])==null?void 0:be.url)||"",M=typeof((Ce=(Oe=e==null?void 0:e.types)==null?void 0:Oe.name)==null?void 0:Ce.prefix)=="string"?e==null?void 0:e.types.name.prefix:"I",ne=typeof((xe=(Ie=e==null?void 0:e.endpoints)==null?void 0:Ie.name)==null?void 0:xe.prefix)=="string"?e==null?void 0:e.endpoints.name.prefix:"",oe=(s,r)=>{var b,a;let x=W(s);if((a=(b=e==null?void 0:e.types)==null?void 0:b.name)!=null&&a.format){let m=e==null?void 0:e.types.name.format("shared",{name:s},x);if(m)return `${M}${m}`}return `${M}${x}`},q=(s,r,x,b,a,m=0)=>{let I="",l="",d="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let u=(r.$ref||"").split("/");u.shift(),[...u].pop();let w=rt(s,u,null);if(w){w!=null&&w.name&&(I=w.name),l=u[u.length-1];let N=oe(l);N.includes(".")&&(N=N.split(".").map((U,K)=>K===0?U:`["${U}"]`).join("")),d+=`${a!=null&&a.noSharedImport?"":"Shared."}${N}`;}}else d+="";else if(r.anyOf)d+=`(${r.anyOf.map(u=>q(s,u,"",b,a)).filter(u=>!!u).join("|")})`;else if(r.oneOf)d+=`(${r.oneOf.map(u=>q(s,u,"",b,a)).filter(u=>!!u).join("|")})`;else if(r.allOf)d+=`(${r.allOf.map(u=>q(s,u,"",b,a)).filter(u=>!!u).join("&")})`;else if(r.items)d+=`${q(s,r.items,"",false,a)}[]`;else if(r.properties){let u=Object.keys(r.properties),j=r.required||[],S="";u.forEach(w=>{var Z,U,K,Y,ae,D;let N="";!((U=(Z=e==null?void 0:e.types)==null?void 0:Z.doc)!=null&&U.disable)&&((Y=(K=r.properties)==null?void 0:K[w])!=null&&Y.description)&&(N=" * "+((ae=r.properties)==null?void 0:ae[w].description.split(`
20
+ `).filter(ie=>ie.trim()!=="").join(`
21
+ *${" ".repeat(1)}`))),S+=(N?`/**
22
+ ${N}
5
23
  */
6
- `:"")+`${q(s,(Y=r.properties)==null?void 0:Y[c],c,h.includes(c),n,p+1)}`;}),C.length>0?o+=`{
7
- ${" ".repeat(p)}${C}${" ".repeat(p)}}`:o+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(o+="("),r.enum.map(i=>JSON.stringify(i)).filter(i=>!!i).forEach((i,h)=>{o+=`${h===0?"":"|"}${i}`;}),r.enum.length>1&&(o+=")");else if(r.type){let i=h=>{let C="";if(typeof h=="string")["string","integer","number","array","boolean","null"].includes(h)?["integer","number"].includes(h)?C+="number":h==="array"?C+="any[]":C+=h:h==="object"&&(r.additionalProperties?C+=`{[k: string]: ${q(s,r.additionalProperties,"",true,n)||"any"}}`:C+="{[k: string]: any}");else if(Array.isArray(h)){let c=h.map(A=>i(A));c.filter(A=>A!==""),c.length>1&&(C+="("+c.join("|")+")");}else C+="any";return C};o=i(r.type);}}else o="string";let m=y||$;n!=null&&n.useComponentName&&!m&&(m=a);let b=m?` "${m}"${u?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return o.length>0?`${b}${o}${t}${m?`;
8
- `:""}`:""},J=(s,r)=>{let n="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let p=(r.$ref||"").split("/");p.shift();let a=Ze(s,p,null);a&&(a!=null&&a.name&&(a.name),p[p.length-1],n+=J(s,a));}else n+="";else if(r.anyOf)n+=J(s,r.anyOf[0]);else if(r.oneOf)n+=J(s,r.oneOf[0]);else if(r.allOf)n+=`{${r.allOf.map(p=>`...(${J(s,p)})`).join(",")}}`;else if(r.items)n+=`[${J(s,r.items)}]`;else if(r.properties){let a=Object.keys(r.properties).map(o=>{var m;return ` "${o}": ${J(s,(m=r.properties)==null?void 0:m[o])}`}).join(`,
9
- `);a.length>0?n+=`{
10
- ${a}
11
- }`:n+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(n+=r.enum[0]);else if(r.type)if(r.example)n+=JSON.stringify(r.example);else {let p=y=>{let a="";if(typeof y=="string")["string","integer","number","array","boolean","null"].includes(y)?["integer","number"].includes(y)?a+="123":y==="array"?a+="[]":y==="boolean"?a+="true":y==="null"?a+="null":a+=`"${y}"`:y==="object"&&(a+="{}");else if(Array.isArray(y)){let o=y.map(m=>p(m));o.filter(m=>m!==""),o.length>1&&(a+=o.join("|"));}else a+="any";return a};n=p(r.type);}}else n="string";return n};M&&!isNaN(M)&&M>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(le[j]&&clearTimeout(le[j]),le[j]=setTimeout(()=>_e(I,j,e$1,M),M)));let tt=He(j);if(at(tt,f$1))return;Ye(j,f$1);let ae="",Q="",L={};f$1.components&&Object.keys(f$1.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=f$1.components[s],$={},u={};Object.keys(r).forEach(p=>{var o;let y=(o=r[p])!=null&&o.schema?r[p].schema:r[p],a=`${q(f$1,y,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(s)})}`;if(a){let m=p.split("."),b=$,t=u;for(let i=0;i<m.length;i++){let h=m[i];i<m.length-1?(h in b||(b[h]={},t[h]={}),b=b[h],t=t[h]):(b[h]=a,t[h]=y);}}}),Object.keys($).forEach(p=>{var m,b,t,i;let y=ue(p),a=$[p],o="";!((b=(m=e$1==null?void 0:e$1.types)==null?void 0:m.doc)!=null&&b.disable)&&p in r&&((t=r[p])!=null&&t.description)&&(o=" * "+r[p].description.split(`
12
- `).filter(h=>h.trim()!=="").join(`
13
- *${" ".repeat(1)}`)),L[p]=((i=L[p])!=null?i:"")+(o?`/**
14
- ${o}
24
+ `:"")+`${q(s,(D=r.properties)==null?void 0:D[w],w,j.includes(w),a,m+1)}`;}),S.length>0?d+=`{
25
+ ${" ".repeat(m)}${S}${" ".repeat(m)}}`:d+="{[k: string]: any}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(d+="("),r.enum.map(u=>JSON.stringify(u)).filter(u=>!!u).forEach((u,j)=>{d+=`${j===0?"":"|"}${u}`;}),r.enum.length>1&&(d+=")");else if(r.type){let u=j=>{let S="";if(typeof j=="string")["string","integer","number","array","boolean","null"].includes(j)?["integer","number"].includes(j)?S+="number":j==="array"?S+="any[]":S+=j:j==="object"&&(r.additionalProperties?S+=`{[k: string]: ${q(s,r.additionalProperties,"",true,a)||"any"}}`:S+="{[k: string]: any}");else if(Array.isArray(j)){let w=j.map(N=>u(N));w.filter(N=>N!==""),w.length>1&&(S+="("+w.join("|")+")");}else S+="any";return S};d=u(r.type);}}else d="string";let c=I||x;a!=null&&a.useComponentName&&!c&&(c=l);let T=c?` "${c}"${b?"":"?"}: `:"",t=r!=null&&r.nullable?" | null":"";return d.length>0?`${T}${d}${t}${c?`;
26
+ `:""}`:""},z=(s,r)=>{let a="";if(r){if(r.$ref)if(r.$ref[0]==="#"){let m=(r.$ref||"").split("/");m.shift();let l=rt(s,m,null);l&&(l!=null&&l.name&&(l.name),m[m.length-1],a+=z(s,l));}else a+="";else if(r.anyOf)a+=z(s,r.anyOf[0]);else if(r.oneOf)a+=z(s,r.oneOf[0]);else if(r.allOf)a+=`{${r.allOf.map(m=>`...(${z(s,m)})`).join(",")}}`;else if(r.items)a+=`[${z(s,r.items)}]`;else if(r.properties){let l=Object.keys(r.properties).map(d=>{var c;return ` "${d}": ${z(s,(c=r.properties)==null?void 0:c[d])}`}).join(`,
27
+ `);l.length>0?a+=`{
28
+ ${l}
29
+ }`:a+="{}";}else if(r.enum&&r.enum.length>0)r.enum.length>1&&(a+=r.enum[0]);else if(r.type)if(r.example)a+=JSON.stringify(r.example);else {let m=I=>{let l="";if(typeof I=="string")["string","integer","number","array","boolean","null"].includes(I)?["integer","number"].includes(I)?l+="123":I==="array"?l+="[]":I==="boolean"?l+="true":I==="null"?l+="null":l+=`"${I}"`:I==="object"&&(l+="{}");else if(Array.isArray(I)){let d=I.map(c=>m(c));d.filter(c=>c!==""),d.length>1&&(l+=d.join("|"));}else l+="any";return l};a=m(r.type);}}else a="string";return a};O&&!isNaN(O)&&O>0&&(process.env.NODE_ENV&&["production","prod","test","staging"].includes(process.env.NODE_ENV)||(ye[i]&&clearTimeout(ye[i]),ye[i]=setTimeout(()=>nt(n,i,e,O),O)));let at=et(i);if(ut(at,o))return;_e(i,o);let de="",Q="",V={};o.components&&Object.keys(o.components).forEach(s=>{if(["schemas","responses","parameters","examples","requestBodies","headers","links","callbacks"].includes(s)){let r=o.components[s],x={},b={};Object.keys(r).forEach(m=>{var d;let I=(d=r[m])!=null&&d.schema?r[m].schema:r[m],l=`${q(o,I,"",true,{noSharedImport:true,useComponentName:["parameters"].includes(s)})}`;if(l){let c=m.split("."),T=x,t=b;for(let u=0;u<c.length;u++){let j=c[u];u<c.length-1?(j in T||(T[j]={},t[j]={}),T=T[j],t=t[j]):(T[j]=l,t[j]=I);}}}),Object.keys(x).forEach(m=>{var c,T,t,u;let I=oe(m),l=x[m],d="";!((T=(c=e==null?void 0:e.types)==null?void 0:c.doc)!=null&&T.disable)&&m in r&&((t=r[m])!=null&&t.description)&&(d=" * "+r[m].description.split(`
30
+ `).filter(j=>j.trim()!=="").join(`
31
+ *${" ".repeat(1)}`)),V[m]=((u=V[m])!=null?u:"")+(d?`/**
32
+ ${d}
15
33
  */
16
- `:"")+"export type "+y+" = "+(typeof a=="string"?a:f(a))+`;
17
- `;});}});let ye=s=>{let r="";if(s.content){let $=Object.keys(s.content);$[0]&&s.content[$[0]].schema&&(r+=`${q(f$1,s.content[$[0]].schema,"")}`);}return r},rt=s=>{var r,$,u,n,p;if(($=(r=e$1==null?void 0:e$1.endpoints)==null?void 0:r.value)!=null&&$.replaceWords&&Array.isArray(e$1==null?void 0:e$1.endpoints.value.replaceWords)){let y=s;return (p=(n=(u=e$1==null?void 0:e$1.endpoints)==null?void 0:u.value)==null?void 0:n.replaceWords)==null||p.forEach((a,o)=>{let m=new RegExp(a.replace,"g");y=y.replace(m,a.with||"");}),y}else return s},st=(s,r,$=[])=>{var p,y;let u=(p=e$1==null?void 0:e$1.endpoints)==null?void 0:p.exclude,n=(y=e$1==null?void 0:e$1.endpoints)==null?void 0:y.include;if(n){let a=n.tags&&n.tags.length>0?$.some(m=>n.tags.includes(m)):true,o=n.endpoints&&n.endpoints.length>0?n.endpoints.some(m=>{let b=!m.method||m.method.toLowerCase()===r.toLowerCase();return m.path?s===m.path&&b:m.regex?new RegExp(m.regex).test(s)&&b:false}):true;if(!a||!o)return true}return !!(u&&(u.tags&&u.tags.length>0&&$.some(o=>u.tags.includes(o))||u.endpoints&&u.endpoints.length>0&&u.endpoints.some(o=>{let m=!o.method||o.method.toLowerCase()===r.toLowerCase();return o.path?s===o.path&&m:o.regex?new RegExp(o.regex).test(s)&&m:false})))};if(Object.keys(f$1.paths||{}).forEach(s=>{let r=f$1.paths[s];Object.keys(r).forEach(u=>{var ee,be,Ce,ce,Ae,xe,Ee,Te,we,Se,Re,ve,Ne,Fe,Pe,qe,ke,Be,Me,Ue,Je,Ke,Le,Ve;let n=u,p=e(s,n),y=((ee=r[n])==null?void 0:ee.tags)||[];if(st(s,n,y))return;let a=r[n],o=T({method:n,path:s,summary:a==null?void 0:a.summary,operationId:a==null?void 0:a.operationId,tags:y,parameters:a==null?void 0:a.parameters,requestBody:a==null?void 0:a.requestBody,responses:a==null?void 0:a.responses});P[o]||(P[o]={endpoints:"",types:""});let m=((Ce=(be=e$1==null?void 0:e$1.endpoints)==null?void 0:be.value)!=null&&Ce.includeServer?G:"")+p.pathParts.map(d=>(d[0]==="{"&&d[d.length-1]==="}"?d=`\${${d.replace(/{/,"").replace(/}/,"")}}`:d[0]==="<"&&d[d.length-1]===">"?d=`\${${d.replace(/</,"").replace(/>/,"")}}`:d[0]===":"&&(d=`\${${d.replace(/:/,"")}}`),d)).join("/"),b=`"${m}"`;p.variables.length>0&&(b=`(${p.variables.map(l=>`${l}:string`).join(",")})=> \`${m}\``),b=rt(b);let t=r[n],i="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((l,x)=>{(l.$ref||l.in==="query"&&l.name)&&(i+=`${q(f$1,l.$ref?l:l.schema,l.name||"",l.required)}`);}),i)){i=`{
18
- ${i}}`;let l=`${p.name}Query`;if((Ae=(ce=e$1==null?void 0:e$1.types)==null?void 0:ce.name)!=null&&Ae.useOperationId&&(t!=null&&t.operationId)&&(l=`${t.operationId}Query`),l=d(`${R}${l}`),(Ee=(xe=e$1==null?void 0:e$1.types)==null?void 0:xe.name)!=null&&Ee.format){let v=e$1==null?void 0:e$1.types.name.format("endpoint",{code:"",type:"query",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},l);v&&(l=`${R}${v}`);}let x=`export type ${l} = ${i};
19
- `;e$1!=null&&e$1.folderSplit?P[o].types+=x:Q+=x;}let h=t==null?void 0:t.requestBody,C="";if(h&&(C=ye(h),C)){let d$1=`${p.name}DTO`;if((we=(Te=e$1==null?void 0:e$1.types)==null?void 0:Te.name)!=null&&we.useOperationId&&(t!=null&&t.operationId)&&(d$1=`${t.operationId}DTO`),d$1=d(`${R}${d$1}`),(Re=(Se=e$1==null?void 0:e$1.types)==null?void 0:Se.name)!=null&&Re.format){let x=e$1==null?void 0:e$1.types.name.format("endpoint",{code:"",type:"dto",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},d$1);x&&(d$1=`${R}${x}`);}let l=`export type ${d$1} = ${C};
20
- `;e$1!=null&&e$1.folderSplit?P[o].types+=l:Q+=l;}let c={},A="";if(t!=null&&t.responses){let d$1=t==null?void 0:t.responses;Object.keys(d$1).forEach(x=>{var v,N,E,S;if(A=ye(d$1[x]),c[x]=A,A){let O=`${p.name}${x}Response`;if((N=(v=e$1==null?void 0:e$1.types)==null?void 0:v.name)!=null&&N.useOperationId&&(t!=null&&t.operationId)&&(O=`${t.operationId}${x}Response`),O=d(`${R}${O}`),(S=(E=e$1==null?void 0:e$1.types)==null?void 0:E.name)!=null&&S.format){let H=e$1==null?void 0:e$1.types.name.format("endpoint",{code:x,type:"response",method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},O);H&&(O=`${R}${H}`);}let B=`export type ${O} = ${A};
21
- `;e$1!=null&&e$1.folderSplit?P[o].types+=B:Q+=B;}});}let z=d=>!d||!d.length?"":d.map(l=>Object.entries(l).map(([v,N])=>{let E=v,S="";return Array.isArray(N)&&N.length&&(S=`
22
- - Scopes: [\`${N.join("`, `")}\`]`,E=`**${E}**`),`
23
- - ${E}${S}`}).join("")).join(`
24
- `),k=t!=null&&t.security?z(t.security):"",K="";if(!((Ne=(ve=e$1==null?void 0:e$1.endpoints)==null?void 0:ve.doc)!=null&&Ne.disable)){let d="";if((Pe=(Fe=e$1==null?void 0:e$1.endpoints)==null?void 0:Fe.doc)!=null&&Pe.showCurl){let l={},x="",v="";(qe=t.requestBody)!=null&&qe.content&&Object.keys(t.requestBody.content).forEach(S=>{let O=t.requestBody.content[S].schema;if(O){Array.isArray(l["Content-type"])?l["Content-type"].push(S):l["Content-type"]=[S];let B=J(f$1,O);B&&(x=B);}}),t!=null&&t.security&&t.security.forEach(E=>{Object.keys(E).forEach(S=>{var B,H;let O=(H=(B=f$1.components)==null?void 0:B.securitySchemes)==null?void 0:H[S];O&&(O.type==="mutualTLS"?v+=`
25
- --cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:O.type==="apiKey"?l[(O==null?void 0:O.name)||"X-API-KEY"]="{API_KEY_VALUE}":l.Authorization=`${(O==null?void 0:O.scheme)==="basic"?"Basic":"Bearer"} {${(O==null?void 0:O.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let N={};Object.keys(l).forEach(E=>{Array.isArray(l[E])?N[E]=l[E].join("; "):N[E]=l[E];}),d=`
34
+ `:"")+"export type "+I+" = "+(typeof l=="string"?l:_(l))+`;
35
+ `;});}});let $e=s=>{let r="";if(s.content){let x=Object.keys(s.content);x[0]&&s.content[x[0]].schema&&(r+=`${q(o,s.content[x[0]].schema,"")}`);}return r},it=s=>{var r,x,b,a,m;if((x=(r=e==null?void 0:e.endpoints)==null?void 0:r.value)!=null&&x.replaceWords&&Array.isArray(e==null?void 0:e.endpoints.value.replaceWords)){let I=s;return (m=(a=(b=e==null?void 0:e.endpoints)==null?void 0:b.value)==null?void 0:a.replaceWords)==null||m.forEach((l,d)=>{let c=new RegExp(l.replace,"g");I=I.replace(c,l.with||"");}),I}else return s},lt=(s,r,x=[])=>{var m,I;let b=(m=e==null?void 0:e.endpoints)==null?void 0:m.exclude,a=(I=e==null?void 0:e.endpoints)==null?void 0:I.include;if(a){let l=a.tags&&a.tags.length>0?x.some(c=>a.tags.includes(c)):true,d=a.endpoints&&a.endpoints.length>0?a.endpoints.some(c=>{let T=!c.method||c.method.toLowerCase()===r.toLowerCase();return c.path?s===c.path&&T:c.regex?new RegExp(c.regex).test(s)&&T:false}):true;if(!l||!d)return true}return !!(b&&(b.tags&&b.tags.length>0&&x.some(d=>b.tags.includes(d))||b.endpoints&&b.endpoints.length>0&&b.endpoints.some(d=>{let c=!d.method||d.method.toLowerCase()===r.toLowerCase();return d.path?s===d.path&&c:d.regex?new RegExp(d.regex).test(s)&&c:false})))};if(Object.keys(o.paths||{}).forEach(s=>{let r=o.paths[s];Object.keys(r).forEach(b=>{var ie,je,Ee,Ae,Te,Se,we,Ne,ve,Re,ke,Be,Me,Fe,Ge,Pe,qe,Ue,Je,Le,ze,Ke,We,Ve;let a=b,m=He(s,a),I=((ie=r[a])==null?void 0:ie.tags)||[];if(lt(s,a,I))return;let l=r[a],d=E({method:a,path:s,summary:l==null?void 0:l.summary,operationId:l==null?void 0:l.operationId,tags:I,parameters:l==null?void 0:l.parameters,requestBody:l==null?void 0:l.requestBody,responses:l==null?void 0:l.responses});f[d]||(f[d]={endpoints:"",types:""});let c=((Ee=(je=e==null?void 0:e.endpoints)==null?void 0:je.value)!=null&&Ee.includeServer?k:"")+m.pathParts.map(h=>(h[0]==="{"&&h[h.length-1]==="}"?h=`\${${h.replace(/{/,"").replace(/}/,"")}}`:h[0]==="<"&&h[h.length-1]===">"?h=`\${${h.replace(/</,"").replace(/>/,"")}}`:h[0]===":"&&(h=`\${${h.replace(/:/,"")}}`),h)).join("/"),T=`"${c}"`;m.variables.length>0&&(T=`(${m.variables.map(y=>`${y}:string`).join(",")})=> \`${c}\``),T=it(T);let t=r[a],u="";if(t!=null&&t.parameters&&((t==null?void 0:t.parameters).forEach((y,v)=>{(y.$ref||y.in==="query"&&y.name)&&(u+=`${q(o,y.$ref?y:y.schema,y.name||"",y.required)}`);}),u)){u=`{
36
+ ${u}}`;let y=`${m.name}Query`;if((Te=(Ae=e==null?void 0:e.types)==null?void 0:Ae.name)!=null&&Te.useOperationId&&(t!=null&&t.operationId)&&(y=`${t.operationId}Query`),y=W(`${M}${y}`),(we=(Se=e==null?void 0:e.types)==null?void 0:Se.name)!=null&&we.format){let G=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"query",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},y);G&&(y=`${M}${G}`);}let v=`export type ${y} = ${u};
37
+ `;e!=null&&e.folderSplit?f[d].types+=v:Q+=v;}let j=t==null?void 0:t.requestBody,S="";if(j&&(S=$e(j),S)){let h=`${m.name}DTO`;if((ve=(Ne=e==null?void 0:e.types)==null?void 0:Ne.name)!=null&&ve.useOperationId&&(t!=null&&t.operationId)&&(h=`${t.operationId}DTO`),h=W(`${M}${h}`),(ke=(Re=e==null?void 0:e.types)==null?void 0:Re.name)!=null&&ke.format){let v=e==null?void 0:e.types.name.format("endpoint",{code:"",type:"dto",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},h);v&&(h=`${M}${v}`);}let y=`export type ${h} = ${S};
38
+ `;e!=null&&e.folderSplit?f[d].types+=y:Q+=y;}let w={},N="";if(t!=null&&t.responses){let h=t==null?void 0:t.responses;Object.keys(h).forEach(v=>{var G,P,R,F;if(N=$e(h[v]),w[v]=N,N){let A=`${m.name}${v}Response`;if((P=(G=e==null?void 0:e.types)==null?void 0:G.name)!=null&&P.useOperationId&&(t!=null&&t.operationId)&&(A=`${t.operationId}${v}Response`),A=W(`${M}${A}`),(F=(R=e==null?void 0:e.types)==null?void 0:R.name)!=null&&F.format){let H=e==null?void 0:e.types.name.format("endpoint",{code:v,type:"response",method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},A);H&&(A=`${M}${H}`);}let J=`export type ${A} = ${N};
39
+ `;e!=null&&e.folderSplit?f[d].types+=J:Q+=J;}});}let Z=h=>!h||!h.length?"":h.map(y=>Object.entries(y).map(([G,P])=>{let R=G,F="";return Array.isArray(P)&&P.length&&(F=`
40
+ - Scopes: [\`${P.join("`, `")}\`]`,R=`**${R}**`),`
41
+ - ${R}${F}`}).join("")).join(`
42
+ `),U=t!=null&&t.security?Z(t.security):"",K="";if(!((Me=(Be=e==null?void 0:e.endpoints)==null?void 0:Be.doc)!=null&&Me.disable)){let h="";if((Ge=(Fe=e==null?void 0:e.endpoints)==null?void 0:Fe.doc)!=null&&Ge.showCurl){let y={},v="",G="";(Pe=t.requestBody)!=null&&Pe.content&&Object.keys(t.requestBody.content).forEach(F=>{let A=t.requestBody.content[F].schema;if(A){Array.isArray(y["Content-type"])?y["Content-type"].push(F):y["Content-type"]=[F];let J=z(o,A);J&&(v=J);}}),t!=null&&t.security&&t.security.forEach(R=>{Object.keys(R).forEach(F=>{var J,H;let A=(H=(J=o.components)==null?void 0:J.securitySchemes)==null?void 0:H[F];A&&(A.type==="mutualTLS"?G+=`
43
+ --cert client-certificate.crt --key client-private-key.key --cacert ca-certificate.crt`:A.type==="apiKey"?y[(A==null?void 0:A.name)||"X-API-KEY"]="{API_KEY_VALUE}":y.Authorization=`${(A==null?void 0:A.scheme)==="basic"?"Basic":"Bearer"} {${(A==null?void 0:A.scheme)==="basic"?"VALUE":"TOKEN"}}`);});});let P={};Object.keys(y).forEach(R=>{Array.isArray(y[R])?P[R]=y[R].join("; "):P[R]=y[R];}),h=`
26
44
  \`\`\`bash
27
- ${CurlGenerator({url:G+s,method:n.toUpperCase(),headers:N,body:x})}${v}
45
+ ${CurlGenerator({url:k+s,method:a.toUpperCase(),headers:P,body:v})}${G}
28
46
  \`\`\``;}K=`/**${t!=null&&t.description?`
29
47
  * ${t==null?void 0:t.description} `:""}
30
- * **Method**: \`${n.toUpperCase()}\`
48
+ * **Method**: \`${a.toUpperCase()}\`
31
49
  * **Summary**: ${(t==null?void 0:t.summary)||""}
32
- * **Tags**: [${((ke=t==null?void 0:t.tags)==null?void 0:ke.join(", "))||""}]
33
- * **OperationId**: ${(t==null?void 0:t.operationId)||""} ${i?`
34
- * **Query**: ${g(i)} `:""}${C?`
35
- * **DTO**: ${g(C)} `:""}${A?`
36
- * **Response**: ${Object.entries(c).map(([l,x])=>`
37
- - **${l}**: ${g(x,2)} `).join("")}`:""}${k?`
38
- * **Security**: ${k}
39
- `:""}${d}
50
+ * **Tags**: [${((qe=t==null?void 0:t.tags)==null?void 0:qe.join(", "))||""}]
51
+ * **OperationId**: ${(t==null?void 0:t.operationId)||""} ${u?`
52
+ * **Query**: ${le(u)} `:""}${S?`
53
+ * **DTO**: ${le(S)} `:""}${N?`
54
+ * **Response**: ${Object.entries(w).map(([y,v])=>`
55
+ - **${y}**: ${le(v,2)} `).join("")}`:""}${U?`
56
+ * **Security**: ${U}
57
+ `:""}${h}
40
58
  */
41
- `;}let V=(Me=(Be=e$1==null?void 0:e$1.endpoints)==null?void 0:Be.name)!=null&&Me.useOperationId&&((Ue=t==null?void 0:t.operationId)==null?void 0:Ue.length)>0?t.operationId:`${p.name}`;if((Ke=(Je=e$1==null?void 0:e$1.endpoints)==null?void 0:Je.name)!=null&&Ke.format){let d=e$1==null?void 0:e$1.endpoints.name.format({method:n,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},V);d&&(V=d);}let g$1={method:`"${n}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:b,tags:(t==null?void 0:t.tags)||[]},Y=`${K}export const ${et}${V} = ${((Ve=(Le=e$1==null?void 0:e$1.endpoints)==null?void 0:Le.value)==null?void 0:Ve.type)==="object"?f(g$1):b};
42
- `;e$1!=null&&e$1.folderSplit?P[o].endpoints+=Y:ae+=Y;});}),e$1!=null&&e$1.folderSplit){for(let[s,r]of Object.entries(P))if(r.endpoints||r.types){let $=w.join(U,s);if(r.endpoints){let u=w.join(_,$,"endpoints.ts");yield F.promises.mkdir(w.dirname(u),{recursive:true}),yield F.promises.writeFile(u,r.endpoints);}if(r.types){let u=w.join(_,$,"types.ts");yield F.promises.mkdir(w.dirname(u),{recursive:true});let n=Object.values(L).length>0?`import * as Shared from "../shared";
59
+ `;}let Y=(Je=(Ue=e==null?void 0:e.endpoints)==null?void 0:Ue.name)!=null&&Je.useOperationId&&((Le=t==null?void 0:t.operationId)==null?void 0:Le.length)>0?t.operationId:`${m.name}`;if((Ke=(ze=e==null?void 0:e.endpoints)==null?void 0:ze.name)!=null&&Ke.format){let h=e==null?void 0:e.endpoints.name.format({method:a,path:s,summary:t==null?void 0:t.summary,operationId:t==null?void 0:t.operationId},Y);h&&(Y=h);}let ae={method:`"${a}"`,operationId:`"${t==null?void 0:t.operationId}"`,url:T,tags:(t==null?void 0:t.tags)||[]},D=`${K}export const ${ne}${Y} = ${((Ve=(We=e==null?void 0:e.endpoints)==null?void 0:We.value)==null?void 0:Ve.type)==="object"?_(ae):T};
60
+ `;e!=null&&e.folderSplit?f[d].endpoints+=D:de+=D;});}),e!=null&&e.folderSplit){for(let[s,r]of Object.entries(f))if(r.endpoints||r.types){let x=B.join(p,s);if(r.endpoints){let b=B.join(re,x,"endpoints.ts");yield L.promises.mkdir(B.dirname(b),{recursive:true}),yield se(b,r.endpoints,e);}if(r.types){let b=B.join(re,x,"types.ts");yield L.promises.mkdir(B.dirname(b),{recursive:true});let a=Object.values(V).length>0?`import * as Shared from "../shared";
43
61
 
44
- ${r.types}`:r.types;yield F.promises.writeFile(u,n);}}}if(ae.length>0){let s=w.join(_,U,"endpoints.ts");yield F.promises.mkdir(w.dirname(s),{recursive:true}),yield F.promises.writeFile(s,ae);}if(Object.values(L).length>0){let s=w.join(_,U,e$1!=null&&e$1.folderSplit?"":"types","shared.ts");yield F.promises.mkdir(w.dirname(s),{recursive:true}),yield F.promises.writeFile(s,Object.values(L).join(`
45
- `));}if(Q.length>0){let s=w.join(_,U,"types","index.ts");yield F.promises.mkdir(w.dirname(s),{recursive:true}),yield F.promises.writeFile(s,`${Object.values(L).length>0?`import * as Shared from "./shared";
62
+ ${r.types}`:r.types;yield se(b,a,e);}}}if(de.length>0){let s=B.join(re,p,"endpoints.ts");yield L.promises.mkdir(B.dirname(s),{recursive:true}),yield se(s,de,e);}if(Object.values(V).length>0){let s=B.join(re,p,e!=null&&e.folderSplit?"":"types","shared.ts");yield L.promises.mkdir(B.dirname(s),{recursive:true}),yield se(s,Object.values(V).join(`
63
+ `),e);}if(Q.length>0){let s=B.join(re,p,"types","index.ts");yield L.promises.mkdir(B.dirname(s),{recursive:true}),yield se(s,`${Object.values(V).length>0?`import * as Shared from "./shared";
46
64
 
47
- `:""}${Q}`);}}),ge=_e;var de=process.cwd(),Bt=I=>b(null,null,function*(){let j;try{a("esbuild-register");}catch(T){throw T}let e=w.join(de,"openapi.sync.js"),M=w.join(de,"openapi.sync.ts"),W=w.join(de,"openapi.sync.json"),ne=[e,M,W];try{for(let T of ne)F.existsSync(T)&&(j=a(T),Object.keys(j).length===1&&j.default&&(j=j.default));}catch(T){console.log(T);}typeof j=="function"&&(j=j());let f=j;if(!f)throw new Error("No config found");let U=Object.keys(f.api),P=I&&"refetchInterval"in I&&!isNaN(I==null?void 0:I.refetchInterval)?I.refetchInterval:f.refetchInterval;Xe();for(let T=0;T<U.length;T+=1){let G=U[T],R=f.api[G];ge(R,G,f,P);}});export{Bt as Init};
65
+ `:""}${Q}`,e);}}),ot=nt;var he=process.cwd(),Vt=n=>g(null,null,function*(){let i;try{X("esbuild-register");}catch(E){throw E}let e=B.join(he,"openapi.sync.js"),O=B.join(he,"openapi.sync.ts"),$=B.join(he,"openapi.sync.json"),C=[e,O,$];try{for(let E of C)L.existsSync(E)&&(i=X(E),Object.keys(i).length===1&&i.default&&(i=i.default));}catch(E){console.log(E);}typeof i=="function"&&(i=i());let o=i;if(!o)throw new Error("No config found");let p=Object.keys(o.api),f=n&&"refetchInterval"in n&&!isNaN(n==null?void 0:n.refetchInterval)?n.refetchInterval:o.refetchInterval;tt();for(let E=0;E<p.length;E+=1){let k=p[E],M=o.api[k];ot(M,k,o,f);}});export{Vt as Init,_ as JSONStringify,W as capitalize,Qe as createCustomCodeMarker,dt as extractCustomCode,He as getEndpointDetails,xt as getNestedValue,Ze as isJson,pt as isYamlString,Xe as mergeCustomCode,le as renderTypeRefMD,Ot as variableName,Ye as variableNameChar,De as yamlStringToJson};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-sync",
3
- "version": "2.1.16",
3
+ "version": "3.0.0",
4
4
  "description": "A developer-friendly tool designed to keep your API up-to-date by leveraging OpenAPI schemas. It automates the generation of endpoint URIs and type definitions, including shared types, directly from your OpenAPI specification.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -66,6 +66,7 @@
66
66
  "jest": "^30.2.0",
67
67
  "source-map-explorer": "^2.5.3",
68
68
  "ts-jest": "^29.4.4",
69
+ "tsup": "^8.5.0",
69
70
  "typescript": "^5.5.4"
70
71
  },
71
72
  "dependencies": {
@@ -77,7 +78,6 @@
77
78
  "js-yaml": "^4.1.0",
78
79
  "lodash.get": "^4.4.2",
79
80
  "lodash.isequal": "^4.5.0",
80
- "tsup": "^8.5.0",
81
81
  "yargs": "^17.7.2"
82
82
  }
83
83
  }
@@ -1 +0,0 @@
1
- var b=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(o,r)=>(typeof require!="undefined"?require:o)[r]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var c=(e,o,r)=>new Promise((A,z)=>{var Z=a=>{try{t(r.next(a));}catch($){z($);}},_=a=>{try{t(r.throw(a));}catch($){z($);}},t=a=>a.done?A(a.value):Promise.resolve(a.value).then(Z,_);t((r=r.apply(e,o)).next());});var l=/^[A-Za-z_$][A-Za-z0-9_$]*$/,m=/[A-Za-z0-9_$]/;export{b as a,c as b,l as c,m as d};
@@ -1,10 +0,0 @@
1
- import {d as d$1}from'./chunk-6GQNHE6A.mjs';import*as a from'js-yaml';var d=n=>["object"].includes(typeof n)&&!(n instanceof Blob),u=n=>{try{return a.load(n),!0}catch(s){let e=s;if(e instanceof a.YAMLException)return false;throw e}},h=n=>{if(u(n)){let s=a.load(n),e=JSON.stringify(s,null,2);return JSON.parse(e)}},p=n=>n.substring(0,1).toUpperCase()+n.substring(1),m=(n,s)=>{let e=n.split("/"),i=`${p(s)}`,o=[];return e.forEach(r=>{if(r[0]==="{"&&r[r.length-1]==="}"){let t=r.replace(/{/,"").replace(/}/,"");o.push(t),r=`$${t}`;}else if(r[0]==="<"&&r[r.length-1]===">"){let t=r.replace(/</,"").replace(/>/,"");o.push(t),r=`$${t}`;}else if(r[0]===":"){let t=r.replace(/:/,"");o.push(t),r=`$${t}`;}let l="";r.split("").forEach(t=>{let c=t;d$1.test(t)||(c="/"),l+=c;}),l.split("/").forEach(t=>{i+=p(t);});}),{name:i,variables:o,pathParts:e}},g=(n,s=1)=>{let e="{",i=Object.keys(n);for(let o=0;o<i.length;o++){let r=i[o],l=n[r];if(e+=`
2
- `+" ".repeat(s)+r+": ",Array.isArray(l)){e+="[";for(let t=0;t<l.length;t++){let c=l[t];typeof c=="object"&&c!==null?e+=g(c,s+1):e+=typeof c=="string"?`"${c}"`:c,t<l.length-1&&(e+=", ");}e+="]";}else typeof l=="object"&&l!==null?e+=""+g(l,s+1):e+=l.split(`
3
- `).filter(t=>t.trim()!=="").join(`
4
- ${" ".repeat(s)}`);o<i.length-1&&(e+=", ");}return e+=`
5
- ${" ".repeat(s-1)}}`,e},$=(n,s=1)=>`
6
- \`\`\`typescript
7
- ${" ".repeat(s)} ${n.split(`
8
- `).filter(e=>e.trim()!=="").join(`
9
- ${" ".repeat(s)} `)}
10
- \`\`\``;function j(n,s){return s.split(".").reduce((i,o)=>i&&i[o]!==void 0?i[o]:void 0,n)}export{d as a,u as b,h as c,p as d,m as e,g as f,$ as g,j as h};
@@ -1,14 +0,0 @@
1
- declare const isJson: (value: any) => boolean;
2
- declare const isYamlString: (fileContent: string) => boolean;
3
- declare const yamlStringToJson: (fileContent: string) => any;
4
- declare const capitalize: (text: string) => string;
5
- declare const getEndpointDetails: (path: string, method: string) => {
6
- name: string;
7
- variables: string[];
8
- pathParts: string[];
9
- };
10
- declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
11
- declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
12
- declare function getNestedValue<T>(obj: object, path: string): T | undefined;
13
-
14
- export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson };
package/dist/helpers.d.ts DELETED
@@ -1,14 +0,0 @@
1
- declare const isJson: (value: any) => boolean;
2
- declare const isYamlString: (fileContent: string) => boolean;
3
- declare const yamlStringToJson: (fileContent: string) => any;
4
- declare const capitalize: (text: string) => string;
5
- declare const getEndpointDetails: (path: string, method: string) => {
6
- name: string;
7
- variables: string[];
8
- pathParts: string[];
9
- };
10
- declare const JSONStringify: (obj: Record<string, any>, indent?: number) => string;
11
- declare const renderTypeRefMD: (typeRef: string, indent?: number) => string;
12
- declare function getNestedValue<T>(obj: object, path: string): T | undefined;
13
-
14
- export { JSONStringify, capitalize, getEndpointDetails, getNestedValue, isJson, isYamlString, renderTypeRefMD, yamlStringToJson };
package/dist/helpers.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';var c=require('js-yaml');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var c__namespace=/*#__PURE__*/_interopNamespace(c);var p=/[A-Za-z0-9_$]/;var $=n=>["object"].includes(typeof n)&&!(n instanceof Blob),u=n=>{try{return c__namespace.load(n),!0}catch(s){let e=s;if(e instanceof c__namespace.YAMLException)return false;throw e}},h=n=>{if(u(n)){let s=c__namespace.load(n),e=JSON.stringify(s,null,2);return JSON.parse(e)}},f=n=>n.substring(0,1).toUpperCase()+n.substring(1),d=(n,s)=>{let e=n.split("/"),i=`${f(s)}`,o=[];return e.forEach(r=>{if(r[0]==="{"&&r[r.length-1]==="}"){let t=r.replace(/{/,"").replace(/}/,"");o.push(t),r=`$${t}`;}else if(r[0]==="<"&&r[r.length-1]===">"){let t=r.replace(/</,"").replace(/>/,"");o.push(t),r=`$${t}`;}else if(r[0]===":"){let t=r.replace(/:/,"");o.push(t),r=`$${t}`;}let l="";r.split("").forEach(t=>{let a=t;p.test(t)||(a="/"),l+=a;}),l.split("/").forEach(t=>{i+=f(t);});}),{name:i,variables:o,pathParts:e}},g=(n,s=1)=>{let e="{",i=Object.keys(n);for(let o=0;o<i.length;o++){let r=i[o],l=n[r];if(e+=`
2
- `+" ".repeat(s)+r+": ",Array.isArray(l)){e+="[";for(let t=0;t<l.length;t++){let a=l[t];typeof a=="object"&&a!==null?e+=g(a,s+1):e+=typeof a=="string"?`"${a}"`:a,t<l.length-1&&(e+=", ");}e+="]";}else typeof l=="object"&&l!==null?e+=""+g(l,s+1):e+=l.split(`
3
- `).filter(t=>t.trim()!=="").join(`
4
- ${" ".repeat(s)}`);o<i.length-1&&(e+=", ");}return e+=`
5
- ${" ".repeat(s-1)}}`,e},x=(n,s=1)=>`
6
- \`\`\`typescript
7
- ${" ".repeat(s)} ${n.split(`
8
- `).filter(e=>e.trim()!=="").join(`
9
- ${" ".repeat(s)} `)}
10
- \`\`\``;function b(n,s){return s.split(".").reduce((i,o)=>i&&i[o]!==void 0?i[o]:void 0,n)}exports.JSONStringify=g;exports.capitalize=f;exports.getEndpointDetails=d;exports.getNestedValue=b;exports.isJson=$;exports.isYamlString=u;exports.renderTypeRefMD=x;exports.yamlStringToJson=h;
package/dist/helpers.mjs DELETED
@@ -1 +0,0 @@
1
- export{f as JSONStringify,d as capitalize,e as getEndpointDetails,h as getNestedValue,a as isJson,b as isYamlString,g as renderTypeRefMD,c as yamlStringToJson}from'./chunk-ALDCDVEN.mjs';import'./chunk-6GQNHE6A.mjs';
package/dist/regex.d.mts DELETED
@@ -1,4 +0,0 @@
1
- declare const variableName: RegExp;
2
- declare const variableNameChar: RegExp;
3
-
4
- export { variableName, variableNameChar };
package/dist/regex.d.ts DELETED
@@ -1,4 +0,0 @@
1
- declare const variableName: RegExp;
2
- declare const variableNameChar: RegExp;
3
-
4
- export { variableName, variableNameChar };
package/dist/regex.js DELETED
@@ -1 +0,0 @@
1
- 'use strict';var a=/^[A-Za-z_$][A-Za-z0-9_$]*$/,e=/[A-Za-z0-9_$]/;exports.variableName=a;exports.variableNameChar=e;
package/dist/regex.mjs DELETED
@@ -1 +0,0 @@
1
- export{c as variableName,d as variableNameChar}from'./chunk-6GQNHE6A.mjs';