@skmtc/core 0.44.2 → 0.46.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 (113) hide show
  1. package/esm/anchors/attribute.js +3 -2
  2. package/esm/context/CoreContext.d.ts +1 -1
  3. package/esm/context/CoreContext.js +1 -1
  4. package/esm/context/GenerateContext.d.ts +13 -10
  5. package/esm/context/GenerateContext.js +36 -25
  6. package/esm/context/ParseContext.js +136 -34
  7. package/esm/context/generateTypes.d.ts +7 -6
  8. package/esm/context/generateTypes.js +2 -0
  9. package/esm/dsl/GeneratorKeys.d.ts +21 -15
  10. package/esm/dsl/GeneratorKeys.js +16 -11
  11. package/esm/dsl/Inserted.d.ts +1 -1
  12. package/esm/dsl/Inserted.js +1 -1
  13. package/esm/dsl/model/ModelDriver.d.ts +6 -5
  14. package/esm/dsl/model/ModelDriver.js +22 -20
  15. package/esm/dsl/model/toModelEntry.d.ts +18 -18
  16. package/esm/dsl/model/toModelEntry.js +9 -9
  17. package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
  18. package/esm/dsl/model/toModelProjectionBase.js +12 -8
  19. package/esm/dsl/model/types.d.ts +26 -17
  20. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  21. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  22. package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  23. package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  24. package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  25. package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
  26. package/esm/helpers/refFns.d.ts +108 -43
  27. package/esm/helpers/refFns.js +166 -57
  28. package/esm/oas/document/Document.d.ts +6 -0
  29. package/esm/oas/document/Document.js +44 -2
  30. package/esm/oas/header/Header.js +4 -1
  31. package/esm/oas/parameter/Parameter.d.ts +1 -1
  32. package/esm/oas/parameter/Parameter.js +5 -2
  33. package/esm/oas/ref/DanglingRefError.d.ts +5 -2
  34. package/esm/oas/ref/DanglingRefError.js +4 -3
  35. package/esm/oas/ref/Ref.d.ts +23 -12
  36. package/esm/oas/ref/Ref.js +68 -72
  37. package/esm/oas/schemaPath/traverseSchema.js +11 -5
  38. package/esm/parse/missingSchema.d.ts +30 -0
  39. package/esm/parse/missingSchema.js +33 -0
  40. package/esm/parse/v3-0/header/toHeadersV3.js +5 -0
  41. package/esm/parse/v3-0/parameter/toParameterV3.js +11 -0
  42. package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  43. package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
  44. package/esm/parse/v3-1/header/toHeadersV3.js +5 -0
  45. package/esm/parse/v3-1/parameter/toParameterV3.js +11 -0
  46. package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  47. package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
  48. package/esm/parse/v3-2/header/toHeadersV3.js +5 -0
  49. package/esm/parse/v3-2/parameter/toParameterV3.js +11 -0
  50. package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  51. package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
  52. package/esm/types/GeneratorType.d.ts +1 -1
  53. package/esm/types/ProjectionOptions.d.ts +1 -1
  54. package/esm/types/ProjectionOptions.js +1 -1
  55. package/esm/types/RefName.d.ts +3 -3
  56. package/esm/types/TypeSystem.d.ts +3 -3
  57. package/package.json +1 -1
  58. package/script/anchors/attribute.js +3 -2
  59. package/script/context/CoreContext.d.ts +1 -1
  60. package/script/context/CoreContext.js +1 -1
  61. package/script/context/GenerateContext.d.ts +13 -10
  62. package/script/context/GenerateContext.js +36 -25
  63. package/script/context/ParseContext.js +135 -33
  64. package/script/context/generateTypes.d.ts +7 -6
  65. package/script/context/generateTypes.js +2 -0
  66. package/script/dsl/GeneratorKeys.d.ts +21 -15
  67. package/script/dsl/GeneratorKeys.js +16 -11
  68. package/script/dsl/Inserted.d.ts +1 -1
  69. package/script/dsl/Inserted.js +1 -1
  70. package/script/dsl/model/ModelDriver.d.ts +6 -5
  71. package/script/dsl/model/ModelDriver.js +22 -20
  72. package/script/dsl/model/toModelEntry.d.ts +18 -18
  73. package/script/dsl/model/toModelEntry.js +9 -9
  74. package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
  75. package/script/dsl/model/toModelProjectionBase.js +12 -8
  76. package/script/dsl/model/types.d.ts +26 -17
  77. package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  78. package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  79. package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  80. package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  81. package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  82. package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
  83. package/script/helpers/refFns.d.ts +108 -43
  84. package/script/helpers/refFns.js +180 -59
  85. package/script/oas/document/Document.d.ts +6 -0
  86. package/script/oas/document/Document.js +44 -2
  87. package/script/oas/header/Header.js +4 -1
  88. package/script/oas/parameter/Parameter.d.ts +1 -1
  89. package/script/oas/parameter/Parameter.js +5 -2
  90. package/script/oas/ref/DanglingRefError.d.ts +5 -2
  91. package/script/oas/ref/DanglingRefError.js +4 -3
  92. package/script/oas/ref/Ref.d.ts +23 -12
  93. package/script/oas/ref/Ref.js +67 -71
  94. package/script/oas/schemaPath/traverseSchema.js +10 -4
  95. package/script/parse/missingSchema.d.ts +30 -0
  96. package/script/parse/missingSchema.js +38 -0
  97. package/script/parse/v3-0/header/toHeadersV3.js +5 -0
  98. package/script/parse/v3-0/parameter/toParameterV3.js +11 -0
  99. package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  100. package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
  101. package/script/parse/v3-1/header/toHeadersV3.js +5 -0
  102. package/script/parse/v3-1/parameter/toParameterV3.js +11 -0
  103. package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  104. package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
  105. package/script/parse/v3-2/header/toHeadersV3.js +5 -0
  106. package/script/parse/v3-2/parameter/toParameterV3.js +11 -0
  107. package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  108. package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
  109. package/script/types/GeneratorType.d.ts +1 -1
  110. package/script/types/ProjectionOptions.d.ts +1 -1
  111. package/script/types/ProjectionOptions.js +1 -1
  112. package/script/types/RefName.d.ts +3 -3
  113. package/script/types/TypeSystem.d.ts +3 -3
