@skmtc/core 0.35.3 → 0.36.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.
@@ -140,9 +140,11 @@ const addNamedType = ({ name, type, stackTrail, context, synthesizeInterfaceUnio
140
140
  // `refKey: name` (the type's own name, not `refName`) preserves the
141
141
  // prior behavior where an interface-union failure marks the base
142
142
  // type as errored so dependents of either form get pruned together.
143
+ // `key: refName` traces the synthesized interface union under its own
144
+ // registered name, so its member trails name the union.
143
145
  const value = (0, tryParseAt_js_1.tryParseAt)({
144
146
  stackTrail,
145
- key: name,
147
+ key: refName,
146
148
  context,
147
149
  type: 'INVALID_TYPE_DEFINITION',
148
150
  parent: type,
@@ -36,6 +36,8 @@ export type ComponentsFields = {
36
36
  /** Custom extension fields (x-* properties) */
37
37
  extensionFields?: Record<string, unknown>;
38
38
  };
39
+ /** One entry of any {@link ComponentsFields} bucket. */
40
+ export type ComponentsEntry = OasSchema | OasRef<'schema'> | OasResponse | OasRef<'response'> | OasParameter | OasRef<'parameter'> | OasExample | OasRef<'example'> | OasRequestBody | OasRef<'requestBody'> | OasHeader | OasRef<'header'> | OasSecurityScheme | OasRef<'securityScheme'> | OasLink | OasRef<'link'>;
39
41
  /**
40
42
  * Represents the OpenAPI Components Object in the SKMTC OAS processing system.
41
43
  *
@@ -285,6 +287,14 @@ export declare class OasComponents {
285
287
  * ```
286
288
  */
287
289
  removeSchema(refName: RefName): OasSchema | OasRef<'schema'>;
290
+ /**
291
+ * Removes the entry `refName` from the `bucket` record (`schemas`,
292
+ * `requestBodies`, `headers`, …) and returns it.
293
+ *
294
+ * Returns `undefined` when the bucket has no such entry, and for a bucket
295
+ * outside {@link componentsKeys}.
296
+ */
297
+ removeEntry(bucket: string, refName: RefName): ComponentsEntry | undefined;
288
298
  /** Record holding re-usable {@link OasResponse} objects or Refs */
289
299
  get responses(): Record<RefName, OasResponse | OasRef<'response'>> | undefined;
290
300
  /** Record holding re-usable {@link OasParameter} objects or Refs */
@@ -27,6 +27,16 @@ exports.componentsKeys = [
27
27
  'securitySchemes',
28
28
  'links'
29
29
  ];
30
+ /** Copy of `record` without `name`, and the value it held. */
31
+ const withoutEntry = (record, name) => {
32
+ if (!record || !Object.hasOwn(record, name)) {
33
+ return { removed: undefined, rest: record };
34
+ }
35
+ const rest = { ...record };
36
+ const removed = rest[name];
37
+ delete rest[name];
38
+ return { removed, rest };
39
+ };
30
40
  /**
31
41
  * Represents the OpenAPI Components Object in the SKMTC OAS processing system.
32
42
  *
@@ -292,6 +302,60 @@ class OasComponents {
292
302
  __classPrivateFieldGet(this, _OasComponents_fields, "f").schemas = rest;
293
303
  return removed;
294
304
  }
305
+ /**
306
+ * Removes the entry `refName` from the `bucket` record (`schemas`,
307
+ * `requestBodies`, `headers`, …) and returns it.
308
+ *
309
+ * Returns `undefined` when the bucket has no such entry, and for a bucket
310
+ * outside {@link componentsKeys}.
311
+ */
312
+ removeEntry(bucket, refName) {
313
+ const fields = __classPrivateFieldGet(this, _OasComponents_fields, "f");
314
+ switch (bucket) {
315
+ case 'schemas': {
316
+ const { removed, rest } = withoutEntry(fields.schemas, refName);
317
+ fields.schemas = rest;
318
+ return removed;
319
+ }
320
+ case 'responses': {
321
+ const { removed, rest } = withoutEntry(fields.responses, refName);
322
+ fields.responses = rest;
323
+ return removed;
324
+ }
325
+ case 'parameters': {
326
+ const { removed, rest } = withoutEntry(fields.parameters, refName);
327
+ fields.parameters = rest;
328
+ return removed;
329
+ }
330
+ case 'examples': {
331
+ const { removed, rest } = withoutEntry(fields.examples, refName);
332
+ fields.examples = rest;
333
+ return removed;
334
+ }
335
+ case 'requestBodies': {
336
+ const { removed, rest } = withoutEntry(fields.requestBodies, refName);
337
+ fields.requestBodies = rest;
338
+ return removed;
339
+ }
340
+ case 'headers': {
341
+ const { removed, rest } = withoutEntry(fields.headers, refName);
342
+ fields.headers = rest;
343
+ return removed;
344
+ }
345
+ case 'securitySchemes': {
346
+ const { removed, rest } = withoutEntry(fields.securitySchemes, refName);
347
+ fields.securitySchemes = rest;
348
+ return removed;
349
+ }
350
+ case 'links': {
351
+ const { removed, rest } = withoutEntry(fields.links, refName);
352
+ fields.links = rest;
353
+ return removed;
354
+ }
355
+ default:
356
+ return undefined;
357
+ }
358
+ }
295
359
  /** Record holding re-usable {@link OasResponse} objects or Refs */
296
360
  get responses() {
297
361
  return __classPrivateFieldGet(this, _OasComponents_fields, "f").responses;
@@ -1,14 +1,12 @@
1
1
  import "../../_dnt.polyfills.js";
2
2
  import type { OasTag } from '../tag/Tag.js';
3
- import type { OasComponents } from '../components/Components.js';
3
+ import type { ComponentsEntry, OasComponents } from '../components/Components.js';
4
4
  import type { OasOperation } from '../operation/Operation.js';
5
5
  import type { OasWebhook } from '../webhook/Webhook.js';
6
6
  import type { OasInfo } from '../info/Info.js';
7
7
  import type { OasServer } from '../server/Server.js';
8
8
  import type { OasSecurityRequirement } from '../securityRequirement/SecurityRequirement.js';
9
9
  import type { StackTrail } from '../../context/StackTrail.js';
10
- import type { OasSchema } from '../schema/Schema.js';
11
- import type { OasRef } from '../ref/Ref.js';
12
10
  import type { OasExternalDocs } from '../externalDocs/ExternalDocs.js';
13
11
  /**
14
12
  * Fields that define the structure of an OpenAPI v3 document.
@@ -179,10 +177,12 @@ export declare class OasDocument {
179
177
  * Removes an item from the document based on a stack trail path.
180
178
  *
181
179
  * This method is used internally during document processing to remove
182
- * specific operations or schema components. The stack trail indicates
183
- * the path to the item within the document structure.
180
+ * specific operations, webhooks or components. The stack trail indicates
181
+ * the path to the item within the document structure. A
182
+ * `components:<bucket>:<name>` trail removes the entry from that bucket
183
+ * (`components:requestBodies:X` removes request body `X`, not schema `X`).
184
184
  *
185
- * @param stackTrail - Path to the item to remove
185
+ * @param stackTrail - Document-relative path to the item to remove
186
186
  * @returns The removed item, or undefined if not found
187
187
  *
188
188
  * @internal This method is primarily used by the processing pipeline
@@ -196,7 +196,7 @@ export declare class OasDocument {
196
196
  * const removedSchema = document.removeItem(new StackTrail(['components', 'schemas', 'User']));
197
197
  * ```
198
198
  */
199
- removeItem(stackTrail: StackTrail): OasOperation | OasWebhook | OasSchema | OasRef<'schema'> | undefined;
199
+ removeItem(stackTrail: StackTrail): OasOperation | OasWebhook | ComponentsEntry | undefined;
200
200
  /**
201
201
  * Sets the document fields after parsing.
202
202
  *
@@ -148,10 +148,12 @@ class OasDocument {
148
148
  * Removes an item from the document based on a stack trail path.
149
149
  *
150
150
  * This method is used internally during document processing to remove
151
- * specific operations or schema components. The stack trail indicates
152
- * the path to the item within the document structure.
151
+ * specific operations, webhooks or components. The stack trail indicates
152
+ * the path to the item within the document structure. A
153
+ * `components:<bucket>:<name>` trail removes the entry from that bucket
154
+ * (`components:requestBodies:X` removes request body `X`, not schema `X`).
153
155
  *
154
- * @param stackTrail - Path to the item to remove
156
+ * @param stackTrail - Document-relative path to the item to remove
155
157
  * @returns The removed item, or undefined if not found
156
158
  *
157
159
  * @internal This method is primarily used by the processing pipeline
@@ -192,7 +194,7 @@ class OasDocument {
192
194
  if (typeof third !== 'string') {
193
195
  throw new Error(`RefName cannot be a number: ${third}`);
194
196
  }
195
- return __classPrivateFieldGet(this, _OasDocument_fields, "f").components.removeSchema(third);
197
+ return __classPrivateFieldGet(this, _OasDocument_fields, "f")?.components?.removeEntry(second, third);
196
198
  }
197
199
  default:
198
200
  throw new Error(`Unexpected stack trail: ${stackTrail}`);
@@ -35,6 +35,7 @@ export type ToPathParameterListArgs<Entry, Parameter> = {
35
35
  index: number;
36
36
  }) => Parameter[];
37
37
  };
38
+ export declare const toNameAndIn: (parameter: unknown) => Pick<BrokenPathParameter, "name" | "in">;
38
39
  /**
39
40
  * Parses a path item's `parameters` without letting a throw escape. Each
40
41
  * entry that fails logs one `INVALID_PARAMETER` error at its index and is
@@ -42,6 +43,18 @@ export type ToPathParameterListArgs<Entry, Parameter> = {
42
43
  * The caller decides per operation which broken entries apply.
43
44
  */
44
45
  export declare const toPathParameterList: <Entry, Parameter>({ parameters, stackTrail, context, toEntry }: ToPathParameterListArgs<Entry, Parameter>) => PathParameterList<Parameter>;
46
+ /**
47
+ * The first broken path-level parameter that applies to an operation. An
48
+ * entry applies unless it has a readable `name` and `in` and the
49
+ * operation's inline `parameters` hold the same pair, which overrides it.
50
+ * A `$ref` operation parameter cannot be resolved during parse, so it
51
+ * overrides nothing.
52
+ */
53
+ export declare const toApplyingBrokenParameter: ({ broken, operation }: {
54
+ broken: BrokenPathParameter[];
55
+ /** The raw operation object. */
56
+ operation: unknown;
57
+ }) => BrokenPathParameter | undefined;
45
58
  /**
46
59
  * True when a broken path-level parameter applies to the operation. Logs
47
60
  * one `INVALID_OPERATION` error at the operation that names the first
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDroppedByPathParameter = exports.toPathParameterList = exports.toParameterEntries = void 0;
3
+ exports.isDroppedByPathParameter = exports.toApplyingBrokenParameter = exports.toPathParameterList = exports.toNameAndIn = exports.toParameterEntries = void 0;
4
4
  const emptyParameter_js_1 = require("./emptyParameter.js");
5
5
  const documentTrail_js_1 = require("../context/documentTrail.js");
6
6
  /**
@@ -40,6 +40,7 @@ const toNameAndIn = (parameter) => {
40
40
  }
41
41
  return {};
42
42
  };
43
+ exports.toNameAndIn = toNameAndIn;
43
44
  /**
44
45
  * Parses a path item's `parameters` without letting a throw escape. Each
45
46
  * entry that fails logs one `INVALID_PARAMETER` error at its index and is
@@ -85,7 +86,7 @@ const toPathParameterList = ({ parameters, stackTrail, context, toEntry }) => {
85
86
  broken: [
86
87
  {
87
88
  ...stackTrail.trace(`${index}`, st => logBroken(st, parameter, error)),
88
- ...toNameAndIn(parameter)
89
+ ...(0, exports.toNameAndIn)(parameter)
89
90
  }
90
91
  ]
91
92
  };
@@ -115,20 +116,21 @@ const toApplyingBrokenParameter = ({ broken, operation }) => {
115
116
  ? operation.parameters
116
117
  : [];
117
118
  const overrides = new Set(operationParameters.flatMap((parameter) => {
118
- const { name, in: parameterIn } = toNameAndIn(parameter);
119
+ const { name, in: parameterIn } = (0, exports.toNameAndIn)(parameter);
119
120
  return name === undefined || parameterIn === undefined ? [] : [`${parameterIn}:${name}`];
120
121
  }));
121
122
  return broken.find(entry => entry.name === undefined ||
122
123
  entry.in === undefined ||
123
124
  !overrides.has(`${entry.in}:${entry.name}`));
124
125
  };
126
+ exports.toApplyingBrokenParameter = toApplyingBrokenParameter;
125
127
  /**
126
128
  * True when a broken path-level parameter applies to the operation. Logs
127
129
  * one `INVALID_OPERATION` error at the operation that names the first
128
130
  * such entry.
129
131
  */
130
132
  const isDroppedByPathParameter = ({ brokenParameters, operation, stackTrail, context }) => {
131
- const broken = toApplyingBrokenParameter({ broken: brokenParameters, operation });
133
+ const broken = (0, exports.toApplyingBrokenParameter)({ broken: brokenParameters, operation });
132
134
  if (!broken) {
133
135
  return false;
134
136
  }