react-query-lightbase-codegen 0.1.1 → 0.1.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.
- package/lib/cjs/import-open-api.js +4 -19
- package/lib/esm/import-open-api.js +4 -19
- package/package.json +1 -1
|
@@ -326,7 +326,8 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
326
326
|
throw new Error(`"${operationId}" is duplicated in your schema definition!`);
|
|
327
327
|
}
|
|
328
328
|
operationIds.push(operationId);
|
|
329
|
-
route = route.replace(/\{/g, '${'); // `/pet/{id}` => `/pet/${id}`
|
|
329
|
+
route = route.replace(/\{/g, '${').replace('//', '/'); // `/pet/{id}` => `/pet/${id}`
|
|
330
|
+
console.log(route);
|
|
330
331
|
// Remove the last param of the route if we are in the DELETE case
|
|
331
332
|
let lastParamInTheRoute = null;
|
|
332
333
|
const componentName = (0, case_1.pascal)(operationId);
|
|
@@ -409,7 +410,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
409
410
|
// QUERIES
|
|
410
411
|
if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
411
412
|
output += `
|
|
412
|
-
// type1
|
|
413
413
|
type ${componentName}Return = ${genericsTypes}
|
|
414
414
|
type ${componentName}Variables = {
|
|
415
415
|
${paramsTypes}
|
|
@@ -453,9 +453,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
453
453
|
}
|
|
454
454
|
if (!requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
455
455
|
output += `
|
|
456
|
-
import queryString from 'query-string';
|
|
457
|
-
|
|
458
|
-
// type2
|
|
459
456
|
type ${componentName}Return = ${genericsTypes}
|
|
460
457
|
type ${componentName}Variables = {
|
|
461
458
|
${paramsTypes}
|
|
@@ -503,7 +500,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
503
500
|
}
|
|
504
501
|
if (!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
505
502
|
output += `
|
|
506
|
-
// type3
|
|
507
503
|
type ${componentName}Return = ${genericsTypes}
|
|
508
504
|
use${componentName}Query.fetch = async () => {
|
|
509
505
|
const result = await api.${verb}<${componentName}Return>(\`${route}\`);
|
|
@@ -513,7 +509,7 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
513
509
|
use${componentName}Query.queryKey = (): QueryKey => use${componentName}Query.baseKey()
|
|
514
510
|
|
|
515
511
|
use${componentName}Query.updateCache = (
|
|
516
|
-
|
|
512
|
+
_params: undefined,
|
|
517
513
|
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
518
514
|
options?: SetDataOptions | undefined
|
|
519
515
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(), updater, options);
|
|
@@ -543,9 +539,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
543
539
|
}
|
|
544
540
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
545
541
|
output += `
|
|
546
|
-
// type4
|
|
547
|
-
import queryString from 'query-string';
|
|
548
|
-
|
|
549
542
|
|
|
550
543
|
type ${componentName}Return = ${genericsTypes}
|
|
551
544
|
type ${componentName}Variables = {
|
|
@@ -589,7 +582,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
589
582
|
}
|
|
590
583
|
if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
591
584
|
output += `
|
|
592
|
-
// type5
|
|
593
585
|
type ${componentName}Return = ${genericsTypes}
|
|
594
586
|
type ${componentName}Variables = ${requestBodyComponent};
|
|
595
587
|
|
|
@@ -632,9 +624,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
632
624
|
}
|
|
633
625
|
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
634
626
|
output += `
|
|
635
|
-
import queryString from 'query-string';
|
|
636
|
-
|
|
637
|
-
// type6
|
|
638
627
|
type ${componentName}Return = ${genericsTypes}
|
|
639
628
|
type ${componentName}Variables = {
|
|
640
629
|
body: ${requestBodyComponent}
|
|
@@ -682,9 +671,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
682
671
|
}
|
|
683
672
|
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
684
673
|
output += `
|
|
685
|
-
import queryString from 'query-string';
|
|
686
|
-
|
|
687
|
-
// type7
|
|
688
674
|
type ${componentName}Return = ${genericsTypes}
|
|
689
675
|
type ${componentName}Variables = {
|
|
690
676
|
body: ${requestBodyComponent}
|
|
@@ -795,8 +781,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
795
781
|
}
|
|
796
782
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
797
783
|
output += `
|
|
798
|
-
import queryString from 'query-string';
|
|
799
|
-
|
|
800
784
|
type ${componentName}Return = ${genericsTypes}
|
|
801
785
|
|
|
802
786
|
type ${componentName}Variables = {
|
|
@@ -942,6 +926,7 @@ const importOpenApi = async ({ data, format, apiDirectory, queryClientDir, heade
|
|
|
942
926
|
} from 'react-query';
|
|
943
927
|
import { Updater } from 'react-query/types/core/utils';
|
|
944
928
|
|
|
929
|
+
import queryString from 'query-string';
|
|
945
930
|
import { AxiosError } from 'axios';
|
|
946
931
|
import { api } from '${apiDirectory}';
|
|
947
932
|
import { queryClient } from '${queryClientDir}';
|
|
@@ -306,7 +306,8 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
306
306
|
throw new Error(`"${operationId}" is duplicated in your schema definition!`);
|
|
307
307
|
}
|
|
308
308
|
operationIds.push(operationId);
|
|
309
|
-
route = route.replace(/\{/g, '${'); // `/pet/{id}` => `/pet/${id}`
|
|
309
|
+
route = route.replace(/\{/g, '${').replace('//', '/'); // `/pet/{id}` => `/pet/${id}`
|
|
310
|
+
console.log(route);
|
|
310
311
|
// Remove the last param of the route if we are in the DELETE case
|
|
311
312
|
let lastParamInTheRoute = null;
|
|
312
313
|
const componentName = pascal(operationId);
|
|
@@ -389,7 +390,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
389
390
|
// QUERIES
|
|
390
391
|
if (!requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
391
392
|
output += `
|
|
392
|
-
// type1
|
|
393
393
|
type ${componentName}Return = ${genericsTypes}
|
|
394
394
|
type ${componentName}Variables = {
|
|
395
395
|
${paramsTypes}
|
|
@@ -433,9 +433,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
433
433
|
}
|
|
434
434
|
if (!requestBodyComponent && paramsInPath.length && queryParam && !headerParam) {
|
|
435
435
|
output += `
|
|
436
|
-
import queryString from 'query-string';
|
|
437
|
-
|
|
438
|
-
// type2
|
|
439
436
|
type ${componentName}Return = ${genericsTypes}
|
|
440
437
|
type ${componentName}Variables = {
|
|
441
438
|
${paramsTypes}
|
|
@@ -483,7 +480,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
483
480
|
}
|
|
484
481
|
if (!requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
485
482
|
output += `
|
|
486
|
-
// type3
|
|
487
483
|
type ${componentName}Return = ${genericsTypes}
|
|
488
484
|
use${componentName}Query.fetch = async () => {
|
|
489
485
|
const result = await api.${verb}<${componentName}Return>(\`${route}\`);
|
|
@@ -493,7 +489,7 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
493
489
|
use${componentName}Query.queryKey = (): QueryKey => use${componentName}Query.baseKey()
|
|
494
490
|
|
|
495
491
|
use${componentName}Query.updateCache = (
|
|
496
|
-
|
|
492
|
+
_params: undefined,
|
|
497
493
|
updater: Updater<${componentName}Return | undefined, ${componentName}Return>,
|
|
498
494
|
options?: SetDataOptions | undefined
|
|
499
495
|
) => queryClient.setQueryData<${componentName}Return>(use${componentName}Query.queryKey(), updater, options);
|
|
@@ -523,9 +519,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
523
519
|
}
|
|
524
520
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
525
521
|
output += `
|
|
526
|
-
// type4
|
|
527
|
-
import queryString from 'query-string';
|
|
528
|
-
|
|
529
522
|
|
|
530
523
|
type ${componentName}Return = ${genericsTypes}
|
|
531
524
|
type ${componentName}Variables = {
|
|
@@ -569,7 +562,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
569
562
|
}
|
|
570
563
|
if (requestBodyComponent && !paramsInPath.length && !queryParam && !headerParam) {
|
|
571
564
|
output += `
|
|
572
|
-
// type5
|
|
573
565
|
type ${componentName}Return = ${genericsTypes}
|
|
574
566
|
type ${componentName}Variables = ${requestBodyComponent};
|
|
575
567
|
|
|
@@ -612,9 +604,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
612
604
|
}
|
|
613
605
|
if (requestBodyComponent && paramsInPath.length && !queryParam && !headerParam) {
|
|
614
606
|
output += `
|
|
615
|
-
import queryString from 'query-string';
|
|
616
|
-
|
|
617
|
-
// type6
|
|
618
607
|
type ${componentName}Return = ${genericsTypes}
|
|
619
608
|
type ${componentName}Variables = {
|
|
620
609
|
body: ${requestBodyComponent}
|
|
@@ -662,9 +651,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
662
651
|
}
|
|
663
652
|
if (requestBodyComponent && !paramsInPath.length && queryParam && !headerParam) {
|
|
664
653
|
output += `
|
|
665
|
-
import queryString from 'query-string';
|
|
666
|
-
|
|
667
|
-
// type7
|
|
668
654
|
type ${componentName}Return = ${genericsTypes}
|
|
669
655
|
type ${componentName}Variables = {
|
|
670
656
|
body: ${requestBodyComponent}
|
|
@@ -775,8 +761,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
775
761
|
}
|
|
776
762
|
if (!requestBodyComponent && !paramsInPath.length && queryParam && headerParam) {
|
|
777
763
|
output += `
|
|
778
|
-
import queryString from 'query-string';
|
|
779
|
-
|
|
780
764
|
type ${componentName}Return = ${genericsTypes}
|
|
781
765
|
|
|
782
766
|
type ${componentName}Variables = {
|
|
@@ -921,6 +905,7 @@ export const importOpenApi = async ({ data, format, apiDirectory, queryClientDir
|
|
|
921
905
|
} from 'react-query';
|
|
922
906
|
import { Updater } from 'react-query/types/core/utils';
|
|
923
907
|
|
|
908
|
+
import queryString from 'query-string';
|
|
924
909
|
import { AxiosError } from 'axios';
|
|
925
910
|
import { api } from '${apiDirectory}';
|
|
926
911
|
import { queryClient } from '${queryClientDir}';
|