@@ -9,52 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
12
+ var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain, _OasRef_toWrittenRef;
13
13
  import "../../_dnt.polyfills.js";
14
14
  import { traverseSchema } from '../schemaPath/traverseSchema.js';
15
- import { toRefName } from '../../helpers/refFns.js';
15
+ import { isDefaultRefPath, isRemoteRefPath, toComponentsBucket, toRefParts, toRefPathBucket, toRefPointer } from '../../helpers/refFns.js';
16
16
  import { OasBase } from '../../types/OasBase.js';
17
17
  import { DanglingRefError } from './DanglingRefError.js';
18
18
  import { changesTarget, changesValues, hasSiblingKeywords, mergeSiblingKeywords, toSkippedSiblings } from '../schema/siblings.js';
19
- /**
20
- * Converts a ref type to its plural components path.
21
- */
22
- function refTypeToPluralPath(refType) {
23
- switch (refType) {
24
- case 'schema':
25
- return 'schemas';
26
- case 'requestBody':
27
- return 'requestBodies';
28
- case 'parameter':
29
- return 'parameters';
30
- case 'response':
31
- return 'responses';
32
- case 'example':
33
- return 'examples';
34
- case 'header':
35
- return 'headers';
36
- case 'securityScheme':
37
- return 'securitySchemes';
38
- case 'link':
39
- return 'links';
40
- default: {
41
- const _exhaustive = refType;
42
- throw new Error(`Unhandled ref type: ${_exhaustive}`);
43
- }
44
- }
45
- }
46
- /**
47
- * The name `resolveOnce` looks up. `toRefName` throws for a `$ref` whose last
48
- * segment is empty (`#/components/schemas/`): that `$ref` names nothing.
49
- */
50
- const toLookupName = ($ref) => {
51
- try {
52
- return toRefName($ref);
53
- }
54
- catch {
55
- throw new DanglingRefError($ref);
56
- }
57
- };
58
19
  /**
59
20
  * Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
60
21
  *
@@ -113,8 +74,8 @@ const toLookupName = ($ref) => {
113
74
  * function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
114
75
  * if (schema.isRef()) {
115
76
  * // Handle reference
116
- * const refName = schema.toRefName();
117
- * console.log(`Processing reference: ${refName}`);
77
+ * const { refName, refPath } = schema;
78
+ * console.log(`Processing reference: ${refName} in ${refPath}`);
118
79
  *
119
80
  * // Resolve only when needed
120
81
  * const resolved = schema.resolve();
@@ -176,13 +137,40 @@ export class OasRef extends OasBase {
176
137
  writable: true,
177
138
  value: void 0
178
139
  });
179
- /** The JSON Reference: `#/components/<bucket>/<name>`. */
140
+ /**
141
+ * The JSON Reference, as written: a component (`#/components/<bucket>/<name>`)
142
+ * or any other place in the document (`#/components/schemas/Pet/properties/tag`).
143
+ */
180
144
  Object.defineProperty(this, "$ref", {
181
145
  enumerable: true,
182
146
  configurable: true,
183
147
  writable: true,
184
148
  value: void 0
185
149
  });
150
+ /**
151
+ * The last segment of the `$ref`'s pointer, unescaped: `Pet` for
152
+ * `#/components/schemas/Pet`, `schema0` for
153
+ * `#/components/schemas/__sharedInput/$defs/schema0`. Empty for a `$ref`
154
+ * that ends in `/`, which names nothing.
155
+ */
156
+ Object.defineProperty(this, "refName", {
157
+ enumerable: true,
158
+ configurable: true,
159
+ writable: true,
160
+ value: void 0
161
+ });
162
+ /**
163
+ * The pointer before {@link refName}, with no percent escapes: `#/components/schemas`
164
+ * for a schema component, `#/components/schemas/__sharedInput/$defs` for
165
+ * the `$defs` entry above. A generator that names by {@link refName} alone
166
+ * may ignore it.
167
+ */
168
+ Object.defineProperty(this, "refPath", {
169
+ enumerable: true,
170
+ configurable: true,
171
+ writable: true,
172
+ value: void 0
173
+ });
186
174
  /**
187
175
  * Use-site nullability (see {@link SiblingKeywords.nullable}). Assigned
188
176
  * even when `undefined`, so `'nullable' in ref` is always true and the
@@ -392,6 +380,9 @@ export class OasRef extends OasBase {
392
380
  _OasRef_resolution.set(this, void 0);
393
381
  this.refType = fields.refType;
394
382
  this.$ref = fields.$ref;
383
+ const { refName, refPath } = toRefParts({ $ref: fields.$ref });
384
+ this.refName = refName;
385
+ this.refPath = refPath;
395
386
  this.nullable = fields.nullable;
396
387
  this.readOnly = fields.readOnly;
397
388
  this.writeOnly = fields.writeOnly;
@@ -468,8 +459,9 @@ export class OasRef extends OasBase {
468
459
  }
469
460
  /**
470
461
  * Resolves this reference one level. Dispatches on the document's
471
- * protocol — OAS reads from `document.components.<bucket>`; GQL
472
- * reads from `document.registry.schemas`.
462
+ * protocol — OAS reads a component from `document.components.<bucket>`,
463
+ * and any other target from the targets the parser kept by pointer
464
+ * (`OasDocument.toRefTarget`); GQL reads from `document.registry.schemas`.
473
465
  *
474
466
  * @returns Either the resolved component or another reference in the chain
475
467
  * @throws {DanglingRefError} when the reference names nothing in the
@@ -479,12 +471,14 @@ export class OasRef extends OasBase {
479
471
  * `requestBody` ref to `#/components/schemas/…`
480
472
  */
481
473
  resolveOnce() {
482
- const refName = toLookupName(this.$ref);
474
+ if (this.refName === '') {
475
+ throw new DanglingRefError(this.$ref);
476
+ }
483
477
  const resolved = __classPrivateFieldGet(this, _OasRef_document, "f").type === 'oas'
484
- ? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value, refName)
485
- : __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value, refName);
478
+ ? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value)
479
+ : __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value);
486
480
  if (!resolved) {
487
- throw new DanglingRefError(this.$ref);
481
+ throw new DanglingRefError(this.$ref, { remote: isRemoteRefPath(this.refPath) });
488
482
  }
489
483
  if (resolved.isRef()) {
490
484
  if (resolved.refType !== this.refType) {
@@ -498,15 +492,6 @@ export class OasRef extends OasBase {
498
492
  }
499
493
  return resolved;
500
494
  }
501
- /**
502
- * The component name the reference looks up.
503
- *
504
- * @throws {DanglingRefError} when the `$ref` has no name, such as
505
- * `#/components/schemas/`: it names nothing
506
- */
507
- toRefName() {
508
- return toLookupName(this.$ref);
509
- }
510
495
  /**
511
496
  * Narrows this reference to a schema reference.
512
497
  *
@@ -628,16 +613,12 @@ export class OasRef extends OasBase {
628
613
  const resolved = this.resolve().toJsonSchema({ resolve });
629
614
  return resolved;
630
615
  }
631
- const ref = {
632
- $ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
633
- };
616
+ const ref = { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
634
617
  return ref;
635
618
  }
636
619
  /** `{ $ref }` only, as {@link toJsonSchema} without `resolve` (skmtc/skmtc#338). */
637
620
  toJSON() {
638
- return {
639
- $ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
640
- };
621
+ return { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
641
622
  }
642
623
  }
643
624
  _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution() {
@@ -677,15 +658,21 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
677
658
  }
678
659
  const index = followed.indexOf(next);
679
660
  return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
680
- }, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document, refName) {
661
+ }, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document) {
681
662
  // A `#/components/<bucket>/<name>` ref names its bucket. A request body
682
663
  // that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
683
- // never looked up in the request bodies.
684
- const bucket = /^#\/components\/([^/]+)\//.exec(this.$ref)?.[1];
685
- const expected = refTypeToPluralPath(this.refType);
686
- if (bucket !== undefined && bucket !== expected) {
664
+ // never looked up in the request bodies. A ref to any other place
665
+ // (`#/components/parameters/limit/schema`) names no bucket: the kind of
666
+ // what it finds is checked in `resolveOnce`.
667
+ const bucket = toRefPathBucket(this.refPath);
668
+ const expected = toComponentsBucket(this.refType);
669
+ if (bucket === undefined) {
670
+ return document.toRefTarget(toRefPointer(this));
671
+ }
672
+ if (bucket !== expected) {
687
673
  throw new Error(`Ref type mismatch for "${this.$ref}". Expected a ref into "components/${expected}" but it names one in "components/${bucket}"`);
688
674
  }
675
+ const refName = this.refName;
689
676
  const c = document.components;
690
677
  const refType = this.refType;
691
678
  switch (refType) {
@@ -710,14 +697,14 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
710
697
  throw new Error(`Unhandled ref type: ${_exhaustive}`);
711
698
  }
712
699
  }
713
- }, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document, refName) {
700
+ }, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document) {
714
701
  // GraphQL only ever creates schema refs — there's no GQL concept
715
702
  // of a response/parameter/header/etc. ref. The refType field is
716
703
  // still typed by `T` for the OAS variants; on the GQL branch we
717
704
  // always do a schema lookup and let the post-lookup refType-vs-
718
705
  // oasType check catch any caller that constructed a non-schema
719
706
  // ref pointing at a GQL document.
720
- return document.registry.schemas[refName];
707
+ return document.registry.schemas[this.refName];
721
708
  }, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
722
709
  if (check.onRef(this)) {
723
710
  return true;
@@ -727,4 +714,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
727
714
  }
728
715
  const next = this.resolveOnce();
729
716
  return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
717
+ }, _OasRef_toWrittenRef = function _OasRef_toWrittenRef() {
718
+ if (this.refName === '') {
719
+ throw new DanglingRefError(this.$ref);
720
+ }
721
+ return isDefaultRefPath({ refPath: this.refPath, refType: this.refType })
722
+ ? `#/components/${toComponentsBucket(this.refType)}/${this.refName}`
723
+ : isRemoteRefPath(this.refPath)
724
+ ? this.$ref
725
+ : toRefPointer(this).replaceAll('%', '%25');
730
726
  };
@@ -1,4 +1,4 @@
1
- import { toRefName } from '../../helpers/refFns.js';
1
+ import { toRefParts, toRefPointer } from '../../helpers/refFns.js';
2
2
  /**
3
3
  * Walk an {@link SchemaPath} into a schema, resolving `$ref`s as it descends.
4
4
  *
@@ -93,8 +93,10 @@ const selectUnionMember = (union, segment) => {
93
93
  throw new Error(`Schema path segment "${segment}" discriminates on "${propertyName}", but this union's discriminator is "${union.discriminator.propertyName}"`);
94
94
  }
95
95
  const mapped = union.discriminator.mapping?.[value];
96
- const targetRefName = mapped ? toRefName(mapped) : value;
97
- const member = findMemberByRefName(union, targetRefName);
96
+ // A mapping holds a whole `$ref` or a bare schema name.
97
+ const member = mapped?.includes('#')
98
+ ? findMemberByPointer(union, mapped)
99
+ : findMemberByRefName(union, mapped ? toRefParts({ $ref: mapped }).refName : value);
98
100
  if (!member) {
99
101
  throw new Error(`Schema path segment "${segment}" does not resolve to a union member via the discriminator`);
100
102
  }
@@ -105,11 +107,15 @@ const selectUnionMember = (union, segment) => {
105
107
  if (!member) {
106
108
  const refNames = union.members
107
109
  .filter(member => member.isRef())
108
- .map(member => member.toRefName());
110
+ .map(member => member.refName);
109
111
  throw new Error(`Schema path segment "${segment}" does not match a union member refName (available: ${refNames.map(name => `$${name}`).join(', ') || 'none — use "[index]" for inline members'})`);
110
112
  }
111
113
  return member;
112
114
  }
113
115
  throw new Error(`Schema path segment "${segment}" is not a valid union selector; use "$RefName", "{discriminator:value}", or "[index]"`);
114
116
  };
115
- const findMemberByRefName = (union, refName) => union.members.find(member => member.isRef() && member.toRefName() === refName);
117
+ const findMemberByPointer = (union, $ref) => {
118
+ const pointer = toRefPointer(toRefParts({ $ref }));
119
+ return union.members.find(member => member.isRef() && toRefPointer(member) === pointer);
120
+ };
121
+ const findMemberByRefName = (union, refName) => union.members.find(member => member.isRef() && member.refName === refName);
@@ -0,0 +1,30 @@
1
+ import type { ParseContextType } from '../context/parseTypes.js';
2
+ import type { StackTrail } from '../context/StackTrail.js';
3
+ import { OasUnknown } from '../oas/unknown/Unknown.js';
4
+ export type ToMissingParameterSchemaArgs = {
5
+ parameter: unknown;
6
+ name: string;
7
+ location: string;
8
+ /** Trail that ends in the parameter. */
9
+ stackTrail: StackTrail;
10
+ context: ParseContextType;
11
+ };
12
+ /**
13
+ * The schema of a parameter with neither `schema` nor `content`: logs one
14
+ * `MISSING_PARAMETER_SCHEMA` warning and returns an empty schema `{}`.
15
+ * Shared by the 3.0, 3.1 and 3.2 parsers.
16
+ */
17
+ export declare const toMissingParameterSchema: ({ parameter, name, location, stackTrail, context }: ToMissingParameterSchemaArgs) => OasUnknown;
18
+ export type ToMissingHeaderSchemaArgs = {
19
+ header: unknown;
20
+ name: string;
21
+ /** Trail that ends in the header. */
22
+ stackTrail: StackTrail;
23
+ context: ParseContextType;
24
+ };
25
+ /**
26
+ * The schema of a header with neither `schema` nor `content`: logs one
27
+ * `MISSING_HEADER_SCHEMA` warning and returns an empty schema `{}`.
28
+ * Shared by the 3.0, 3.1 and 3.2 parsers.
29
+ */
30
+ export declare const toMissingHeaderSchema: ({ header, name, stackTrail, context }: ToMissingHeaderSchemaArgs) => OasUnknown;
@@ -0,0 +1,33 @@
1
+ import { OasUnknown } from '../oas/unknown/Unknown.js';
2
+ /**
3
+ * The schema of a parameter with neither `schema` nor `content`: logs one
4
+ * `MISSING_PARAMETER_SCHEMA` warning and returns an empty schema `{}`.
5
+ * Shared by the 3.0, 3.1 and 3.2 parsers.
6
+ */
7
+ export const toMissingParameterSchema = ({ parameter, name, location, stackTrail, context }) => {
8
+ context.logIssueNoKey({
9
+ stackTrail,
10
+ parent: parameter,
11
+ level: 'warning',
12
+ type: 'MISSING_PARAMETER_SCHEMA',
13
+ message: `Parameter '${name}' in ${location} has neither schema nor content; read as an empty schema {}`
14
+ });
15
+ return toEmptySchema({ stackTrail, context });
16
+ };
17
+ /**
18
+ * The schema of a header with neither `schema` nor `content`: logs one
19
+ * `MISSING_HEADER_SCHEMA` warning and returns an empty schema `{}`.
20
+ * Shared by the 3.0, 3.1 and 3.2 parsers.
21
+ */
22
+ export const toMissingHeaderSchema = ({ header, name, stackTrail, context }) => {
23
+ context.logIssueNoKey({
24
+ stackTrail,
25
+ parent: header,
26
+ level: 'warning',
27
+ type: 'MISSING_HEADER_SCHEMA',
28
+ message: `Header '${name}' has neither schema nor content; read as an empty schema {}`
29
+ });
30
+ return toEmptySchema({ stackTrail, context });
31
+ };
32
+ /** The `{}` schema, as the parser reads it: an {@link OasUnknown}. */
33
+ const toEmptySchema = ({ stackTrail, context }) => stackTrail.trace('schema', st => context.withStackTrail(st, () => new OasUnknown({}, context)));
@@ -6,6 +6,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
6
6
  import { OasHeader } from '../../../oas/header/Header.js';
