nestjs-openapi 0.1.4 → 0.2.0
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/dist/cli.mjs +84 -22
- package/dist/index.d.mts +157 -738
- package/dist/index.d.ts +157 -738
- package/dist/index.mjs +31 -85
- package/dist/internal.d.mts +2 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.mjs +52 -45
- package/dist/shared/nestjs-openapi.D0Osp4GW.d.mts +2275 -0
- package/dist/shared/nestjs-openapi.D0Osp4GW.d.ts +2275 -0
- package/dist/shared/nestjs-openapi.P9V98nna.mjs +5504 -0
- package/package.json +5 -1
- package/dist/shared/nestjs-openapi.CUKGdNSM.mjs +0 -2336
- package/dist/shared/nestjs-openapi.ClTIhsb-.d.mts +0 -440
- package/dist/shared/nestjs-openapi.ClTIhsb-.d.ts +0 -440
- package/dist/shared/nestjs-openapi.DRcy130f.mjs +0 -1571
package/dist/cli.mjs
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import 'tsx';
|
|
3
|
-
import {
|
|
3
|
+
import { Effect, Exit, Cause, Option } from 'effect';
|
|
4
|
+
import { ax as generateEffect, ak as generatorServicesLayer, az as runtimeLayerFor, aw as formatValidationResult } from './shared/nestjs-openapi.P9V98nna.mjs';
|
|
4
5
|
import minimist from 'minimist';
|
|
5
6
|
import { relative } from 'node:path';
|
|
6
7
|
import { createRequire } from 'node:module';
|
|
7
|
-
import 'effect';
|
|
8
8
|
import 'node:fs';
|
|
9
9
|
import 'node:crypto';
|
|
10
10
|
import 'ts-morph';
|
|
11
11
|
import 'glob';
|
|
12
|
-
import 'js-yaml';
|
|
13
|
-
import './shared/nestjs-openapi.DRcy130f.mjs';
|
|
14
|
-
import 'ts-json-schema-generator';
|
|
15
12
|
import 'node:url';
|
|
16
13
|
import 'child_process';
|
|
14
|
+
import 'js-yaml';
|
|
15
|
+
import 'ts-json-schema-generator';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_ERROR_MESSAGE = "OpenAPI generation failed";
|
|
18
|
+
const toUserFacingErrorMessage = (error) => error && typeof error === "object" && "message" in error && typeof error.message === "string" ? error.message : DEFAULT_ERROR_MESSAGE;
|
|
17
19
|
|
|
18
20
|
const require = createRequire(import.meta.url);
|
|
19
21
|
const pkg = require("../package.json");
|
|
@@ -31,6 +33,10 @@ Options:
|
|
|
31
33
|
-f, --format <format> Output format: json or yaml (overrides config)
|
|
32
34
|
-q, --quiet Suppress output (only show errors)
|
|
33
35
|
-d, --debug Enable debug output (verbose logging, full stack traces)
|
|
36
|
+
--otel Enable OpenTelemetry tracing
|
|
37
|
+
--otel-exporter OTel exporter: console or otlp (default: console)
|
|
38
|
+
--otel-endpoint OTLP HTTP endpoint (default: http://localhost:4318/v1/traces)
|
|
39
|
+
--otel-service-name Service name for trace resource (default: nestjs-openapi)
|
|
34
40
|
-h, --help Show this help message
|
|
35
41
|
-v, --version Show version
|
|
36
42
|
|
|
@@ -38,6 +44,7 @@ Examples:
|
|
|
38
44
|
nestjs-openapi generate -c openapi.config.ts
|
|
39
45
|
nestjs-openapi generate -c openapi.config.ts --format yaml
|
|
40
46
|
nestjs-openapi generate -c openapi.config.ts --debug
|
|
47
|
+
nestjs-openapi generate -c openapi.config.ts --otel --otel-exporter console
|
|
41
48
|
`.trim();
|
|
42
49
|
const formatDuration = (ms) => {
|
|
43
50
|
if (ms < 1e3) return `${ms}ms`;
|
|
@@ -52,10 +59,30 @@ const warning = (message) => {
|
|
|
52
59
|
const error = (message) => {
|
|
53
60
|
console.error(`\x1B[31m\u2717\x1B[0m ${message}`);
|
|
54
61
|
};
|
|
62
|
+
const formatCauseForDebug = (cause) => {
|
|
63
|
+
if (!cause || typeof cause !== "object") {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
if ("stack" in cause && typeof cause.stack === "string") {
|
|
67
|
+
return cause.stack;
|
|
68
|
+
}
|
|
69
|
+
if ("cause" in cause && cause.cause !== void 0) {
|
|
70
|
+
return String(cause.cause);
|
|
71
|
+
}
|
|
72
|
+
return void 0;
|
|
73
|
+
};
|
|
55
74
|
const main = async () => {
|
|
56
75
|
const args = minimist(process.argv.slice(2), {
|
|
57
|
-
string: [
|
|
58
|
-
|
|
76
|
+
string: [
|
|
77
|
+
"c",
|
|
78
|
+
"config",
|
|
79
|
+
"f",
|
|
80
|
+
"format",
|
|
81
|
+
"otel-exporter",
|
|
82
|
+
"otel-endpoint",
|
|
83
|
+
"otel-service-name"
|
|
84
|
+
],
|
|
85
|
+
boolean: ["quiet", "q", "debug", "d", "otel", "help", "h", "version", "v"],
|
|
59
86
|
alias: {
|
|
60
87
|
c: "config",
|
|
61
88
|
f: "format",
|
|
@@ -85,8 +112,12 @@ const main = async () => {
|
|
|
85
112
|
}
|
|
86
113
|
const configPath = args.config || args.c;
|
|
87
114
|
const format = args.format || args.f;
|
|
88
|
-
const quiet = args.quiet || args.q;
|
|
89
|
-
const debug = args.debug || args.d;
|
|
115
|
+
const quiet = Boolean(args.quiet || args.q);
|
|
116
|
+
const debug = Boolean(args.debug || args.d);
|
|
117
|
+
const otel = Boolean(args.otel);
|
|
118
|
+
const otelExporter = args["otel-exporter"];
|
|
119
|
+
const otelEndpoint = args["otel-endpoint"];
|
|
120
|
+
const otelServiceName = args["otel-service-name"];
|
|
90
121
|
if (!configPath) {
|
|
91
122
|
error("Config path is required. Use -c or --config to specify the path.");
|
|
92
123
|
console.log("\nExample: nestjs-openapi generate -c openapi.config.ts");
|
|
@@ -96,12 +127,29 @@ const main = async () => {
|
|
|
96
127
|
error(`Invalid format: ${format}. Must be 'json' or 'yaml'.`);
|
|
97
128
|
process.exit(1);
|
|
98
129
|
}
|
|
130
|
+
if (otelExporter && otelExporter !== "console" && otelExporter !== "otlp") {
|
|
131
|
+
error(`Invalid --otel-exporter: ${otelExporter}. Must be 'console' or 'otlp'.`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
const telemetry = otel ? {
|
|
135
|
+
enabled: true,
|
|
136
|
+
exporter: otelExporter ?? "console",
|
|
137
|
+
otlpEndpoint: otelEndpoint,
|
|
138
|
+
serviceName: otelServiceName
|
|
139
|
+
} : void 0;
|
|
99
140
|
const startTime = performance.now();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
141
|
+
const program = generateEffect(configPath, {
|
|
142
|
+
format,
|
|
143
|
+
debug,
|
|
144
|
+
telemetry
|
|
145
|
+
}).pipe(
|
|
146
|
+
Effect.provide(generatorServicesLayer),
|
|
147
|
+
Effect.provide(runtimeLayerFor(debug, telemetry)),
|
|
148
|
+
Effect.exit
|
|
149
|
+
);
|
|
150
|
+
const exit = await Effect.runPromise(program);
|
|
151
|
+
if (Exit.isSuccess(exit)) {
|
|
152
|
+
const result = exit.value;
|
|
105
153
|
const duration = performance.now() - startTime;
|
|
106
154
|
if (!quiet) {
|
|
107
155
|
const relativePath = relative(process.cwd(), result.outputPath);
|
|
@@ -118,17 +166,31 @@ const main = async () => {
|
|
|
118
166
|
}
|
|
119
167
|
}
|
|
120
168
|
process.exit(result.validation.valid ? 0 : 1);
|
|
121
|
-
}
|
|
169
|
+
} else {
|
|
122
170
|
const duration = performance.now() - startTime;
|
|
123
|
-
const
|
|
171
|
+
const failure = Cause.failureOption(exit.cause);
|
|
172
|
+
const message = failure.pipe(
|
|
173
|
+
Option.map(toUserFacingErrorMessage),
|
|
174
|
+
Option.getOrElse(() => toUserFacingErrorMessage(void 0))
|
|
175
|
+
);
|
|
124
176
|
error(`Generation failed (${formatDuration(Math.round(duration))})`);
|
|
125
177
|
console.error(` ${message}`);
|
|
126
|
-
if (debug
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
178
|
+
if (debug) {
|
|
179
|
+
failure.pipe(
|
|
180
|
+
Option.map(formatCauseForDebug),
|
|
181
|
+
Option.match({
|
|
182
|
+
onNone: () => void 0,
|
|
183
|
+
onSome: (debugOutput) => {
|
|
184
|
+
if (debugOutput) {
|
|
185
|
+
console.error("\nStack trace:");
|
|
186
|
+
console.error(debugOutput);
|
|
187
|
+
} else {
|
|
188
|
+
console.error("\nCause:");
|
|
189
|
+
console.error(Cause.pretty(exit.cause));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
);
|
|
132
194
|
}
|
|
133
195
|
process.exit(1);
|
|
134
196
|
}
|