@skmtc/core 0.30.1 → 0.32.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.
Files changed (79) hide show
  1. package/esm/context/generateTypes.d.ts +14 -2
  2. package/esm/context/generateTypes.js +3 -1
  3. package/esm/mod.d.ts +1 -0
  4. package/esm/mod.js +1 -0
  5. package/esm/oas/header/Header.d.ts +4 -2
  6. package/esm/oas/header/Header.js +12 -5
  7. package/esm/oas/mediaType/jsonMediaType.d.ts +50 -0
  8. package/esm/oas/mediaType/jsonMediaType.js +64 -0
  9. package/esm/oas/mediaType/toContentSchema.d.ts +8 -0
  10. package/esm/oas/mediaType/toContentSchema.js +6 -0
  11. package/esm/oas/operation/Operation.d.ts +10 -2
  12. package/esm/oas/operation/Operation.js +20 -7
  13. package/esm/oas/parameter/Parameter.d.ts +1 -1
  14. package/esm/oas/parameter/Parameter.js +7 -4
  15. package/esm/oas/pathItem/PathItem.d.ts +5 -0
  16. package/esm/oas/pathItem/PathItem.js +8 -0
  17. package/esm/oas/requestBody/RequestBody.d.ts +11 -0
  18. package/esm/oas/requestBody/RequestBody.js +16 -2
  19. package/esm/oas/response/Response.d.ts +11 -0
  20. package/esm/oas/response/Response.js +16 -2
  21. package/esm/oas/webhook/Webhook.d.ts +4 -4
  22. package/esm/oas/webhook/Webhook.js +6 -6
  23. package/esm/parse/logBodyMediaTypes.d.ts +27 -0
  24. package/esm/parse/logBodyMediaTypes.js +50 -0
  25. package/esm/parse/v3-0/parameter/toParameterV3.d.ts +3 -2
  26. package/esm/parse/v3-0/parameter/toParameterV3.js +3 -2
  27. package/esm/parse/v3-0/pathItem/toPathItemV3.js +11 -1
  28. package/esm/parse/v3-0/requestBody/toRequestBodiesV3.js +4 -1
  29. package/esm/parse/v3-0/response/toResponseV3.js +4 -1
  30. package/esm/parse/v3-1/parameter/toParameterV3.d.ts +3 -2
  31. package/esm/parse/v3-1/parameter/toParameterV3.js +3 -2
  32. package/esm/parse/v3-1/pathItem/toPathItemV3.js +11 -1
  33. package/esm/parse/v3-1/requestBody/toRequestBodiesV3.js +4 -1
  34. package/esm/parse/v3-1/response/toResponseV3.js +4 -1
  35. package/esm/parse/v3-2/parameter/toParameterV3.d.ts +2 -2
  36. package/esm/parse/v3-2/parameter/toParameterV3.js +3 -2
  37. package/esm/parse/v3-2/pathItem/toPathItemV3.js +11 -1
  38. package/esm/parse/v3-2/requestBody/toRequestBodiesV3.js +4 -1
  39. package/esm/parse/v3-2/response/toResponseV3.js +4 -1
  40. package/package.json +1 -1
  41. package/script/context/generateTypes.d.ts +14 -2
  42. package/script/context/generateTypes.js +3 -1
  43. package/script/mod.d.ts +1 -0
  44. package/script/mod.js +1 -0
  45. package/script/oas/header/Header.d.ts +4 -2
  46. package/script/oas/header/Header.js +12 -5
  47. package/script/oas/mediaType/jsonMediaType.d.ts +50 -0
  48. package/script/oas/mediaType/jsonMediaType.js +71 -0
  49. package/script/oas/mediaType/toContentSchema.d.ts +8 -0
  50. package/script/oas/mediaType/toContentSchema.js +10 -0
  51. package/script/oas/operation/Operation.d.ts +10 -2
  52. package/script/oas/operation/Operation.js +20 -7
  53. package/script/oas/parameter/Parameter.d.ts +1 -1
  54. package/script/oas/parameter/Parameter.js +7 -4
  55. package/script/oas/pathItem/PathItem.d.ts +5 -0
  56. package/script/oas/pathItem/PathItem.js +8 -0
  57. package/script/oas/requestBody/RequestBody.d.ts +11 -0
  58. package/script/oas/requestBody/RequestBody.js +16 -2
  59. package/script/oas/response/Response.d.ts +11 -0
  60. package/script/oas/response/Response.js +16 -2
  61. package/script/oas/webhook/Webhook.d.ts +4 -4
  62. package/script/oas/webhook/Webhook.js +6 -6
  63. package/script/parse/logBodyMediaTypes.d.ts +27 -0
  64. package/script/parse/logBodyMediaTypes.js +54 -0
  65. package/script/parse/v3-0/parameter/toParameterV3.d.ts +3 -2
  66. package/script/parse/v3-0/parameter/toParameterV3.js +3 -2
  67. package/script/parse/v3-0/pathItem/toPathItemV3.js +11 -1
  68. package/script/parse/v3-0/requestBody/toRequestBodiesV3.js +4 -1
  69. package/script/parse/v3-0/response/toResponseV3.js +4 -1
  70. package/script/parse/v3-1/parameter/toParameterV3.d.ts +3 -2
  71. package/script/parse/v3-1/parameter/toParameterV3.js +3 -2
  72. package/script/parse/v3-1/pathItem/toPathItemV3.js +11 -1
  73. package/script/parse/v3-1/requestBody/toRequestBodiesV3.js +4 -1
  74. package/script/parse/v3-1/response/toResponseV3.js +4 -1
  75. package/script/parse/v3-2/parameter/toParameterV3.d.ts +2 -2
  76. package/script/parse/v3-2/parameter/toParameterV3.js +3 -2
  77. package/script/parse/v3-2/pathItem/toPathItemV3.js +11 -1
  78. package/script/parse/v3-2/requestBody/toRequestBodiesV3.js +4 -1
  79. package/script/parse/v3-2/response/toResponseV3.js +4 -1
@@ -0,0 +1,8 @@
1
+ import type { OasRef } from '../ref/Ref.js';
2
+ import type { OasSchema } from '../schema/Schema.js';
3
+ import type { OasMediaType } from './MediaType.js';
4
+ /**
5
+ * The schema a `toSchema(mediaType?)` lookup returns: an exact key lookup when
6
+ * `mediaType` is given, else the schema of `toJsonContent`.
7
+ */
8
+ export declare const toContentSchema: (content: Record<string, OasMediaType> | undefined, mediaType: string | undefined) => OasSchema | OasRef<"schema"> | undefined;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toContentSchema = void 0;
4
+ const jsonMediaType_js_1 = require("./jsonMediaType.js");
5
+ /**
6
+ * The schema a `toSchema(mediaType?)` lookup returns: an exact key lookup when
7
+ * `mediaType` is given, else the schema of `toJsonContent`.
8
+ */
9
+ const toContentSchema = (content, mediaType) => mediaType === undefined ? (0, jsonMediaType_js_1.toJsonContent)(content)?.schema : content?.[mediaType]?.schema;
10
+ exports.toContentSchema = toContentSchema;
@@ -60,6 +60,14 @@ export type OperationFields = {
60
60
  export type ToRequestBodyMapArgs = {
61
61
  schema: OasSchema | OasRef<'schema'>;
62
62
  requestBody: OasRequestBody;
63
+ /** The `content` key the schema was read from. */
64
+ mediaType: string;
65
+ /**
66
+ * The media type to send the body as: the explicit media type when one was
67
+ * passed, else `contentType` of `OasRequestBody.toJsonContent` (the
68
+ * JSON-like key, or `application/json` for a body read from `*\/*`).
69
+ */
70
+ contentType: string;
63
71
  };
64
72
  export declare class OasOperation extends OasBase {
65
73
  /** Type identifier for OAS operation objects */
@@ -120,7 +128,7 @@ export declare class OasOperation extends OasBase {
120
128
  * Maps the request body schema to a custom value using the provided mapping function.
121
129
  *
122
130
  * @param map - Function to transform the request body schema and metadata
123
- * @param mediaType - Media type to extract schema from (default: 'application/json')
131
+ * @param mediaType - Media type to extract schema from, an exact lookup. Omitted: the media type `OasRequestBody.toJsonContent` picks.
124
132
  * @returns Mapped value or undefined if no request body schema found
125
133
  */
126
134
  toRequestBody<V>(map: ({ schema, requestBody }: ToRequestBodyMapArgs) => V, mediaType?: string): V | undefined;
@@ -133,7 +141,7 @@ export declare class OasOperation extends OasBase {
133
141
  * {@link traverseSchema}.
134
142
  *
135
143
  * @param path - Schema path; `path[0]` must be `'SuccessResponse'` or `'RequestBody'`.
136
- * @param mediaType - Media type the body schema is read from (default `application/json`).
144
+ * @param mediaType - Media type the body schema is read from, an exact lookup. Omitted: the JSON media type (`application/json`, else the first JSON-like type, else `*\/*`).
137
145
  * @returns The schema at the path (may be an unresolved `$ref`).
138
146
  * @throws Error on an unknown root, a missing response/request body, or a non-navigable segment.
139
147
  */
@@ -167,13 +167,25 @@ class OasOperation extends OasBase_js_1.OasBase {
167
167
  * Maps the request body schema to a custom value using the provided mapping function.
168
168
  *
169
169
  * @param map - Function to transform the request body schema and metadata
170
- * @param mediaType - Media type to extract schema from (default: 'application/json')
170
+ * @param mediaType - Media type to extract schema from, an exact lookup. Omitted: the media type `OasRequestBody.toJsonContent` picks.
171
171
  * @returns Mapped value or undefined if no request body schema found
172
172
  */
173
- toRequestBody(map, mediaType = 'application/json') {
173
+ toRequestBody(map, mediaType) {
174
174
  const requestBody = this.requestBody?.resolve();
175
- const schema = requestBody?.content[mediaType]?.schema;
176
- return schema ? map({ schema, requestBody }) : undefined;
175
+ if (!requestBody) {
176
+ return undefined;
177
+ }
178
+ const chosen = mediaType === undefined
179
+ ? requestBody.toJsonContent()
180
+ : { mediaType, contentType: mediaType, schema: requestBody.toSchema(mediaType) };
181
+ return chosen?.schema
182
+ ? map({
183
+ schema: chosen.schema,
184
+ requestBody,
185
+ mediaType: chosen.mediaType,
186
+ contentType: chosen.contentType
187
+ })
188
+ : undefined;
177
189
  }
178
190
  /**
179
191
  * Navigate into this operation's response or request body schema along an
@@ -184,11 +196,11 @@ class OasOperation extends OasBase_js_1.OasBase {
184
196
  * {@link traverseSchema}.
185
197
  *
186
198
  * @param path - Schema path; `path[0]` must be `'SuccessResponse'` or `'RequestBody'`.
187
- * @param mediaType - Media type the body schema is read from (default `application/json`).
199
+ * @param mediaType - Media type the body schema is read from, an exact lookup. Omitted: the JSON media type (`application/json`, else the first JSON-like type, else `*\/*`).
188
200
  * @returns The schema at the path (may be an unresolved `$ref`).
189
201
  * @throws Error on an unknown root, a missing response/request body, or a non-navigable segment.
190
202
  */
191
- traverse(path, mediaType = 'application/json') {
203
+ traverse(path, mediaType) {
192
204
  const [root, ...rest] = path;
193
205
  let rootSchema;
194
206
  switch (root) {
@@ -203,7 +215,8 @@ class OasOperation extends OasBase_js_1.OasBase {
203
215
  }
204
216
  if (!rootSchema) {
205
217
  const label = root === 'SuccessResponse' ? 'success response' : 'request body';
206
- throw new Error(`Operation "${this.method} ${this.path}" has no ${label} schema for media type "${mediaType}"`);
218
+ const mediaTypeLabel = mediaType === undefined ? 'a JSON media type' : `media type "${mediaType}"`;
219
+ throw new Error(`Operation "${this.method} ${this.path}" has no ${label} schema for ${mediaTypeLabel}`);
207
220
  }
208
221
  return (0, traverseSchema_js_1.traverseSchema)(rootSchema, rest);
209
222
  }
@@ -243,7 +243,7 @@ export declare class OasParameter extends OasBase {
243
243
  * for the specified media type. When `content` has exactly one entry, its
244
244
  * schema is used whatever the media type.
245
245
  *
246
- * @param mediaType - Media type to extract schema from when using content definitions
246
+ * @param mediaType - Media type to extract schema from when using content definitions, an exact lookup. Omitted: the JSON media type (`application/json`, else the first JSON-like type, else `*\/*`).
247
247
  * @returns The parameter's schema object
248
248
  * @throws Error if no schema is found for the specified media type
249
249
  */
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasParameter = void 0;
4
4
  require("../../_dnt.polyfills.js");
5
5
  const OasBase_js_1 = require("../../types/OasBase.js");
6
+ const toContentSchema_js_1 = require("../mediaType/toContentSchema.js");
6
7
  /**
7
8
  * Represents a Parameter Object in the OpenAPI Specification.
8
9
  *
@@ -298,19 +299,21 @@ class OasParameter extends OasBase_js_1.OasBase {
298
299
  * for the specified media type. When `content` has exactly one entry, its
299
300
  * schema is used whatever the media type.
300
301
  *
301
- * @param mediaType - Media type to extract schema from when using content definitions
302
+ * @param mediaType - Media type to extract schema from when using content definitions, an exact lookup. Omitted: the JSON media type (`application/json`, else the first JSON-like type, else `*\/*`).
302
303
  * @returns The parameter's schema object
303
304
  * @throws Error if no schema is found for the specified media type
304
305
  */
305
- toSchema(mediaType = 'application/json') {
306
+ toSchema(mediaType) {
306
307
  if (this.schema) {
307
308
  return this.schema;
308
309
  }
309
310
  const contentEntries = Object.values(this.content ?? {});
310
311
  const onlyEntry = contentEntries.length === 1 ? contentEntries[0] : undefined;
311
- const schema = this.content?.[mediaType]?.schema ?? onlyEntry?.schema;
312
+ const schema = (0, toContentSchema_js_1.toContentSchema)(this.content, mediaType) ?? onlyEntry?.schema;
312
313
  if (!schema) {
313
- throw new Error(`Schema not found for media type ${mediaType}`);
314
+ throw new Error(mediaType === undefined
315
+ ? 'Schema not found for a JSON media type'
316
+ : `Schema not found for media type "${mediaType}"`);
314
317
  }
315
318
  return schema;
316
319
  }
@@ -1,5 +1,6 @@
1
1
  import type { OasParameter } from '../parameter/Parameter.js';
2
2
  import type { OasRef } from '../ref/Ref.js';
3
+ import type { OasServer } from '../server/Server.js';
3
4
  /**
4
5
  * Constructor fields for {@link OasPathItem}.
5
6
  */
@@ -10,6 +11,8 @@ export type PathItemFields = {
10
11
  description?: string | undefined;
11
12
  /** Parameters that are applicable for all operations on this path */
12
13
  parameters?: (OasParameter | OasRef<'parameter'>)[] | undefined;
14
+ /** Servers that replace the document's servers for all operations on this path */
15
+ servers?: OasServer[] | undefined;
13
16
  /** Custom extension fields (x-* properties) */
14
17
  extensionFields?: Record<string, unknown>;
15
18
  };
@@ -103,6 +106,8 @@ export declare class OasPathItem {
103
106
  summary: string | undefined;
104
107
  description: string | undefined;
105
108
  parameters: (OasParameter | OasRef<'parameter'>)[] | undefined;
109
+ /** Servers that replace the document's servers for all operations on this path */
110
+ servers: OasServer[] | undefined;
106
111
  extensionFields: Record<string, unknown> | undefined;
107
112
  constructor(fields?: PathItemFields);
108
113
  }
@@ -112,6 +112,13 @@ class OasPathItem {
112
112
  writable: true,
113
113
  value: void 0
114
114
  });
115
+ /** Servers that replace the document's servers for all operations on this path */
116
+ Object.defineProperty(this, "servers", {
117
+ enumerable: true,
118
+ configurable: true,
119
+ writable: true,
120
+ value: void 0
121
+ });
115
122
  Object.defineProperty(this, "extensionFields", {
116
123
  enumerable: true,
117
124
  configurable: true,
@@ -121,6 +128,7 @@ class OasPathItem {
121
128
  this.summary = fields.summary;
122
129
  this.description = fields.description;
123
130
  this.parameters = fields.parameters;
131
+ this.servers = fields.servers;
124
132
  this.extensionFields = fields.extensionFields;
125
133
  }
126
134
  }
@@ -6,6 +6,7 @@ import type { ToJsonSchemaOptions } from '../schema/Schema.js';
6
6
  import type { OpenAPIV3 } from 'openapi-types';
7
7
  import { OasBase } from '../../types/OasBase.js';
8
8
  import type { ParseContextType } from '../../context/parseTypes.js';
9
+ import type { JsonContent } from '../mediaType/jsonMediaType.js';
9
10
  /**
10
11
  * Constructor fields for {@link OasRequestBody}.
11
12
  */
@@ -286,6 +287,16 @@ export declare class OasRequestBody extends OasBase {
286
287
  isRef(): this is OasRef<'requestBody'>;
287
288
  resolve(): OasRequestBody;
288
289
  resolveOnce(): OasRequestBody;
290
+ /**
291
+ * The body schema for `mediaType`, an exact key lookup. Without
292
+ * `mediaType`, the schema of the JSON media type that {@link toJsonContent}
293
+ * picks: `application/json`, else the first JSON-like type such as
294
+ * `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
295
+ * when its schema is an object, array, union or `$ref`.
296
+ * `undefined` when there is no such media type or it has no schema.
297
+ */
289
298
  toSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
299
+ /** The media type this body is read from (JSON-like, or `*\/*`), and its schema. See {@link toJsonContent}. */
300
+ toJsonContent(): JsonContent | undefined;
290
301
  toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.RequestBodyObject;
291
302
  }
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasRequestBody = void 0;
4
4
  require("../../_dnt.polyfills.js");
5
5
  const OasBase_js_1 = require("../../types/OasBase.js");
6
+ const jsonMediaType_js_1 = require("../mediaType/jsonMediaType.js");
7
+ const toContentSchema_js_1 = require("../mediaType/toContentSchema.js");
6
8
  /**
7
9
  * Represents a Request Body Object in the OpenAPI Specification.
8
10
  *
@@ -307,8 +309,20 @@ class OasRequestBody extends OasBase_js_1.OasBase {
307
309
  resolveOnce() {
308
310
  return this;
309
311
  }
310
- toSchema(mediaType = 'application/json') {
311
- return this.content?.[mediaType]?.schema;
312
+ /**
313
+ * The body schema for `mediaType`, an exact key lookup. Without
314
+ * `mediaType`, the schema of the JSON media type that {@link toJsonContent}
315
+ * picks: `application/json`, else the first JSON-like type such as
316
+ * `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
317
+ * when its schema is an object, array, union or `$ref`.
318
+ * `undefined` when there is no such media type or it has no schema.
319
+ */
320
+ toSchema(mediaType) {
321
+ return (0, toContentSchema_js_1.toContentSchema)(this.content, mediaType);
322
+ }
323
+ /** The media type this body is read from (JSON-like, or `*\/*`), and its schema. See {@link toJsonContent}. */
324
+ toJsonContent() {
325
+ return (0, jsonMediaType_js_1.toJsonContent)(this.content);
312
326
  }
313
327
  toJsonSchema(options) {
314
328
  return {
@@ -8,6 +8,7 @@ import type { ToJsonSchemaOptions } from '../schema/Schema.js';
8
8
  import type { OpenAPIV3 } from 'openapi-types';
9
9
  import { OasBase } from '../../types/OasBase.js';
10
10
  import type { ParseContextType } from '../../context/parseTypes.js';
11
+ import type { JsonContent } from '../mediaType/jsonMediaType.js';
11
12
  /**
12
13
  * Constructor fields for {@link OasResponse}.
13
14
  */
@@ -220,7 +221,17 @@ export declare class OasResponse extends OasBase {
220
221
  isRef(): this is OasRef<'response'>;
221
222
  resolve(): OasResponse;
222
223
  resolveOnce(): OasResponse;
224
+ /**
225
+ * The body schema for `mediaType`, an exact key lookup. Without
226
+ * `mediaType`, the schema of the JSON media type that {@link toJsonContent}
227
+ * picks: `application/json`, else the first JSON-like type such as
228
+ * `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
229
+ * when its schema is an object, array, union or `$ref`.
230
+ * `undefined` when there is no such media type or it has no schema.
231
+ */
223
232
  toSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
233
+ /** The media type this response is read from (JSON-like, or `*\/*`), and its schema. See {@link toJsonContent}. */
234
+ toJsonContent(): JsonContent | undefined;
224
235
  toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.ResponseObject & {
225
236
  summary?: string;
226
237
  };
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasResponse = void 0;
4
4
  require("../../_dnt.polyfills.js");
5
5
  const OasBase_js_1 = require("../../types/OasBase.js");
6
+ const jsonMediaType_js_1 = require("../mediaType/jsonMediaType.js");
7
+ const toContentSchema_js_1 = require("../mediaType/toContentSchema.js");
6
8
  /**
7
9
  * Represents a Response Object in the OpenAPI Specification.
8
10
  *
@@ -247,8 +249,20 @@ class OasResponse extends OasBase_js_1.OasBase {
247
249
  resolveOnce() {
248
250
  return this;
249
251
  }
250
- toSchema(mediaType = 'application/json') {
251
- return this.content?.[mediaType]?.schema;
252
+ /**
253
+ * The body schema for `mediaType`, an exact key lookup. Without
254
+ * `mediaType`, the schema of the JSON media type that {@link toJsonContent}
255
+ * picks: `application/json`, else the first JSON-like type such as
256
+ * `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
257
+ * when its schema is an object, array, union or `$ref`.
258
+ * `undefined` when there is no such media type or it has no schema.
259
+ */
260
+ toSchema(mediaType) {
261
+ return (0, toContentSchema_js_1.toContentSchema)(this.content, mediaType);
262
+ }
263
+ /** The media type this response is read from (JSON-like, or `*\/*`), and its schema. See {@link toJsonContent}. */
264
+ toJsonContent() {
265
+ return (0, jsonMediaType_js_1.toJsonContent)(this.content);
252
266
  }
253
267
  toJsonSchema(options) {
254
268
  return {
@@ -113,10 +113,10 @@ export declare class OasWebhook extends OasBase {
113
113
  */
114
114
  toPayload(): OasRequestBody | undefined;
115
115
  /**
116
- * The schema of the received payload for `mediaType` (default
117
- * `application/json`) — the inbound body shape a handler generator emits a
118
- * type for. `undefined` when there is no body or no schema for that media
119
- * type.
116
+ * The schema of the received payload for `mediaType`, an exact lookup —
117
+ * the inbound body shape a handler generator writes a type for. Without
118
+ * `mediaType`, the media type `OasRequestBody.toJsonContent` picks.
119
+ * `undefined` when there is no body or no schema for that media type.
120
120
  */
121
121
  toPayloadSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
122
122
  /**
@@ -160,13 +160,13 @@ class OasWebhook extends OasBase_js_1.OasBase {
160
160
  return this.requestBody?.resolve();
161
161
  }
162
162
  /**
163
- * The schema of the received payload for `mediaType` (default
164
- * `application/json`) — the inbound body shape a handler generator emits a
165
- * type for. `undefined` when there is no body or no schema for that media
166
- * type.
163
+ * The schema of the received payload for `mediaType`, an exact lookup —
164
+ * the inbound body shape a handler generator writes a type for. Without
165
+ * `mediaType`, the media type `OasRequestBody.toJsonContent` picks.
166
+ * `undefined` when there is no body or no schema for that media type.
167
167
  */
168
- toPayloadSchema(mediaType = 'application/json') {
169
- return this.toPayload()?.content[mediaType]?.schema;
168
+ toPayloadSchema(mediaType) {
169
+ return this.toPayload()?.toSchema(mediaType);
170
170
  }
171
171
  /**
172
172
  * Resolve the inbound parameters (e.g. the signature/headers a handler
@@ -0,0 +1,27 @@
1
+ import type { ParseContextType } from '../context/parseTypes.js';
2
+ import type { StackTrail } from '../context/StackTrail.js';
3
+ import type { OasMediaType } from '../oas/mediaType/MediaType.js';
4
+ export type LogBodyMediaTypesArgs = {
5
+ /** The parsed `content` map of a response or request body. */
6
+ content: Record<string, OasMediaType> | undefined;
7
+ /** Trail of the response or request body; the issue is logged at its `content` key. */
8
+ stackTrail: StackTrail;
9
+ context: ParseContextType;
10
+ };
11
+ /**
12
+ * Log at most one issue for a parsed response or request body, from the same
13
+ * choice the lookups make (`toJsonContent`), so the issue and the lookup
14
+ * cannot disagree. Called after the body is built, so a body that fails to
15
+ * parse logs nothing.
16
+ *
17
+ * - `WILDCARD_MEDIA_TYPE` (`warning`): the body is read from `*\/*` as JSON,
18
+ * though the document does not say its format.
19
+ * - `NO_JSON_MEDIA_TYPE` (`debug`): no lookup reads the body, and its keys
20
+ * include a range (`*\/*` with a scalar schema, `application/*`), so its
21
+ * format is unknown.
22
+ *
23
+ * A body with only specific non-JSON types (`multipart/form-data`,
24
+ * `application/octet-stream`, `text/plain`) logs nothing: that is a normal
25
+ * text, form or binary body.
26
+ */
27
+ export declare const logBodyMediaTypes: ({ content, stackTrail, context }: LogBodyMediaTypesArgs) => void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logBodyMediaTypes = void 0;
4
+ const jsonMediaType_js_1 = require("../oas/mediaType/jsonMediaType.js");
5
+ /**
6
+ * Log at most one issue for a parsed response or request body, from the same
7
+ * choice the lookups make (`toJsonContent`), so the issue and the lookup
8
+ * cannot disagree. Called after the body is built, so a body that fails to
9
+ * parse logs nothing.
10
+ *
11
+ * - `WILDCARD_MEDIA_TYPE` (`warning`): the body is read from `*\/*` as JSON,
12
+ * though the document does not say its format.
13
+ * - `NO_JSON_MEDIA_TYPE` (`debug`): no lookup reads the body, and its keys
14
+ * include a range (`*\/*` with a scalar schema, `application/*`), so its
15
+ * format is unknown.
16
+ *
17
+ * A body with only specific non-JSON types (`multipart/form-data`,
18
+ * `application/octet-stream`, `text/plain`) logs nothing: that is a normal
19
+ * text, form or binary body.
20
+ */
21
+ const logBodyMediaTypes = ({ content, stackTrail, context }) => {
22
+ const mediaTypes = Object.keys(content ?? {});
23
+ if (mediaTypes.length === 0) {
24
+ return;
25
+ }
26
+ const listed = mediaTypes.map(mediaType => `"${mediaType}"`).join(', ');
27
+ // `parent` is only the keys: the issue log serializes it on every issue.
28
+ const parent = { mediaTypes };
29
+ const chosen = (0, jsonMediaType_js_1.toJsonContent)(content);
30
+ if (chosen !== undefined) {
31
+ if ((0, jsonMediaType_js_1.isAnyMediaType)(chosen.mediaType)) {
32
+ context.logIssue({
33
+ key: 'content',
34
+ level: 'warning',
35
+ type: 'WILDCARD_MEDIA_TYPE',
36
+ message: `Content has no JSON media type (${listed}), so the body is read from "*/*" as JSON although the document does not say its format`,
37
+ parent,
38
+ stackTrail
39
+ });
40
+ }
41
+ return;
42
+ }
43
+ if (mediaTypes.some(mediaType => (0, jsonMediaType_js_1.toMediaTypeEssence)(mediaType).includes('*'))) {
44
+ context.logIssue({
45
+ key: 'content',
46
+ level: 'debug',
47
+ type: 'NO_JSON_MEDIA_TYPE',
48
+ message: `Content names only a media type range or non-JSON types (${listed}), so no lookup without a media type reads its schema`,
49
+ parent,
50
+ stackTrail
51
+ });
52
+ }
53
+ };
54
+ exports.logBodyMediaTypes = logBodyMediaTypes;
@@ -1,10 +1,11 @@
1
1
  import type { ParseContextType } from '../../../context/parseTypes.js';
2
- import type { OasParameterLocation } from '../../../oas/parameter/parameter-types.js';
2
+ import type { OasParameterLocation, OasParameterStyle } from '../../../oas/parameter/parameter-types.js';
3
3
  import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
7
  type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
8
+ type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
8
9
  export type ToParameterListV3Args = {
9
10
  parameters: (OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject)[] | undefined;
10
11
  stackTrail: StackTrail;
@@ -35,7 +36,7 @@ export type ToStyleArgs = {
35
36
  };
36
37
  export type ToExplodeArgs = {
37
38
  explode: boolean | undefined;
38
- style: string | undefined;
39
+ style: ParameterStyle;
39
40
  stackTrail: StackTrail;
40
41
  };
41
42
  export {};
@@ -111,14 +111,15 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
111
111
  }
112
112
  // Set missing 'required' to true for path parameters and false for others
113
113
  const defaultRequired = typeof required === 'undefined' ? (parsedLocation === 'path' ? true : false) : required;
114
+ const parsedStyle = stackTrail.trace('style', st => toStyle({ style, location: parsedLocation, stackTrail: st }));
114
115
  const fields = {
115
116
  name,
116
117
  location: parsedLocation,
117
118
  description,
118
119
  required: defaultRequired,
119
120
  deprecated,
120
- style: stackTrail.trace('style', st => toStyle({ style, location: parsedLocation, stackTrail: st })),
121
- explode: stackTrail.trace('explode', st => toExplode({ explode, style, stackTrail: st })),
121
+ style: parsedStyle,
122
+ explode: stackTrail.trace('explode', st => toExplode({ explode, style: parsedStyle, stackTrail: st })),
122
123
  allowEmptyValue,
123
124
  allowReserved,
124
125
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
@@ -3,13 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toPathItemV3 = void 0;
4
4
  const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
5
5
  const PathItem_js_1 = require("../../../oas/pathItem/PathItem.js");
6
+ const toServerV3_js_1 = require("../server/toServerV3.js");
7
+ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
6
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
7
9
  const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
8
- const { summary, description, parameters, ...skipped } = pathItem;
10
+ const { summary, description, parameters, servers, ...skipped } = pathItem;
9
11
  return new PathItem_js_1.OasPathItem({
10
12
  summary,
11
13
  description,
12
14
  parameters: stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toParameterListV3)({ parameters, stackTrail: st, context })),
15
+ servers: (0, tryParseAt_js_1.tryParseAt)({
16
+ stackTrail,
17
+ key: 'servers',
18
+ context,
19
+ type: 'INVALID_OPERATION',
20
+ parent: pathItem,
21
+ fn: st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context })
22
+ }),
13
23
  extensionFields: (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
14
24
  skipped,
15
25
  parent: pathItem,
@@ -6,6 +6,7 @@ const toRefV31_js_1 = require("../ref/toRefV31.js");
6
6
  const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
7
7
  const RequestBody_js_1 = require("../../../oas/requestBody/RequestBody.js");
8
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
9
+ const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
9
10
  const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
10
11
  if (!requestBody) {
11
12
  return undefined;
@@ -29,7 +30,9 @@ const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
29
30
  required,
30
31
  extensionFields
31
32
  };
32
- return context.withStackTrail(stackTrail, () => new RequestBody_js_1.OasRequestBody(fields, context));
33
+ const parsed = context.withStackTrail(stackTrail, () => new RequestBody_js_1.OasRequestBody(fields, context));
34
+ (0, logBodyMediaTypes_js_1.logBodyMediaTypes)({ content: fields.content, stackTrail, context });
35
+ return parsed;
33
36
  };
34
37
  exports.toRequestBodyV3 = toRequestBodyV3;
35
38
  const toRequestBodiesV3 = ({ requestBodies, stackTrail, context }) => {
@@ -9,6 +9,7 @@ const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
9
9
  const Response_js_1 = require("../../../oas/response/Response.js");
10
10
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
11
11
  const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
12
+ const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
12
13
  const toResponsesV3 = ({ responses, stackTrail, context }) => {
13
14
  const output = {};
14
15
  const entries = Object.entries(responses);
@@ -50,12 +51,14 @@ const toResponseV3 = ({ response, stackTrail, context }) => {
50
51
  const parsedHeaders = stackTrail.trace('headers', st => (0, toHeadersV3_js_1.toHeadersV3)({ headers, stackTrail: st, context }));
51
52
  const parsedLinks = stackTrail.trace('links', st => (0, toLinksV3_js_1.toLinksV3)({ links, stackTrail: st, context }));
52
53
  const parsedContent = stackTrail.trace('content', st => (0, toMediaTypeItemV3_js_1.toOptionalMediaTypeItemsV3)({ content, stackTrail: st, context }));
53
- return context.withStackTrail(stackTrail, () => new Response_js_1.OasResponse({
54
+ const parsed = context.withStackTrail(stackTrail, () => new Response_js_1.OasResponse({
54
55
  description,
55
56
  headers: parsedHeaders,
56
57
  links: parsedLinks,
57
58
  content: parsedContent,
58
59
  extensionFields
59
60
  }, context));
61
+ (0, logBodyMediaTypes_js_1.logBodyMediaTypes)({ content: parsedContent, stackTrail, context });
62
+ return parsed;
60
63
  };
61
64
  exports.toResponseV3 = toResponseV3;
@@ -1,10 +1,11 @@
1
1
  import type { ParseContextType } from '../../../context/parseTypes.js';
2
- import type { OasParameterLocation } from '../../../oas/parameter/parameter-types.js';
2
+ import type { OasParameterLocation, OasParameterStyle } from '../../../oas/parameter/parameter-types.js';
3
3
  import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
7
  type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
8
+ type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
8
9
  export type ToParameterListV3Args = {
9
10
  parameters: (OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject)[] | undefined;
10
11
  stackTrail: StackTrail;
@@ -35,7 +36,7 @@ export type ToStyleArgs = {
35
36
  };
36
37
  export type ToExplodeArgs = {
37
38
  explode: boolean | undefined;
38
- style: string | undefined;
39
+ style: ParameterStyle;
39
40
  stackTrail: StackTrail;
40
41
  };
41
42
  export {};
@@ -111,14 +111,15 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
111
111
  }
112
112
  // Set missing 'required' to true for path parameters and false for others
113
113
  const defaultRequired = typeof required === 'undefined' ? (parsedLocation === 'path' ? true : false) : required;
114
+ const parsedStyle = stackTrail.trace('style', st => toStyle({ style, location: parsedLocation, stackTrail: st }));
114
115
  const fields = {
115
116
  name,
116
117
  location: parsedLocation,
117
118
  description,
118
119
  required: defaultRequired,
119
120
  deprecated,
120
- style: stackTrail.trace('style', st => toStyle({ style, location: parsedLocation, stackTrail: st })),
121
- explode: stackTrail.trace('explode', st => toExplode({ explode, style, stackTrail: st })),
121
+ style: parsedStyle,
122
+ explode: stackTrail.trace('explode', st => toExplode({ explode, style: parsedStyle, stackTrail: st })),
122
123
  allowEmptyValue,
123
124
  allowReserved,
124
125
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
@@ -3,13 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toPathItemV3 = void 0;
4
4
  const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
5
5
  const PathItem_js_1 = require("../../../oas/pathItem/PathItem.js");
6
+ const toServerV3_js_1 = require("../server/toServerV3.js");
7
+ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
6
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
7
9
  const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
8
- const { summary, description, parameters, ...skipped } = pathItem;
10
+ const { summary, description, parameters, servers, ...skipped } = pathItem;
9
11
  return new PathItem_js_1.OasPathItem({
10
12
  summary,
11
13
  description,
12
14
  parameters: stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toParameterListV3)({ parameters, stackTrail: st, context })),
15
+ servers: (0, tryParseAt_js_1.tryParseAt)({
16
+ stackTrail,
17
+ key: 'servers',
18
+ context,
19
+ type: 'INVALID_OPERATION',
20
+ parent: pathItem,
21
+ fn: st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context })
22
+ }),
13
23
  extensionFields: (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
14
24
  skipped,
15
25
  parent: pathItem,
@@ -6,6 +6,7 @@ const toRefV31_js_1 = require("../ref/toRefV31.js");
6
6
  const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
7
7
  const RequestBody_js_1 = require("../../../oas/requestBody/RequestBody.js");
8
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
9
+ const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
9
10
  const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
10
11
  if (!requestBody) {
11
12
  return undefined;
@@ -29,7 +30,9 @@ const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
29
30
  required,
30
31
  extensionFields
31
32
  };
32
- return context.withStackTrail(stackTrail, () => new RequestBody_js_1.OasRequestBody(fields, context));
33
+ const parsed = context.withStackTrail(stackTrail, () => new RequestBody_js_1.OasRequestBody(fields, context));
34
+ (0, logBodyMediaTypes_js_1.logBodyMediaTypes)({ content: fields.content, stackTrail, context });
35
+ return parsed;
33
36
  };
34
37
  exports.toRequestBodyV3 = toRequestBodyV3;
35
38
  const toRequestBodiesV3 = ({ requestBodies, stackTrail, context }) => {