react-query-lightbase-codegen 0.0.15 → 0.0.16
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.
|
@@ -25,6 +25,8 @@ const importSpecs = (data, extension) => {
|
|
|
25
25
|
reject(err);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
convertedObj.openapi.basePath = convertedObj.original.basePath;
|
|
28
30
|
resolve(convertedObj.openapi);
|
|
29
31
|
}
|
|
30
32
|
});
|
|
@@ -586,8 +588,6 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
586
588
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
587
589
|
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
588
590
|
|
|
589
|
-
// TODO: CHECK
|
|
590
|
-
|
|
591
591
|
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
592
592
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props${queryParams
|
|
593
593
|
.map((param) => `["${param.name}"]`)
|
|
@@ -730,7 +730,8 @@ const generateRestfulComponent = ({ operation, verb, route, operationIds, parame
|
|
|
730
730
|
return output;
|
|
731
731
|
};
|
|
732
732
|
exports.generateRestfulComponent = generateRestfulComponent;
|
|
733
|
-
const generateQueryHooks = (
|
|
733
|
+
const generateQueryHooks = (spec, operationIds, headerFilters) => {
|
|
734
|
+
const { paths, components } = spec;
|
|
734
735
|
let output = '';
|
|
735
736
|
Object.entries(paths).forEach(([route, verbs]) => {
|
|
736
737
|
Object.entries(verbs).forEach(([verb, operation]) => {
|
|
@@ -738,10 +739,10 @@ const generateQueryHooks = (paths, operationIds, schemasComponents, headerFilter
|
|
|
738
739
|
output += (0, exports.generateRestfulComponent)({
|
|
739
740
|
operation,
|
|
740
741
|
verb,
|
|
741
|
-
route,
|
|
742
|
+
route: spec.basePath + route,
|
|
742
743
|
operationIds,
|
|
743
744
|
parameters: verbs.parameters,
|
|
744
|
-
schemasComponents,
|
|
745
|
+
schemasComponents: components,
|
|
745
746
|
headerFilters,
|
|
746
747
|
});
|
|
747
748
|
}
|
|
@@ -755,6 +756,7 @@ const generateQueryHooks = (paths, operationIds, schemasComponents, headerFilter
|
|
|
755
756
|
const importOpenApi = async ({ data, format, apiDir, headerFilters = [], }) => {
|
|
756
757
|
const operationIds = [];
|
|
757
758
|
let specs = await importSpecs(data, format);
|
|
759
|
+
console.log(JSON.stringify(Object.keys(specs), null, 2));
|
|
758
760
|
(0, exports.resolveDiscriminator)(specs);
|
|
759
761
|
let output = '';
|
|
760
762
|
output = `
|
|
@@ -773,7 +775,7 @@ const importOpenApi = async ({ data, format, apiDir, headerFilters = [], }) => {
|
|
|
773
775
|
${(0, exports.generateRequestBodiesDefinition)(specs.components?.requestBodies)}
|
|
774
776
|
|
|
775
777
|
// HOOKS
|
|
776
|
-
${generateQueryHooks(specs
|
|
778
|
+
${generateQueryHooks(specs, operationIds, headerFilters)}
|
|
777
779
|
`;
|
|
778
780
|
return output;
|
|
779
781
|
};
|
|
@@ -19,6 +19,8 @@ const importSpecs = (data, extension) => {
|
|
|
19
19
|
reject(err);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
convertedObj.openapi.basePath = convertedObj.original.basePath;
|
|
22
24
|
resolve(convertedObj.openapi);
|
|
23
25
|
}
|
|
24
26
|
});
|
|
@@ -566,8 +568,6 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
566
568
|
use${componentName}Query.baseKey = (): QueryKey => ["${componentName.toLowerCase()}"];
|
|
567
569
|
use${componentName}Query.queryKey = (params: ${componentName}Variables ): QueryKey => [...use${componentName}Query.baseKey(), params];
|
|
568
570
|
|
|
569
|
-
// TODO: CHECK
|
|
570
|
-
|
|
571
571
|
export function use${componentName}Query<T = ${genericsTypes}>({ options = {}, ...props }: ${componentName}QueryProps<T>) {
|
|
572
572
|
return useQuery(use${componentName}Query.queryKey(props), async () => use${componentName}Query.fetch(props), { enabled: !!props${queryParams
|
|
573
573
|
.map((param) => `["${param.name}"]`)
|
|
@@ -709,7 +709,8 @@ export const generateRestfulComponent = ({ operation, verb, route, operationIds,
|
|
|
709
709
|
}
|
|
710
710
|
return output;
|
|
711
711
|
};
|
|
712
|
-
const generateQueryHooks = (
|
|
712
|
+
const generateQueryHooks = (spec, operationIds, headerFilters) => {
|
|
713
|
+
const { paths, components } = spec;
|
|
713
714
|
let output = '';
|
|
714
715
|
Object.entries(paths).forEach(([route, verbs]) => {
|
|
715
716
|
Object.entries(verbs).forEach(([verb, operation]) => {
|
|
@@ -717,10 +718,10 @@ const generateQueryHooks = (paths, operationIds, schemasComponents, headerFilter
|
|
|
717
718
|
output += generateRestfulComponent({
|
|
718
719
|
operation,
|
|
719
720
|
verb,
|
|
720
|
-
route,
|
|
721
|
+
route: spec.basePath + route,
|
|
721
722
|
operationIds,
|
|
722
723
|
parameters: verbs.parameters,
|
|
723
|
-
schemasComponents,
|
|
724
|
+
schemasComponents: components,
|
|
724
725
|
headerFilters,
|
|
725
726
|
});
|
|
726
727
|
}
|
|
@@ -734,6 +735,7 @@ const generateQueryHooks = (paths, operationIds, schemasComponents, headerFilter
|
|
|
734
735
|
export const importOpenApi = async ({ data, format, apiDir, headerFilters = [], }) => {
|
|
735
736
|
const operationIds = [];
|
|
736
737
|
let specs = await importSpecs(data, format);
|
|
738
|
+
console.log(JSON.stringify(Object.keys(specs), null, 2));
|
|
737
739
|
resolveDiscriminator(specs);
|
|
738
740
|
let output = '';
|
|
739
741
|
output = `
|
|
@@ -752,7 +754,7 @@ export const importOpenApi = async ({ data, format, apiDir, headerFilters = [],
|
|
|
752
754
|
${generateRequestBodiesDefinition(specs.components?.requestBodies)}
|
|
753
755
|
|
|
754
756
|
// HOOKS
|
|
755
|
-
${generateQueryHooks(specs
|
|
757
|
+
${generateQueryHooks(specs, operationIds, headerFilters)}
|
|
756
758
|
`;
|
|
757
759
|
return output;
|
|
758
760
|
};
|