7
7
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
8
8
  import { toComponentEntries } from '../../toComponentEntries.js';
9
+ import { toMissingHeaderSchema } from '../../missingSchema.js';
9
10
  export const toHeadersV3 = ({ headers, stackTrail, context }) => {
10
11
  if (!headers) {
11
12
  return undefined;
@@ -63,5 +64,9 @@ const toHeaderV3 = ({ header, name, stackTrail, context }) => {
63
64
  content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
64
65
  extensionFields
65
66
  };
67
+ // A `null` schema or content reads as absent; a boolean schema does not.
68
+ if (typeof schema !== 'boolean' && fields.schema === undefined && fields.content === undefined) {
69
+ fields.schema = toMissingHeaderSchema({ header, name, stackTrail, context });
70
+ }
66
71
  return new OasHeader(fields);
67
72
  };
@@ -8,6 +8,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
8
8
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
9
9
  import * as v from 'valibot';
10
10
  import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
11
+ import { toMissingParameterSchema } from '../../missingSchema.js';
11
12
  import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
12
13
  const parameterLocation = v.enum({
13
14
  query: 'query',
@@ -112,6 +113,16 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
112
113
  content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
113
114
  extensionFields
114
115
  };
116
+ // A `null` schema or content reads as absent; a boolean schema does not.
117
+ if (typeof schema !== 'boolean' && fields.schema === undefined && fields.content === undefined) {
118
+ fields.schema = toMissingParameterSchema({
119
+ parameter,
120
+ name,
121
+ location: parsedLocation,
122
+ stackTrail,
123
+ context
124
+ });
125
+ }
115
126
  return context.withStackTrail(stackTrail, () => new OasParameter(fields, context));
116
127
  };
117
128
  const toStyle = ({ style, location, stackTrail }) => {
@@ -0,0 +1,23 @@
1
+ import type { ParseContextType } from '../../../context/parseTypes.js';
2
+ import type { StackTrail } from '../../../context/StackTrail.js';
3
+ import type { ComponentsEntry } from '../../../oas/components/Components.js';
4
+ import type { OasRefData } from '../../../oas/ref/ref-types.js';
5
+ /** What {@link toRefTargetV3} parses. */
6
+ export type ToRefTargetArgs = {
7
+ /** The kind of component the ref is written for. */
8
+ refType: OasRefData['refType'];
9
+ /** The last segment of the target's pointer, unescaped: the key it parses under. */
10
+ name: string;
11
+ /** The raw value at the pointer. */
12
+ value: Record<string, unknown>;
13
+ /** The trail of the target's parent, so the target parses at its own position. */
14
+ stackTrail: StackTrail;
15
+ context: ParseContextType;
16
+ };
17
+ /**
18
+ * Parses the target of a ref that does not point at a component
19
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
20
+ * at its own position, with the parser that components of its kind use. Gives
21
+ * `undefined` when the target does not parse (the parser has logged why).
22
+ */
23
+ export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
@@ -0,0 +1,70 @@
1
+ import { isPlainObject } from '../../isPlainObject.js';
2
+ import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
3
+ import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
4
+ import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
5
+ import { toRequestBodiesV3 } from '../requestBody/toRequestBodiesV3.js';
6
+ import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
7
+ import { toLinksV3 } from '../link/toLinksV3.js';
8
+ import { toExampleV3 } from '../example/toExamplesV3.js';
9
+ import { toSecuritySchemesV3 } from '../securitySchemes/toSecuritySchemes.js';
10
+ import { tryParseAt } from '../../../context/tryParseAt.js';
11
+ /**
12
+ * The raw value read as the OpenAPI type its parser takes, as the components
13
+ * parser reads `documentObject.components`: the parser checks what it reads.
14
+ */
15
+ const isRawEntry = (value) => isPlainObject(value);
16
+ /**
17
+ * Parses the target of a ref that does not point at a component
18
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
19
+ * at its own position, with the parser that components of its kind use. Gives
20
+ * `undefined` when the target does not parse (the parser has logged why).
21
+ */
22
+ export const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
23
+ switch (refType) {
24
+ case 'schema':
25
+ return isRawEntry(value)
26
+ ? toOptionalSchemasV3({ schemas: { [name]: value }, stackTrail, context })?.[name]
27
+ : undefined;
28
+ case 'parameter':
29
+ return isRawEntry(value)
30
+ ? toOptionalParametersV3({ parameters: { [name]: value }, stackTrail, context })?.[name]
31
+ : undefined;
32
+ case 'response':
33
+ return isRawEntry(value)
34
+ ? toOptionalResponsesV3({ responses: { [name]: value }, stackTrail, context })?.[name]
35
+ : undefined;
36
+ case 'requestBody':
37
+ return isRawEntry(value)
38
+ ? toRequestBodiesV3({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
39
+ : undefined;
40
+ case 'header':
41
+ return isRawEntry(value)
42
+ ? toComponentHeadersV3({ headers: { [name]: value }, stackTrail, context })?.[name]
43
+ : undefined;
44
+ case 'link':
45
+ return isRawEntry(value)
46
+ ? toLinksV3({ links: { [name]: value }, stackTrail, context })?.[name]
47
+ : undefined;
48
+ case 'example':
49
+ // No components parser reads a single example by key, so the target
50
+ // is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
51
+ return isRawEntry(value)
52
+ ? tryParseAt({
53
+ stackTrail,
54
+ key: name,
55
+ context,
56
+ type: 'INVALID_EXAMPLE',
57
+ parent: value,
58
+ fn: st => toExampleV3({ example: value, stackTrail: st, context })
59
+ })
60
+ : undefined;
61
+ case 'securityScheme':
62
+ return isRawEntry(value)
63
+ ? toSecuritySchemesV3({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
64
+ : undefined;
65
+ default: {
66
+ const _exhaustive = refType;
67
+ throw new Error(`Unhandled ref type: ${_exhaustive}`);
68
+ }
69
+ }
70
+ };
@@ -6,6 +6,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
6
6
  import { OasHeader } from '../../../oas/header/Header.js';
7
7
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
8
8
  import { toComponentEntries } from '../../toComponentEntries.js';
9
+ import { toMissingHeaderSchema } from '../../missingSchema.js';
9
10
  export const toHeadersV3 = ({ headers, stackTrail, context }) => {
10
11
  if (!headers) {
11
12
  return undefined;
@@ -63,5 +64,9 @@ const toHeaderV3 = ({ header, name, stackTrail, context }) => {
63
64
  content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
64
65
  extensionFields
65
66
  };
67
+ // A `null` schema or content reads as absent; a boolean schema does not.
68
+ if (typeof schema !== 'boolean' && fields.schema === undefined && fields.content === undefined) {
69
+ fields.schema = toMissingHeaderSchema({ header, name, stackTrail, context });
70
+ }
66
71
  return new OasHeader(fields);
67
72
  };
@@ -8,6 +8,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
8
8
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
9
9
  import * as v from 'valibot';
10
10
  import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
11
+ import { toMissingParameterSchema } from '../../missingSchema.js';
11
12
  import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
12
13
  const parameterLocation = v.enum({
13
14
  query: 'query',
@@ -112,6 +113,16 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
112
113
  content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
113
114
  extensionFields
114
115
  };
116
+ // A `null` schema or content reads as absent; a boolean schema does not.
117
+ if (typeof schema !== 'boolean' && fields.schema === undefined && fields.content === undefined) {
118
+ fields.schema = toMissingParameterSchema({
119
+ parameter,
120
+ name,
121
+ location: parsedLocation,
122
+ stackTrail,
123
+ context
124
+ });
125
+ }
115
126
  return context.withStackTrail(stackTrail, () => new OasParameter(fields, context));
116
127
  };
117
128
  const toStyle = ({ style, location, stackTrail }) => {
@@ -0,0 +1,23 @@
1
+ import type { ParseContextType } from '../../../context/parseTypes.js';
2
+ import type { StackTrail } from '../../../context/StackTrail.js';
3
+ import type { ComponentsEntry } from '../../../oas/components/Components.js';
4
+ import type { OasRefData } from '../../../oas/ref/ref-types.js';
5
+ /** What {@link toRefTargetV3} parses. */
6
+ export type ToRefTargetArgs = {
7
+ /** The kind of component the ref is written for. */
8
+ refType: OasRefData['refType'];
9
+ /** The last segment of the target's pointer, unescaped: the key it parses under. */
10
+ name: string;
11
+ /** The raw value at the pointer. */
12
+ value: Record<string, unknown>;
13
+ /** The trail of the target's parent, so the target parses at its own position. */
14
+ stackTrail: StackTrail;
15
+ context: ParseContextType;
16
+ };
17
+ /**
18
+ * Parses the target of a ref that does not point at a component
19
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
20
+ * at its own position, with the parser that components of its kind use. Gives
21
+ * `undefined` when the target does not parse (the parser has logged why).
22
+ */
23
+ export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
@@ -0,0 +1,70 @@
1
+ import { isPlainObject } from '../../isPlainObject.js';
2
+ import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
3
+ import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
4
+ import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
5
+ import { toRequestBodiesV3 } from '../requestBody/toRequestBodiesV3.js';
6
+ import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
7
+ import { toLinksV3 } from '../link/toLinksV3.js';
8
+ import { toExampleV3 } from '../example/toExamplesV3.js';
9
+ import { toSecuritySchemesV3 } from '../securitySchemes/toSecuritySchemes.js';
10
+ import { tryParseAt } from '../../../context/tryParseAt.js';
11
+ /**
12
+ * The raw value read as the OpenAPI type its parser takes, as the components
13
+ * parser reads `documentObject.components`: the parser checks what it reads.
14
+ */
15
+ const isRawEntry = (value) => isPlainObject(value);
16
+ /**
17
+ * Parses the target of a ref that does not point at a component
18
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
19
+ * at its own position, with the parser that components of its kind use. Gives
20
+ * `undefined` when the target does not parse (the parser has logged why).
21
+ */
22
+ export const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
23
+ switch (refType) {
24
+ case 'schema':
25
+ return isRawEntry(value)
26
+ ? toOptionalSchemasV3({ schemas: { [name]: value }, stackTrail, context })?.[name]
27
+ : undefined;
28
+ case 'parameter':
29
+ return isRawEntry(value)
30
+ ? toOptionalParametersV3({ parameters: { [name]: value }, stackTrail, context })?.[name]
31
+ : undefined;
32
+ case 'response':
33
+ return isRawEntry(value)
34
+ ? toOptionalResponsesV3({ responses: { [name]: value }, stackTrail, context })?.[name]
35
+ : undefined;
36
+ case 'requestBody':
37
+ return isRawEntry(value)
38
+ ? toRequestBodiesV3({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
39
+ : undefined;
40
+ case 'header':
41
+ return isRawEntry(value)
42
+ ? toComponentHeadersV3({ headers: { [name]: value }, stackTrail, context })?.[name]
43
+ : undefined;
44
+ case 'link':
45
+ return isRawEntry(value)
46
+ ? toLinksV3({ links: { [name]: value }, stackTrail, context })?.[name]
47
+ : undefined;
48
+ case 'example':
49
+ // No components parser reads a single example by key, so the target
50
+ // is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
51
+ return isRawEntry(value)
52
+ ? tryParseAt({
53
+ stackTrail,
54
+ key: name,
55
+ context,
56
+ type: 'INVALID_EXAMPLE',
57
+ parent: value,
58
+ fn: st => toExampleV3({ example: value, stackTrail: st, context })
59
+ })
60
+ : undefined;
61
+ case 'securityScheme':
62
+ return isRawEntry(value)
63
+ ? toSecuritySchemesV3({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
64
+ : undefined;
65
+ default: {
66
+ const _exhaustive = refType;
67
+ throw new Error(`Unhandled ref type: ${_exhaustive}`);
68
+ }
69
+ }
70
+ };
@@ -6,6 +6,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
6
6
  import { OasHeader } from '../../../oas/header/Header.js';
7
7
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
8
8
  import { toComponentEntries } from '../../toComponentEntries.js';
9
+ import { toMissingHeaderSchema } from '../../missingSchema.js';
9
10
  export const toHeadersV3 = ({ headers, stackTrail, context }) => {
10
11
  if (!headers) {
11
12
  return undefined;
@@ -63,5 +64,9 @@ const toHeaderV3 = ({ header, name, stackTrail, context }) => {
63
64
  content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
64
65
  extensionFields
65
66
  };
67
+ // A `null` schema or content reads as absent; a boolean schema does not.
68
+ if (typeof schema !== 'boolean' && fields.schema === undefined && fields.content === undefined) {
69
+ fields.schema = toMissingHeaderSchema({ header, name, stackTrail, context });
70
+ }
66
71
  return new OasHeader(fields);
67
72
  };