• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmcelhaney / counterfact / 5942933897

22 Aug 2023 06:59PM UTC coverage: 83.567% (-3.8%) from 87.388%
5942933897

push

github

web-flow
Merge pull request #517 from pmcelhaney/windows-support

disable the end-to-end test because it won't work on Windows

389 of 423 branches covered (91.96%)

Branch coverage included in aggregate %.

1818 of 2218 relevant lines covered (81.97%)

9.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.86
/src/typescript-generator/operation-type-coder.js
1
import nodePath from "node:path";
1✔
2

1✔
3
import { Coder } from "./coder.js";
1✔
4
import { SchemaTypeCoder } from "./schema-type-coder.js";
1✔
5
import { ParametersTypeCoder } from "./parameters-type-coder.js";
1✔
6
import { ResponseTypeCoder } from "./response-type-coder.js";
1✔
7
import { ContextCoder } from "./context-coder.js";
1✔
8

1✔
9
export class OperationTypeCoder extends Coder {
1✔
10
  names() {
1✔
11
    return super.names(
1✔
12
      `HTTP_${this.requirement.url.split("/").at(-1).toUpperCase()}`
1✔
13
    );
1✔
14
  }
1✔
15

1✔
16
  responseTypes(script) {
1✔
17
    return this.requirement
6✔
18
      .get("responses")
6✔
19
      .flatMap((response, responseCode) => {
6✔
20
        const status =
12✔
21
          responseCode === "default"
12✔
22
            ? "number | undefined"
6✔
23
            : Number.parseInt(responseCode, 10);
12✔
24

12✔
25
        if (response.has("content")) {
12✔
26
          return response.get("content").map(
4✔
27
            (content, contentType) => `{  
4✔
28
              status: ${status}, 
4✔
29
              contentType?: "${contentType}",
4✔
30
              body?: ${new SchemaTypeCoder(content.get("schema")).write(script)}
4✔
31
            }`
4✔
32
          );
4✔
33
        }
4✔
34

8✔
35
        if (response.has("schema")) {
8✔
36
          const produces =
8✔
37
            this.requirement?.get("produces")?.data ??
8✔
38
            this.requirement.specification.rootRequirement.get("produces").data;
3✔
39

8✔
40
          return produces
8✔
41
            .map(
8✔
42
              (contentType) => `{
8✔
43
            status: ${status},
8✔
44
            contentType?: "${contentType}",
8✔
45
            body?: ${new SchemaTypeCoder(response.get("schema")).write(script)}
8✔
46
          }`
8✔
47
            )
8✔
48
            .join(" | ");
8✔
49
        }
8✔
50

×
51
        return `{  
×
52
          status: ${status} 
×
53
        }`;
×
54
      })
×
55

6✔
56
      .join(" | ");
6✔
57
  }
6✔
58

1✔
59
  modulePath() {
1✔
60
    const pathString = this.requirement.url
1✔
61
      .split("/")
1✔
62
      .at(-2)
1✔
63
      .replaceAll("~1", "/");
1✔
64

1✔
65
    return `${nodePath
1✔
66
      .join("path-types", pathString)
1✔
67
      .replaceAll("\\", "/")}.types.ts`;
1✔
68
  }
1✔
69

1✔
70
  write(script) {
1✔
71
    const contextImportName = script.importDefault(
6✔
72
      new ContextCoder(this.requirement)
6✔
73
    );
6✔
74

6✔
75
    const parameters = this.requirement.get("parameters");
6✔
76

6✔
77
    const queryType =
6✔
78
      parameters === undefined
6✔
79
        ? "never"
3✔
80
        : new ParametersTypeCoder(parameters, "query").write(script);
6✔
81

6✔
82
    const pathType =
6✔
83
      parameters === undefined
6✔
84
        ? "never"
3✔
85
        : new ParametersTypeCoder(parameters, "path").write(script);
6✔
86

6✔
87
    const headerType =
6✔
88
      parameters === undefined
6✔
89
        ? "never"
3✔
90
        : new ParametersTypeCoder(parameters, "header").write(script);
6✔
91

6✔
92
    const bodyRequirement = this.requirement.get("consumes")
6✔
93
      ? parameters
4✔
94
          .find((parameter) =>
4✔
95
            ["body", "formData"].includes(parameter.get("in").data)
4✔
96
          )
4✔
97
          .get("schema")
4✔
98
      : this.requirement.select("requestBody/content/application~1json/schema");
6✔
99

6✔
100
    const bodyType = bodyRequirement
6✔
101
      ? new SchemaTypeCoder(bodyRequirement).write(script)
3✔
102
      : "undefined";
3✔
103

6✔
104
    const responseType = new ResponseTypeCoder(
6✔
105
      this.requirement.get("responses"),
6✔
106
      this.requirement.get("produces")?.data ??
6✔
107
        this.requirement.specification?.rootRequirement?.get("produces")?.data
3✔
108
    ).write(script);
6✔
109

6✔
110
    const proxyType = "(url: string) => { proxyUrl: string }";
6✔
111

6✔
112
    return `({ query, path, header, body, context, proxy }: { query: ${queryType}, path: ${pathType}, header: ${headerType}, body: ${bodyType}, context: typeof ${contextImportName}, response: ${responseType}, proxy: ${proxyType} }) => ${this.responseTypes(
6✔
113
      script
6✔
114
    )} | { status: 415, contentType: "text/plain", body: string } | void`;
6✔
115
  }
6✔
116
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc