diff --git a/.changeset/late-pianos-jam.md b/.changeset/late-pianos-jam.md new file mode 100644 index 00000000..1ca18b3c --- /dev/null +++ b/.changeset/late-pianos-jam.md @@ -0,0 +1,5 @@ +--- +"counterfact": patch +--- + +don't import HTTPStatusCode if not needed diff --git a/src/typescript-generator/response-type-coder.js b/src/typescript-generator/response-type-coder.js index 6382adb0..3aa73644 100644 --- a/src/typescript-generator/response-type-coder.js +++ b/src/typescript-generator/response-type-coder.js @@ -12,6 +12,8 @@ export class ResponseTypeCoder extends Coder { } typeForDefaultStatusCode(listedStatusCodes) { + this.needsHttpStatusCodeImport = true; + const definedStatusCodes = listedStatusCodes.filter( (key) => key !== "default" ); @@ -101,10 +103,13 @@ export class ResponseTypeCoder extends Coder { "ResponseBuilderFactory", nodePath.join(basePath, "response-builder-factory.js") ); - script.importExternalType( - "HttpStatusCode", - nodePath.join(basePath, "response-builder-factory.js") - ); + + if (this.needsHttpStatusCodeImport) { + script.importExternalType( + "HttpStatusCode", + nodePath.join(basePath, "response-builder-factory.js") + ); + } return `ResponseBuilderFactory<${this.buildResponseObjectType(script)}>`; } diff --git a/test/typescript-generator/__snapshots__/end-to-end.test.js.snap b/test/typescript-generator/__snapshots__/end-to-end.test.js.snap index 0dc36bc9..75c15cdf 100644 --- a/test/typescript-generator/__snapshots__/end-to-end.test.js.snap +++ b/test/typescript-generator/__snapshots__/end-to-end.test.js.snap @@ -143,10 +143,6 @@ Map { "isType": true, "modulePath": "../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -402,10 +398,6 @@ class Context { "isType": true, "modulePath": "../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -665,10 +657,6 @@ class Context { "isType": true, "modulePath": "../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -895,10 +883,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -1110,10 +1094,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -1342,10 +1322,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -1557,10 +1533,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -1859,10 +1831,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -2114,10 +2082,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -2369,10 +2333,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -2628,10 +2588,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -2847,10 +2803,6 @@ class Context { "isType": true, "modulePath": "../../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -2984,10 +2936,6 @@ class Context { "isType": true, "modulePath": "../../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -3137,10 +3085,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -3242,10 +3186,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -3371,10 +3311,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -3514,10 +3450,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -3725,10 +3657,6 @@ class Context { "isType": true, "modulePath": "../../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -3902,10 +3830,6 @@ class Context { "isType": true, "modulePath": "../../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4083,10 +4007,6 @@ class Context { "isType": true, "modulePath": "../../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4244,10 +4164,6 @@ class Context { "isType": true, "modulePath": "../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4386,10 +4302,6 @@ class Context { "isType": true, "modulePath": "../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4551,10 +4463,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4701,10 +4609,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4870,10 +4774,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -4991,10 +4891,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -5105,10 +5001,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -5204,10 +5096,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -5416,10 +5304,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -5612,10 +5496,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -5808,10 +5688,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object { @@ -6008,10 +5884,6 @@ class Context { "isType": true, "modulePath": "../../response-builder-factory.js", }, - "HttpStatusCode" => Object { - "isType": true, - "modulePath": "../../response-builder-factory.js", - }, }, "imports": Map { "Context" => Object {