@bitstack/ng-query-codegen-openapi 0.0.38-alpha.3 → 0.0.38-alpha.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/bin/cli.mjs +64 -61
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.js +44 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +44 -8
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/rtk-enhance-endpoints-generator.ts +4 -1
- package/src/generators/rtk-query-generator.ts +1 -0
- package/src/generators/types-generator.ts +22 -8
- package/src/services/endpoint-info-extractor.ts +35 -0
package/lib/index.js
CHANGED
|
@@ -619,6 +619,7 @@ var EndpointInfoExtractor = class {
|
|
|
619
619
|
const { queryParams, pathParams, isVoidArg, hasRequestBody } = this.extractParameters(operationDefinition);
|
|
620
620
|
const contentType = this.extractContentType(operation);
|
|
621
621
|
const tags = Array.isArray(operation.tags) ? operation.tags : [];
|
|
622
|
+
const isBlobResponse = this.isBlobResponseEndpoint(operation);
|
|
622
623
|
return {
|
|
623
624
|
operationName: finalOperationName,
|
|
624
625
|
argTypeName,
|
|
@@ -633,7 +634,8 @@ var EndpointInfoExtractor = class {
|
|
|
633
634
|
summary,
|
|
634
635
|
contentType,
|
|
635
636
|
hasRequestBody,
|
|
636
|
-
tags
|
|
637
|
+
tags,
|
|
638
|
+
isBlobResponse
|
|
637
639
|
};
|
|
638
640
|
}
|
|
639
641
|
/**
|
|
@@ -667,6 +669,28 @@ var EndpointInfoExtractor = class {
|
|
|
667
669
|
if (!parameters) return [];
|
|
668
670
|
return Array.isArray(parameters) ? parameters : [parameters];
|
|
669
671
|
}
|
|
672
|
+
/**
|
|
673
|
+
* 偵測是否為 Blob 下載端點
|
|
674
|
+
* 當 response content type 為 binary 類型或 schema format 為 binary 時回傳 true
|
|
675
|
+
*/
|
|
676
|
+
isBlobResponseEndpoint(operation) {
|
|
677
|
+
if (!operation.responses) return false;
|
|
678
|
+
const successResponse = operation.responses["200"] || operation.responses["201"];
|
|
679
|
+
if (!successResponse?.content) return false;
|
|
680
|
+
const contentTypes = Object.keys(successResponse.content);
|
|
681
|
+
const textContentTypes = ["application/json", "text/", "*/*"];
|
|
682
|
+
const hasNonTextContentType = contentTypes.some(
|
|
683
|
+
(ct) => !textContentTypes.some((textCt) => ct === textCt || ct.startsWith(textCt))
|
|
684
|
+
);
|
|
685
|
+
if (hasNonTextContentType) return true;
|
|
686
|
+
for (const ct of contentTypes) {
|
|
687
|
+
const schema = successResponse.content[ct]?.schema;
|
|
688
|
+
if (schema && schema.type === "string" && schema.format === "binary") {
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
670
694
|
/**
|
|
671
695
|
* 提取操作的 content type
|
|
672
696
|
* @param operation - 操作對象
|
|
@@ -707,10 +731,15 @@ function generateTypesFile(endpointInfos, _options, schemaInterfaces, operationD
|
|
|
707
731
|
}
|
|
708
732
|
});
|
|
709
733
|
}
|
|
734
|
+
const hasBlobResponse = endpointInfos.some((info) => info.isBlobResponse);
|
|
710
735
|
let importStatement = `/* eslint-disable */
|
|
711
|
-
// [Warning] Generated automatically - do not edit manually
|
|
712
|
-
|
|
736
|
+
// [Warning] Generated automatically - do not edit manually
|
|
737
|
+
|
|
738
|
+
`;
|
|
739
|
+
if (hasBlobResponse) {
|
|
740
|
+
importStatement += `import { HttpResponse } from '@angular/common/http';
|
|
713
741
|
`;
|
|
742
|
+
}
|
|
714
743
|
const hasSchemaTypes = schemaInterfaces && Object.keys(schemaInterfaces).length > 0;
|
|
715
744
|
if (hasSchemaTypes) {
|
|
716
745
|
importStatement += `import * as Schema from "../schema";
|
|
@@ -731,11 +760,15 @@ function generateTypesFile(endpointInfos, _options, schemaInterfaces, operationD
|
|
|
731
760
|
}
|
|
732
761
|
}
|
|
733
762
|
if (resTypeName) {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
endpointTypes.push(`export type ${resTypeName} = void;`, ``);
|
|
763
|
+
if (endpoint.isBlobResponse) {
|
|
764
|
+
endpointTypes.push(`export type ${resTypeName} = HttpResponse<Blob>;`, ``);
|
|
737
765
|
} else {
|
|
738
|
-
|
|
766
|
+
const responseTypeContent = generateResponseTypeContent(endpoint, operationDefinitions, schemaTypeMap);
|
|
767
|
+
if (responseTypeContent.trim() === "") {
|
|
768
|
+
endpointTypes.push(`export type ${resTypeName} = void;`, ``);
|
|
769
|
+
} else {
|
|
770
|
+
endpointTypes.push(`export type ${resTypeName} = {`, responseTypeContent, `};`, ``);
|
|
771
|
+
}
|
|
739
772
|
}
|
|
740
773
|
}
|
|
741
774
|
});
|
|
@@ -1050,10 +1083,13 @@ ${endpointInfos.map((info) => {
|
|
|
1050
1083
|
const paramsLines = info.queryParams.map((param) => `${param.name}: args.variables.${param.name},`).join("\n");
|
|
1051
1084
|
paramsSection = `params: {${paramsLines}},`;
|
|
1052
1085
|
}
|
|
1086
|
+
const blobOptions = info.isBlobResponse ? `
|
|
1087
|
+
responseType: 'blob',
|
|
1088
|
+
observe: 'response',` : "";
|
|
1053
1089
|
return `{
|
|
1054
1090
|
...args?.fetchOptions,
|
|
1055
1091
|
headers: { 'Content-Type': '${info.contentType}', ...args?.fetchOptions?.headers },
|
|
1056
|
-
${paramsSection}${info.hasRequestBody ? `body: args.variables.body,` : ""}
|
|
1092
|
+
${paramsSection}${info.hasRequestBody ? `body: args.variables.body,` : ""}${blobOptions}
|
|
1057
1093
|
}`;
|
|
1058
1094
|
};
|
|
1059
1095
|
return `
|