react-query-lightbase-codegen 2.0.2 → 2.0.4

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.
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateReactQuery = generateReactQuery;
4
4
  const utils_1 = require("../utils");
5
5
  function generateQueryOptions(operation, spec) {
6
- const { operationId, parameters, requestBody } = operation;
6
+ const { operationId, parameters, requestBody, method } = operation;
7
7
  const hasData = (parameters && parameters.length > 0) || operation.requestBody;
8
8
  // Helper to get required fields from a schema
9
9
  const getRequiredFields = (schema, context) => {
@@ -28,9 +28,10 @@ function generateQueryOptions(operation, spec) {
28
28
  })
29
29
  : []),
30
30
  ];
31
- const namedQuery = (0, utils_1.camelCase)(operationId);
31
+ const namedQueryOptions = `get${operationId}QueryOptions`;
32
+ const namedQuery = (0, utils_1.camelCase)(`${method}_${operationId}`);
32
33
  return `
33
- export const ${namedQuery}QueryOptions = (
34
+ export const ${namedQueryOptions} = (
34
35
  ${hasData ? `params: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>` : `_: undefined, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>`}
35
36
  ) => {
36
37
  const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
@@ -54,9 +55,9 @@ function generateReactQuery(spec) {
54
55
  if (!operation)
55
56
  return;
56
57
  operations.push({
57
- method: method.toUpperCase(),
58
+ method: method,
58
59
  path,
59
- operationId: `${method}_${(0, utils_1.sanitizeTypeName)(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
60
+ operationId: `${(0, utils_1.sanitizeTypeName)(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
60
61
  summary: operation.summary,
61
62
  description: operation.description,
62
63
  parameters: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-lightbase-codegen",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "license": "MIT",
5
5
  "description": "Generate Axios API clients and React Query options from OpenAPI specifications",
6
6
  "exports": "./dist/index.js",
@@ -3,7 +3,7 @@ import { camelCase, pascalCase, sanitizeTypeName, specTitle } from "../utils";
3
3
  import type { OperationInfo } from "./clientGenerator";
4
4
 
5
5
  function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document): string {
6
- const { operationId, parameters, requestBody } = operation;
6
+ const { operationId, parameters, requestBody, method } = operation;
7
7
 
8
8
  const hasData = (parameters && parameters.length > 0) || operation.requestBody;
9
9
 
@@ -35,10 +35,11 @@ function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document
35
35
  : []),
36
36
  ];
37
37
 
38
- const namedQuery = camelCase(operationId);
38
+ const namedQueryOptions = `get${operationId}QueryOptions`;
39
+ const namedQuery = camelCase(`${method}_${operationId}`);
39
40
 
40
41
  return `
41
- export const ${namedQuery}QueryOptions = (
42
+ export const ${namedQueryOptions} = (
42
43
  ${hasData ? `params: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>` : `_: undefined, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>`}
43
44
  ) => {
44
45
  const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
@@ -63,9 +64,9 @@ export function generateReactQuery(spec: OpenAPIV3.Document): string {
63
64
  const operation = pathItem[method as keyof OpenAPIV3.PathItemObject] as OpenAPIV3.OperationObject;
64
65
  if (!operation) return;
65
66
  operations.push({
66
- method: method.toUpperCase(),
67
+ method: method,
67
68
  path,
68
- operationId: `${method}_${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
69
+ operationId: `${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
69
70
  summary: operation.summary,
70
71
  description: operation.description,
71
72
  parameters: [