@acrool/rtk-query-codegen-openapi 0.0.7 → 0.0.9

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
@@ -15,6 +15,39 @@ Code Generator
15
15
 
16
16
  This is a utility library meant to be used with [RTK Query](https://redux-toolkit.js.org/rtk-query/overview) that will generate a typed API client from an OpenAPI schema.
17
17
 
18
+ ### Features
19
+
20
+ - **Local Schema File Support**: Direct processing of local schema files via `schemaFile`
21
+ - **Remote Schema Download**: Download remote schemas to local files via `remoteFile` and `schemaFile`
22
+ - **Type Generation**: Generates TypeScript types from OpenAPI schemas
23
+ - **RTK Query Integration**: Seamless integration with RTK Query
24
+
25
+ ### Configuration Options
26
+
27
+ - `schemaFile`: The local OpenAPI schema file path (required)
28
+ - `remoteFile`: (Optional) Remote schema URL to download to `schemaFile` path
29
+ - `outputFile`: The output file path for generated code
30
+ - `apiFile`: The base API file path
31
+
32
+ ### Example Configuration
33
+
34
+ ```typescript
35
+ // For remote schemas with download
36
+ {
37
+ schemaFile: './schemas/api-schema.json',
38
+ remoteFile: 'https://api.example.com/openapi.json',
39
+ apiFile: './baseApi',
40
+ outputFile: './generated-api.ts'
41
+ }
42
+
43
+ // For local schema files
44
+ {
45
+ schemaFile: './schemas/api-schema.json',
46
+ apiFile: './baseApi',
47
+ outputFile: './generated-api.ts'
48
+ }
49
+ ```
50
+
18
51
  ### Documentation
19
52
 
20
53
  [View the RTK Query Code Generation docs](https://redux-toolkit.js.org/rtk-query/usage/code-generation)
package/lib/index.d.mts CHANGED
@@ -27,9 +27,13 @@ type GenerationOptions = Id<CommonOptions & Optional<OutputFileOptions, 'outputF
27
27
  interface CommonOptions {
28
28
  apiFile: string;
29
29
  /**
30
- * filename or url
30
+ * local schema file path (only supports local files)
31
31
  */
32
32
  schemaFile: string;
33
+ /**
34
+ * remote schema file URL (when provided, will download to schemaFile path)
35
+ */
36
+ remoteFile?: string;
33
37
  /**
34
38
  * defaults to "api"
35
39
  */
@@ -107,6 +111,11 @@ interface CommonOptions {
107
111
  * resolution mechanism will be used.
108
112
  */
109
113
  prettierConfigFile?: string;
114
+ /**
115
+ * defaults to "@acrool/react-fetcher"
116
+ * File path for importing IRestFulEndpointsQueryReturn type
117
+ */
118
+ endpointsQueryReturnTypeFile?: string;
110
119
  }
111
120
  type TextMatcher = string | RegExp | (string | RegExp)[];
112
121
  type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;
@@ -117,6 +126,7 @@ interface OutputFileOptions extends Partial<CommonOptions> {
117
126
  outputFile: string;
118
127
  filterEndpoints?: EndpointMatcher;
119
128
  endpointOverrides?: EndpointOverrides[];
129
+ queryMatch?: (method: string, path: string) => boolean;
120
130
  /**
121
131
  * defaults to false
122
132
  * If passed as true it will generate TS enums instead of union of strings
@@ -131,10 +141,10 @@ type EndpointOverrides = {
131
141
  parameterFilter: ParameterMatcher;
132
142
  }>;
133
143
  type OutputFilesConfig = {
134
- [outputFile: string]: {
135
- groupMatch: RegExp;
136
- filterEndpoint?: (groupName: string) => RegExp;
137
- };
144
+ groupKeyMatch: (path: string) => string;
145
+ outputDir: string;
146
+ queryMatch?: (method: string, path: string) => boolean;
147
+ filterEndpoint?: (groupName: string) => RegExp;
138
148
  };
139
149
  type ConfigFile = Id<Require<CommonOptions & OutputFileOptions, 'outputFile'>> | Id<Omit<CommonOptions, 'outputFile'> & {
140
150
  outputFiles: OutputFilesConfig;
package/lib/index.d.ts CHANGED
@@ -27,9 +27,13 @@ type GenerationOptions = Id<CommonOptions & Optional<OutputFileOptions, 'outputF
27
27
  interface CommonOptions {
28
28
  apiFile: string;
29
29
  /**
30
- * filename or url
30
+ * local schema file path (only supports local files)
31
31
  */
32
32
  schemaFile: string;
33
+ /**
34
+ * remote schema file URL (when provided, will download to schemaFile path)
35
+ */
36
+ remoteFile?: string;
33
37
  /**
34
38
  * defaults to "api"
35
39
  */
@@ -107,6 +111,11 @@ interface CommonOptions {
107
111
  * resolution mechanism will be used.
108
112
  */
109
113
  prettierConfigFile?: string;
114
+ /**
115
+ * defaults to "@acrool/react-fetcher"
116
+ * File path for importing IRestFulEndpointsQueryReturn type
117
+ */
118
+ endpointsQueryReturnTypeFile?: string;
110
119
  }
111
120
  type TextMatcher = string | RegExp | (string | RegExp)[];
112
121
  type EndpointMatcherFunction = (operationName: string, operationDefinition: OperationDefinition) => boolean;
@@ -117,6 +126,7 @@ interface OutputFileOptions extends Partial<CommonOptions> {
117
126
  outputFile: string;
118
127
  filterEndpoints?: EndpointMatcher;
119
128
  endpointOverrides?: EndpointOverrides[];
129
+ queryMatch?: (method: string, path: string) => boolean;
120
130
  /**
121
131
  * defaults to false
122
132
  * If passed as true it will generate TS enums instead of union of strings
@@ -131,10 +141,10 @@ type EndpointOverrides = {
131
141
  parameterFilter: ParameterMatcher;
132
142
  }>;
133
143
  type OutputFilesConfig = {
134
- [outputFile: string]: {
135
- groupMatch: RegExp;
136
- filterEndpoint?: (groupName: string) => RegExp;
137
- };
144
+ groupKeyMatch: (path: string) => string;
145
+ outputDir: string;
146
+ queryMatch?: (method: string, path: string) => boolean;
147
+ filterEndpoint?: (groupName: string) => RegExp;
138
148
  };
139
149
  type ConfigFile = Id<Require<CommonOptions & OutputFileOptions, 'outputFile'>> | Id<Omit<CommonOptions, 'outputFile'> & {
140
150
  outputFiles: OutputFilesConfig;