@clov-std/elysia-openapi 1.2.0 → 1.2.1
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/index.js +17 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Elysia } from "elysia";
|
|
|
4
4
|
|
|
5
5
|
// src/document.ts
|
|
6
6
|
import { StatusMapBack } from "elysia";
|
|
7
|
+
import { isProduction } from "elysia/error";
|
|
7
8
|
import { isRecordNumber } from "elysia/utils";
|
|
8
9
|
import { IsOptional, IsUnion as IsUnion2 } from "typebox";
|
|
9
10
|
|
|
@@ -285,31 +286,36 @@ var mergeRequestBody = (generated, override) => {
|
|
|
285
286
|
return { ...generated, ...override, content };
|
|
286
287
|
};
|
|
287
288
|
var VALIDATION_PROBLEM = "validation";
|
|
288
|
-
var validationProblemSchema = {
|
|
289
|
+
var validationProblemSchema = () => ({
|
|
289
290
|
type: "object",
|
|
290
291
|
description: "The request failed validation.",
|
|
291
|
-
required: ["type", "title", "status", "detail"],
|
|
292
|
+
required: isProduction() ? ["type", "title", "status"] : ["type", "title", "status", "detail"],
|
|
292
293
|
properties: {
|
|
293
294
|
type: { type: "string", const: VALIDATION_PROBLEM },
|
|
294
295
|
code: { type: "string", const: VALIDATION_PROBLEM },
|
|
295
296
|
title: { type: "string", example: "Validation Error" },
|
|
296
297
|
status: { type: "integer", const: 422 },
|
|
297
|
-
detail: { type: "string", description: "The first validation error, in words." },
|
|
298
298
|
on: {
|
|
299
299
|
type: "string",
|
|
300
300
|
enum: ["params", "query", "headers", "cookie", "body"],
|
|
301
301
|
description: "The part of the request that failed."
|
|
302
302
|
},
|
|
303
303
|
property: { type: "string", description: "Path of the first invalid property." },
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
304
|
+
...isProduction() ? {} : {
|
|
305
|
+
detail: {
|
|
306
|
+
type: "string",
|
|
307
|
+
description: "The first validation error, in words."
|
|
308
|
+
},
|
|
309
|
+
found: { description: "The value received." },
|
|
310
|
+
expected: { description: "A value of the expected shape." },
|
|
311
|
+
errors: {
|
|
312
|
+
type: "array",
|
|
313
|
+
description: "Every validation error.",
|
|
314
|
+
items: { type: "object" }
|
|
315
|
+
}
|
|
310
316
|
}
|
|
311
317
|
}
|
|
312
|
-
};
|
|
318
|
+
});
|
|
313
319
|
var validationResponse = {
|
|
314
320
|
description: "Unprocessable Content",
|
|
315
321
|
content: {
|
|
@@ -318,7 +324,7 @@ var validationResponse = {
|
|
|
318
324
|
}
|
|
319
325
|
}
|
|
320
326
|
};
|
|
321
|
-
var validationComponent = (operations) => operations.some((operation) => operation.responses?.["422"] === validationResponse) ? { [VALIDATION_PROBLEM]: validationProblemSchema } : {};
|
|
327
|
+
var validationComponent = (operations) => operations.some((operation) => operation.responses?.["422"] === validationResponse) ? { [VALIDATION_PROBLEM]: validationProblemSchema() } : {};
|
|
322
328
|
var toOperation = (route, models, method) => {
|
|
323
329
|
const { hooks } = route;
|
|
324
330
|
const parameters = new Map;
|