• 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

98.84
/src/typescript-generator/schema-type-coder.js
1
import { Coder } from "./coder.js";
1✔
2

1✔
3
export class SchemaTypeCoder extends Coder {
1✔
4
  names() {
1✔
5
    return super.names(this.requirement.data.$ref.split("/").at(-1));
1✔
6
  }
1✔
7

1✔
8
  additionalPropertiesType(script) {
1✔
9
    const { properties, additionalProperties } = this.requirement.data;
4✔
10

4✔
11
    if (!additionalProperties.type) {
4✔
12
      return "unknown";
1✔
13
    }
1✔
14

3✔
15
    if (
3✔
16
      Object.values(properties ?? {}).some(
4✔
17
        (property) => property.type !== additionalProperties.type
4✔
18
      )
4✔
19
    ) {
4✔
20
      return "unknown";
1✔
21
    }
1✔
22

2✔
23
    const requirement = this.requirement.get("additionalProperties");
2✔
24

2✔
25
    return new SchemaTypeCoder(requirement).write(script);
2✔
26
  }
2✔
27

1✔
28
  objectSchema(script) {
1✔
29
    const { data } = this.requirement;
7✔
30

7✔
31
    const properties = Object.keys(data.properties ?? {}).map((name) => {
7✔
32
      const property = this.requirement.get("properties").get(name);
13✔
33

13✔
34
      const isRequired =
13✔
35
        data.required?.includes(name) || property.data.required;
13✔
36
      const optionalFlag = isRequired ? "" : "?";
13✔
37

13✔
38
      return `${name}${optionalFlag}: ${new SchemaTypeCoder(property).write(
13✔
39
        script
13✔
40
      )}`;
13✔
41
    });
13✔
42

7✔
43
    if (data.additionalProperties) {
7✔
44
      properties.push(
4✔
45
        `[key: string]: ${this.additionalPropertiesType(script)}`
4✔
46
      );
4✔
47
    }
4✔
48

7✔
49
    return `{${properties.join(",")}}`;
7✔
50
  }
7✔
51

1✔
52
  arraySchema(script) {
1✔
53
    return `Array<${new SchemaTypeCoder(this.requirement.get("items")).write(
1✔
54
      script
1✔
55
    )}>`;
1✔
56
  }
1✔
57

1✔
58
  writeType(script, type) {
1✔
59
    if (type === "object") {
51✔
60
      return this.objectSchema(script);
7✔
61
    }
7✔
62

44✔
63
    if (type === "array") {
51✔
64
      return this.arraySchema(script);
1✔
65
    }
1✔
66

43✔
67
    if (type === "integer") {
51✔
68
      return "number";
5✔
69
    }
5✔
70

38✔
71
    return type ?? "unknown";
51✔
72
  }
51✔
73

1✔
74
  writeGroup(script, { allOf, anyOf, oneOf }) {
1✔
75
    function matchingKey() {
3✔
76
      if (allOf) {
6✔
77
        return "allOf";
2✔
78
      }
2✔
79

4✔
80
      if (anyOf) {
6✔
81
        return "anyOf";
2✔
82
      }
2✔
83

2✔
84
      return "oneOf";
2✔
85
    }
2✔
86

3✔
87
    const types = (allOf ?? anyOf ?? oneOf).map((item, index) =>
3✔
88
      new SchemaTypeCoder(this.requirement.get(matchingKey()).get(index)).write(
3✔
89
        script
3✔
90
      )
3✔
91
    );
3✔
92

3✔
93
    return types.join(allOf ? " & " : " | ");
3✔
94
  }
3✔
95

1✔
96
  writeEnum(script, requirement) {
1✔
97
    return requirement.data
1✔
98
      .map((item) => (typeof item === "string" ? `"${item}"` : item))
1✔
99
      .join(" | ");
1✔
100
  }
1✔
101

1✔
102
  modulePath() {
1✔
103
    return `components/${this.requirement.data.$ref.split("/").at(-1)}.ts`;
×
104
  }
×
105

1✔
106
  write(script) {
1✔
107
    if (this.requirement.isReference) {
83✔
108
      return script.importType(this);
28✔
109
    }
28✔
110

55✔
111
    const { type, allOf, anyOf, oneOf } = this.requirement.data;
55✔
112

55✔
113
    if (allOf ?? anyOf ?? oneOf) {
83✔
114
      return this.writeGroup(script, { allOf, anyOf, oneOf });
3✔
115
    }
3✔
116

52✔
117
    if (this.requirement.has("enum")) {
83✔
118
      return this.writeEnum(script, this.requirement.get("enum"));
1✔
119
    }
1✔
120

51✔
121
    return this.writeType(script, type);
51✔
122
  }
51✔
123
}
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