typed-openapi 2.2.3 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ts-factory.ts CHANGED
@@ -3,12 +3,17 @@ import { createFactory, unwrap } from "./box-factory.ts";
3
3
  import { wrapWithQuotesIfNeeded } from "./string-utils.ts";
4
4
 
5
5
  export const tsFactory = createFactory({
6
- union: (types) => `(${types.map(unwrap).join(" | ")})`,
7
- intersection: (types) => `(${types.map(unwrap).join(" & ")})`,
6
+ union: (types) => (types.length ? `(${types.map(unwrap).join(" | ")})` : "never"),
7
+ intersection: (types) => (types.length ? `(${types.map(unwrap).join(" & ")})` : "unknown"),
8
8
  array: (type) => `Array<${unwrap(type)}>`,
9
9
  optional: (type) => `${unwrap(type)} | undefined`,
10
10
  reference: (name, typeArgs) => `${name}${typeArgs ? `<${typeArgs.map(unwrap).join(", ")}>` : ""}`,
11
- literal: (value) => value.toString(),
11
+ literal: (value) => {
12
+ if (typeof value === "string") return value;
13
+ if (Box.isBox(value)) return unwrap(value);
14
+ if (Array.isArray(value) || typeof value === "object") return JSON.stringify(value);
15
+ return String(value);
16
+ },
12
17
  string: () => "string" as const,
13
18
  number: () => "number" as const,
14
19
  boolean: () => "boolean" as const,
@@ -1,21 +0,0 @@
1
- // src/format.ts
2
- import prettier from "prettier";
3
- import parserTypescript from "prettier/parser-typescript";
4
- function maybePretty(input, options) {
5
- try {
6
- return prettier.format(input, {
7
- parser: "typescript",
8
- plugins: [parserTypescript],
9
- ...options
10
- });
11
- } catch (err) {
12
- console.warn("Failed to format code");
13
- console.warn(err);
14
- return input;
15
- }
16
- }
17
- var prettify = (str, options) => maybePretty(str, { printWidth: 120, trailingComma: "all", ...options });
18
-
19
- export {
20
- prettify
21
- };