Closed mat813 closed 2 years ago
Here is the diff that solved my problem:
diff --git a/node_modules/openapi-client-axios-typegen/typegen.js b/node_modules/openapi-client-axios-typegen/typegen.js
index 82d87c5..35b4714 100644
--- a/node_modules/openapi-client-axios-typegen/typegen.js
+++ b/node_modules/openapi-client-axios-typegen/typegen.js
@@ -180,7 +180,7 @@ function generateMethodForOperation(methodName, operation, exportTypes) {
var responseTypePaths = lodash_1.default.chain(exportTypes)
.filter(function (_a) {
var schemaRef = _a.schemaRef;
- return schemaRef.startsWith("#/paths/" + normalizedOperationId + "/responses");
+ return schemaRef.startsWith("#/paths/" + normalizedOperationId + "/responses/2");
})
.map(function (_a) {
var path = _a.path;
You can apply it with patch-package.
Say I have this path:
The error type is this:
typegen will generate this:
But only
Paths.AuthAuth.Responses.$200
will ever be returned byclient.authAuth
as all status codes outside of 200..300 generate an exception. (see lib/adapters/xhr.js for example)I think only the responses in the 2xx range should be added there. If TypeScript ever gets a "throws" keyword to describe what a function can throw, then they can be added back in there, but adding it as the return values feels wrong.