Skip to content

Commit

Permalink
Merge pull request #369 from pmcelhaney/fix-extrarneous-import
Browse files Browse the repository at this point in the history
don't import HTTPStatusCode if not needed
  • Loading branch information
pmcelhaney committed Jan 19, 2023
2 parents 4adc059 + cbfb229 commit 63b095b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 132 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-pianos-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

don't import HTTPStatusCode if not needed
13 changes: 9 additions & 4 deletions src/typescript-generator/response-type-coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class ResponseTypeCoder extends Coder {
}

typeForDefaultStatusCode(listedStatusCodes) {
this.needsHttpStatusCodeImport = true;

const definedStatusCodes = listedStatusCodes.filter(
(key) => key !== "default"
);
Expand Down Expand Up @@ -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)}>`;
}
Expand Down
128 changes: 0 additions & 128 deletions test/typescript-generator/__snapshots__/end-to-end.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ Map {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -448,10 +444,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -756,10 +748,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1030,10 +1018,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1245,10 +1229,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1477,10 +1457,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1692,10 +1668,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -1996,10 +1968,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2345,10 +2313,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -2694,10 +2658,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3047,10 +3007,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3358,10 +3314,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3495,10 +3447,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3648,10 +3596,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3753,10 +3697,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -3882,10 +3822,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4025,10 +3961,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4237,10 +4169,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4461,10 +4389,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4689,10 +4613,6 @@ class Context {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -4896,10 +4816,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5038,10 +4954,6 @@ class Context {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5203,10 +5115,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5353,10 +5261,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5522,10 +5426,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5643,10 +5543,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5757,10 +5653,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -5856,10 +5748,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -6070,10 +5958,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -6360,10 +6244,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -6650,10 +6530,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down Expand Up @@ -6944,10 +6820,6 @@ class Context {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
"HttpStatusCode" => Object {
"isType": true,
"modulePath": "../../response-builder-factory.js",
},
},
"imports": Map {
"Context" => Object {
Expand Down

0 comments on commit 63b095b

Please sign in to comment.