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

pmcelhaney / counterfact / 3919348865

pending completion
3919348865

push

github

GitHub
Update dependency eslint-config-hardcore to v26

398 of 420 branches covered (94.76%)

Branch coverage included in aggregate %.

1802 of 2023 relevant lines covered (89.08%)

22.18 hits per line

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

98.57
/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(
39✔
12
      `HTTP_${this.requirement.url.split("/").at(-1).toUpperCase()}`
39✔
13
    );
39✔
14
  }
39✔
15

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

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

28✔
35
        if (response.has("schema")) {
41✔
36
          const produces =
5✔
37
            this.requirement?.get("produces")?.data ??
5!
38
            this.requirement.specification.requirementAt("#/produces").data;
×
39

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

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

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

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

20✔
65
    return `${nodePath.join("path-types", pathString)}.types.ts`;
20✔
66
  }
20✔
67

1✔
68
  write(script) {
1✔
69
    const contextImportName = script.importDefault(
24✔
70
      new ContextCoder(this.requirement)
24✔
71
    );
24✔
72

24✔
73
    const parameters = this.requirement.get("parameters");
24✔
74

24✔
75
    const queryType =
24✔
76
      parameters === undefined
24✔
77
        ? "never"
15✔
78
        : new ParametersTypeCoder(parameters, "query").write(script);
24✔
79

24✔
80
    const pathType =
24✔
81
      parameters === undefined
24✔
82
        ? "never"
15✔
83
        : new ParametersTypeCoder(parameters, "path").write(script);
24✔
84

24✔
85
    const headerType =
24✔
86
      parameters === undefined
24✔
87
        ? "never"
15✔
88
        : new ParametersTypeCoder(parameters, "header").write(script);
24✔
89

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

24✔
98
    const bodyType = bodyRequirement
24✔
99
      ? new SchemaTypeCoder(bodyRequirement).write(script)
16✔
100
      : "undefined";
16✔
101

24✔
102
    const responseType = new ResponseTypeCoder(
24✔
103
      this.requirement.get("responses"),
24✔
104
      this.requirement.get("produces")?.data
24✔
105
    ).write(script);
24✔
106

24✔
107
    const proxyType = "(url: string) => { proxyUrl: string }";
24✔
108

24✔
109
    return `({ query, path, header, body, context, proxy }: { query: ${queryType}, path: ${pathType}, header: ${headerType}, body: ${bodyType}, context: typeof ${contextImportName}, response: ${responseType}, proxy: ${proxyType} }) => ${this.responseTypes(
24✔
110
      script
24✔
111
    )} | { status: 415, contentType: "text/plain", body: string } | void`;
24✔
112
  }
24✔
113
}
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

© 2025 Coveralls, Inc