@clov-std/elysia-openapi 1.0.1 → 1.1.0-rc.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.
Files changed (2) hide show
  1. package/dist/index.js +8 -3
  2. 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" : "application/json"]: {
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
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clov-std/elysia-openapi",
3
- "version": "1.0.1",
3
+ "version": "1.1.0-rc.1",
4
4
  "description": "OpenAPI 3.2 document and Scalar reference for Elysia, generated from your route schemas.",
5
5
  "keywords": [
6
6
  "elysia",