@clov-std/elysia-openapi 1.0.1 → 1.1.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/index.js +8 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -196,7 +196,7 @@ var toRequestBody = (hooks, models, method) => {
|
|
|
196
196
|
]))
|
|
197
197
|
};
|
|
198
198
|
};
|
|
199
|
-
var toResponseContent = (schemas, models) => {
|
|
199
|
+
var toResponseContent = (schemas, models, status) => {
|
|
200
200
|
const [first] = schemas;
|
|
201
201
|
const resolved = resolveModel(first, models);
|
|
202
202
|
const type = jsonTypeOf(resolved);
|
|
@@ -217,8 +217,13 @@ var toResponseContent = (schemas, models) => {
|
|
|
217
217
|
{ schema: toCombinedSchema(group, "anyOf") }
|
|
218
218
|
]));
|
|
219
219
|
}
|
|
220
|
+
const isProblem = Number(status) >= 400 && schemas.every((schema) => {
|
|
221
|
+
const required = objectShapeOf(schema, models)?.required;
|
|
222
|
+
return required?.has("type") === true && required.has("status");
|
|
223
|
+
});
|
|
224
|
+
const mediaType = isProblem ? "application/problem+json" : "application/json";
|
|
220
225
|
return {
|
|
221
|
-
[isText(first, models) ? "text/plain" :
|
|
226
|
+
[isText(first, models) ? "text/plain" : mediaType]: {
|
|
222
227
|
schema: toCombinedSchema(schemas, "anyOf")
|
|
223
228
|
}
|
|
224
229
|
};
|
|
@@ -243,7 +248,7 @@ var toResponseHeaders = (schema, models) => {
|
|
|
243
248
|
var toResponses = (route, models) => Object.fromEntries(Object.entries(route.responses).map(([status, schemas]) => {
|
|
244
249
|
const description = descriptionOf(resolveModel(schemas[0], models)) ?? StatusMapBack[status];
|
|
245
250
|
const headers = toResponseHeaders(schemas[0], models);
|
|
246
|
-
const content = toResponseContent(schemas, models);
|
|
251
|
+
const content = toResponseContent(schemas, models, status);
|
|
247
252
|
return [
|
|
248
253
|
status,
|
|
249
254
|
{
|