@skmtc/core 0.45.0 → 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 (89) 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 +5 -4
  8. package/esm/dsl/GeneratorKeys.d.ts +21 -15
  9. package/esm/dsl/GeneratorKeys.js +16 -11
  10. package/esm/dsl/Inserted.d.ts +1 -1
  11. package/esm/dsl/Inserted.js +1 -1
  12. package/esm/dsl/model/ModelDriver.d.ts +6 -5
  13. package/esm/dsl/model/ModelDriver.js +22 -20
  14. package/esm/dsl/model/toModelEntry.d.ts +18 -18
  15. package/esm/dsl/model/toModelEntry.js +9 -9
  16. package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
  17. package/esm/dsl/model/toModelProjectionBase.js +12 -8
  18. package/esm/dsl/model/types.d.ts +26 -17
  19. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  20. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  21. package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  22. package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  23. package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  24. package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
  25. package/esm/helpers/refFns.d.ts +108 -43
  26. package/esm/helpers/refFns.js +166 -57
  27. package/esm/oas/document/Document.d.ts +6 -0
  28. package/esm/oas/document/Document.js +44 -2
  29. package/esm/oas/ref/DanglingRefError.d.ts +5 -2
  30. package/esm/oas/ref/DanglingRefError.js +4 -3
  31. package/esm/oas/ref/Ref.d.ts +23 -12
  32. package/esm/oas/ref/Ref.js +68 -72
  33. package/esm/oas/schemaPath/traverseSchema.js +11 -5
  34. package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  35. package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
  36. package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  37. package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
  38. package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  39. package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
  40. package/esm/types/GeneratorType.d.ts +1 -1
  41. package/esm/types/ProjectionOptions.d.ts +1 -1
  42. package/esm/types/ProjectionOptions.js +1 -1
  43. package/esm/types/RefName.d.ts +3 -3
  44. package/esm/types/TypeSystem.d.ts +3 -3
  45. package/package.json +1 -1
  46. package/script/anchors/attribute.js +3 -2
  47. package/script/context/CoreContext.d.ts +1 -1
  48. package/script/context/CoreContext.js +1 -1
  49. package/script/context/GenerateContext.d.ts +13 -10
  50. package/script/context/GenerateContext.js +36 -25
  51. package/script/context/ParseContext.js +135 -33
  52. package/script/context/generateTypes.d.ts +5 -4
  53. package/script/dsl/GeneratorKeys.d.ts +21 -15
  54. package/script/dsl/GeneratorKeys.js +16 -11
  55. package/script/dsl/Inserted.d.ts +1 -1
  56. package/script/dsl/Inserted.js +1 -1
  57. package/script/dsl/model/ModelDriver.d.ts +6 -5
  58. package/script/dsl/model/ModelDriver.js +22 -20
  59. package/script/dsl/model/toModelEntry.d.ts +18 -18
  60. package/script/dsl/model/toModelEntry.js +9 -9
  61. package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
  62. package/script/dsl/model/toModelProjectionBase.js +12 -8
  63. package/script/dsl/model/types.d.ts +26 -17
  64. package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  65. package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  66. package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  67. package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  68. package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  69. package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
  70. package/script/helpers/refFns.d.ts +108 -43
  71. package/script/helpers/refFns.js +180 -59
  72. package/script/oas/document/Document.d.ts +6 -0
  73. package/script/oas/document/Document.js +44 -2
  74. package/script/oas/ref/DanglingRefError.d.ts +5 -2
  75. package/script/oas/ref/DanglingRefError.js +4 -3
  76. package/script/oas/ref/Ref.d.ts +23 -12
  77. package/script/oas/ref/Ref.js +67 -71
  78. package/script/oas/schemaPath/traverseSchema.js +10 -4
  79. package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  80. package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
  81. package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  82. package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
  83. package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  84. package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
  85. package/script/types/GeneratorType.d.ts +1 -1
  86. package/script/types/ProjectionOptions.d.ts +1 -1
  87. package/script/types/ProjectionOptions.js +1 -1
  88. package/script/types/RefName.d.ts +3 -3
  89. package/script/types/TypeSystem.d.ts +3 -3
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
13
+ var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain, _OasRef_toWrittenRef;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.OasRef = void 0;
16
16
  require("../../_dnt.polyfills.js");
@@ -19,45 +19,6 @@ const refFns_js_1 = require("../../helpers/refFns.js");
19
19
  const OasBase_js_1 = require("../../types/OasBase.js");
20
20
  const DanglingRefError_js_1 = require("./DanglingRefError.js");
21
21
  const siblings_js_1 = require("../schema/siblings.js");
22
- /**
23
- * Converts a ref type to its plural components path.
24
- */
25
- function refTypeToPluralPath(refType) {
26
- switch (refType) {
27
- case 'schema':
28
- return 'schemas';
29
- case 'requestBody':
30
- return 'requestBodies';
31
- case 'parameter':
32
- return 'parameters';
33
- case 'response':
34
- return 'responses';
35
- case 'example':
36
- return 'examples';
37
- case 'header':
38
- return 'headers';
39
- case 'securityScheme':
40
- return 'securitySchemes';
41
- case 'link':
42
- return 'links';
43
- default: {
44
- const _exhaustive = refType;
45
- throw new Error(`Unhandled ref type: ${_exhaustive}`);
46
- }
47
- }
48
- }
49
- /**
50
- * The name `resolveOnce` looks up. `toRefName` throws for a `$ref` whose last
51
- * segment is empty (`#/components/schemas/`): that `$ref` names nothing.
52
- */
53
- const toLookupName = ($ref) => {
54
- try {
55
- return (0, refFns_js_1.toRefName)($ref);
56
- }
57
- catch {
58
- throw new DanglingRefError_js_1.DanglingRefError($ref);
59
- }
60
- };
61
22
  /**
62
23
  * Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
63
24
  *
@@ -116,8 +77,8 @@ const toLookupName = ($ref) => {
116
77
  * function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
117
78
  * if (schema.isRef()) {
118
79
  * // Handle reference
119
- * const refName = schema.toRefName();
120
- * console.log(`Processing reference: ${refName}`);
80
+ * const { refName, refPath } = schema;
81
+ * console.log(`Processing reference: ${refName} in ${refPath}`);
121
82
  *
122
83
  * // Resolve only when needed
123
84
  * const resolved = schema.resolve();
@@ -179,13 +140,40 @@ class OasRef extends OasBase_js_1.OasBase {
179
140
  writable: true,
180
141
  value: void 0
181
142
  });
182
- /** The JSON Reference: `#/components/<bucket>/<name>`. */
143
+ /**
144
+ * The JSON Reference, as written: a component (`#/components/<bucket>/<name>`)
145
+ * or any other place in the document (`#/components/schemas/Pet/properties/tag`).
146
+ */
183
147
  Object.defineProperty(this, "$ref", {
184
148
  enumerable: true,
185
149
  configurable: true,
186
150
  writable: true,
187
151
  value: void 0
188
152
  });
153
+ /**
154
+ * The last segment of the `$ref`'s pointer, unescaped: `Pet` for
155
+ * `#/components/schemas/Pet`, `schema0` for
156
+ * `#/components/schemas/__sharedInput/$defs/schema0`. Empty for a `$ref`
157
+ * that ends in `/`, which names nothing.
158
+ */
159
+ Object.defineProperty(this, "refName", {
160
+ enumerable: true,
161
+ configurable: true,
162
+ writable: true,
163
+ value: void 0
164
+ });
165
+ /**
166
+ * The pointer before {@link refName}, with no percent escapes: `#/components/schemas`
167
+ * for a schema component, `#/components/schemas/__sharedInput/$defs` for
168
+ * the `$defs` entry above. A generator that names by {@link refName} alone
169
+ * may ignore it.
170
+ */
171
+ Object.defineProperty(this, "refPath", {
172
+ enumerable: true,
173
+ configurable: true,
174
+ writable: true,
175
+ value: void 0
176
+ });
189
177
  /**
190
178
  * Use-site nullability (see {@link SiblingKeywords.nullable}). Assigned
191
179
  * even when `undefined`, so `'nullable' in ref` is always true and the
@@ -395,6 +383,9 @@ class OasRef extends OasBase_js_1.OasBase {
395
383
  _OasRef_resolution.set(this, void 0);
396
384
  this.refType = fields.refType;
397
385
  this.$ref = fields.$ref;
386
+ const { refName, refPath } = (0, refFns_js_1.toRefParts)({ $ref: fields.$ref });
387
+ this.refName = refName;
388
+ this.refPath = refPath;
398
389
  this.nullable = fields.nullable;
399
390
  this.readOnly = fields.readOnly;
400
391
  this.writeOnly = fields.writeOnly;
@@ -471,8 +462,9 @@ class OasRef extends OasBase_js_1.OasBase {
471
462
  }
472
463
  /**
473
464
  * Resolves this reference one level. Dispatches on the document's
474
- * protocol — OAS reads from `document.components.<bucket>`; GQL
475
- * reads from `document.registry.schemas`.
465
+ * protocol — OAS reads a component from `document.components.<bucket>`,
466
+ * and any other target from the targets the parser kept by pointer
467
+ * (`OasDocument.toRefTarget`); GQL reads from `document.registry.schemas`.
476
468
  *
477
469
  * @returns Either the resolved component or another reference in the chain
478
470
  * @throws {DanglingRefError} when the reference names nothing in the
@@ -482,12 +474,14 @@ class OasRef extends OasBase_js_1.OasBase {
482
474
  * `requestBody` ref to `#/components/schemas/…`
483
475
  */
484
476
  resolveOnce() {
485
- const refName = toLookupName(this.$ref);
477
+ if (this.refName === '') {
478
+ throw new DanglingRefError_js_1.DanglingRefError(this.$ref);
479
+ }
486
480
  const resolved = __classPrivateFieldGet(this, _OasRef_document, "f").type === 'oas'
487
- ? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value, refName)
488
- : __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value, refName);
481
+ ? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value)
482
+ : __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value);
489
483
  if (!resolved) {
490
- throw new DanglingRefError_js_1.DanglingRefError(this.$ref);
484
+ throw new DanglingRefError_js_1.DanglingRefError(this.$ref, { remote: (0, refFns_js_1.isRemoteRefPath)(this.refPath) });
491
485
  }
492
486
  if (resolved.isRef()) {
493
487
  if (resolved.refType !== this.refType) {
@@ -501,15 +495,6 @@ class OasRef extends OasBase_js_1.OasBase {
501
495
  }
502
496
  return resolved;
503
497
  }
504
- /**
505
- * The component name the reference looks up.
506
- *
507
- * @throws {DanglingRefError} when the `$ref` has no name, such as
508
- * `#/components/schemas/`: it names nothing
509
- */
510
- toRefName() {
511
- return toLookupName(this.$ref);
512
- }
513
498
  /**
514
499
  * Narrows this reference to a schema reference.
515
500
  *
@@ -631,16 +616,12 @@ class OasRef extends OasBase_js_1.OasBase {
631
616
  const resolved = this.resolve().toJsonSchema({ resolve });
632
617
  return resolved;
633
618
  }
634
- const ref = {
635
- $ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
636
- };
619
+ const ref = { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
637
620
  return ref;
638
621
  }
639
622
  /** `{ $ref }` only, as {@link toJsonSchema} without `resolve` (skmtc/skmtc#338). */
640
623
  toJSON() {
641
- return {
642
- $ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
643
- };
624
+ return { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
644
625
  }
645
626
  }
646
627
  exports.OasRef = OasRef;
@@ -681,15 +662,21 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
681
662
  }
682
663
  const index = followed.indexOf(next);
683
664
  return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
684
- }, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document, refName) {
665
+ }, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document) {
685
666
  // A `#/components/<bucket>/<name>` ref names its bucket. A request body
686
667
  // that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
687
- // never looked up in the request bodies.
688
- const bucket = /^#\/components\/([^/]+)\//.exec(this.$ref)?.[1];
689
- const expected = refTypeToPluralPath(this.refType);
690
- if (bucket !== undefined && bucket !== expected) {
668
+ // never looked up in the request bodies. A ref to any other place
669
+ // (`#/components/parameters/limit/schema`) names no bucket: the kind of
670
+ // what it finds is checked in `resolveOnce`.
671
+ const bucket = (0, refFns_js_1.toRefPathBucket)(this.refPath);
672
+ const expected = (0, refFns_js_1.toComponentsBucket)(this.refType);
673
+ if (bucket === undefined) {
674
+ return document.toRefTarget((0, refFns_js_1.toRefPointer)(this));
675
+ }
676
+ if (bucket !== expected) {
691
677
  throw new Error(`Ref type mismatch for "${this.$ref}". Expected a ref into "components/${expected}" but it names one in "components/${bucket}"`);
692
678
  }
679
+ const refName = this.refName;
693
680
  const c = document.components;
694
681
  const refType = this.refType;
695
682
  switch (refType) {
@@ -714,14 +701,14 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
714
701
  throw new Error(`Unhandled ref type: ${_exhaustive}`);
715
702
  }
716
703
  }
717
- }, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document, refName) {
704
+ }, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document) {
718
705
  // GraphQL only ever creates schema refs — there's no GQL concept
719
706
  // of a response/parameter/header/etc. ref. The refType field is
720
707
  // still typed by `T` for the OAS variants; on the GQL branch we
721
708
  // always do a schema lookup and let the post-lookup refType-vs-
722
709
  // oasType check catch any caller that constructed a non-schema
723
710
  // ref pointing at a GQL document.
724
- return document.registry.schemas[refName];
711
+ return document.registry.schemas[this.refName];
725
712
  }, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
726
713
  if (check.onRef(this)) {
727
714
  return true;
@@ -731,4 +718,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
731
718
  }
732
719
  const next = this.resolveOnce();
733
720
  return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
721
+ }, _OasRef_toWrittenRef = function _OasRef_toWrittenRef() {
722
+ if (this.refName === '') {
723
+ throw new DanglingRefError_js_1.DanglingRefError(this.$ref);
724
+ }
725
+ return (0, refFns_js_1.isDefaultRefPath)({ refPath: this.refPath, refType: this.refType })
726
+ ? `#/components/${(0, refFns_js_1.toComponentsBucket)(this.refType)}/${this.refName}`
727
+ : (0, refFns_js_1.isRemoteRefPath)(this.refPath)
728
+ ? this.$ref
729
+ : (0, refFns_js_1.toRefPointer)(this).replaceAll('%', '%25');
734
730
  };
@@ -97,8 +97,10 @@ const selectUnionMember = (union, segment) => {
97
97
  throw new Error(`Schema path segment "${segment}" discriminates on "${propertyName}", but this union's discriminator is "${union.discriminator.propertyName}"`);
98
98
  }
99
99
  const mapped = union.discriminator.mapping?.[value];
100
- const targetRefName = mapped ? (0, refFns_js_1.toRefName)(mapped) : value;
101
- const member = findMemberByRefName(union, targetRefName);
100
+ // A mapping holds a whole `$ref` or a bare schema name.
101
+ const member = mapped?.includes('#')
102
+ ? findMemberByPointer(union, mapped)
103
+ : findMemberByRefName(union, mapped ? (0, refFns_js_1.toRefParts)({ $ref: mapped }).refName : value);
102
104
  if (!member) {
103
105
  throw new Error(`Schema path segment "${segment}" does not resolve to a union member via the discriminator`);
104
106
  }
@@ -109,11 +111,15 @@ const selectUnionMember = (union, segment) => {
109
111
  if (!member) {
110
112
  const refNames = union.members
111
113
  .filter(member => member.isRef())
112
- .map(member => member.toRefName());
114
+ .map(member => member.refName);
113
115
  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'})`);
114
116
  }
115
117
  return member;
116
118
  }
117
119
  throw new Error(`Schema path segment "${segment}" is not a valid union selector; use "$RefName", "{discriminator:value}", or "[index]"`);
118
120
  };
119
- const findMemberByRefName = (union, refName) => union.members.find(member => member.isRef() && member.toRefName() === refName);
121
+ const findMemberByPointer = (union, $ref) => {
122
+ const pointer = (0, refFns_js_1.toRefPointer)((0, refFns_js_1.toRefParts)({ $ref }));
123
+ return union.members.find(member => member.isRef() && (0, refFns_js_1.toRefPointer)(member) === pointer);
124
+ };
125
+ const findMemberByRefName = (union, refName) => union.members.find(member => member.isRef() && member.refName === refName);
@@ -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,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRefTargetV3 = void 0;
4
+ const isPlainObject_js_1 = require("../../isPlainObject.js");
5
+ const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
6
+ const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
7
+ const toResponseV3_js_1 = require("../response/toResponseV3.js");
8
+ const toRequestBodiesV3_js_1 = require("../requestBody/toRequestBodiesV3.js");
9
+ const toHeadersV3_js_1 = require("../header/toHeadersV3.js");
10
+ const toLinksV3_js_1 = require("../link/toLinksV3.js");
11
+ const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
12
+ const toSecuritySchemes_js_1 = require("../securitySchemes/toSecuritySchemes.js");
13
+ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
14
+ /**
15
+ * The raw value read as the OpenAPI type its parser takes, as the components
16
+ * parser reads `documentObject.components`: the parser checks what it reads.
17
+ */
18
+ const isRawEntry = (value) => (0, isPlainObject_js_1.isPlainObject)(value);
19
+ /**
20
+ * Parses the target of a ref that does not point at a component
21
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
22
+ * at its own position, with the parser that components of its kind use. Gives
23
+ * `undefined` when the target does not parse (the parser has logged why).
24
+ */
25
+ const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
26
+ switch (refType) {
27
+ case 'schema':
28
+ return isRawEntry(value)
29
+ ? (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas: { [name]: value }, stackTrail, context })?.[name]
30
+ : undefined;
31
+ case 'parameter':
32
+ return isRawEntry(value)
33
+ ? (0, toParameterV3_js_1.toOptionalParametersV3)({ parameters: { [name]: value }, stackTrail, context })?.[name]
34
+ : undefined;
35
+ case 'response':
36
+ return isRawEntry(value)
37
+ ? (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses: { [name]: value }, stackTrail, context })?.[name]
38
+ : undefined;
39
+ case 'requestBody':
40
+ return isRawEntry(value)
41
+ ? (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
42
+ : undefined;
43
+ case 'header':
44
+ return isRawEntry(value)
45
+ ? (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers: { [name]: value }, stackTrail, context })?.[name]
46
+ : undefined;
47
+ case 'link':
48
+ return isRawEntry(value)
49
+ ? (0, toLinksV3_js_1.toLinksV3)({ links: { [name]: value }, stackTrail, context })?.[name]
50
+ : undefined;
51
+ case 'example':
52
+ // No components parser reads a single example by key, so the target
53
+ // is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
54
+ return isRawEntry(value)
55
+ ? (0, tryParseAt_js_1.tryParseAt)({
56
+ stackTrail,
57
+ key: name,
58
+ context,
59
+ type: 'INVALID_EXAMPLE',
60
+ parent: value,
61
+ fn: st => (0, toExamplesV3_js_1.toExampleV3)({ example: value, stackTrail: st, context })
62
+ })
63
+ : undefined;
64
+ case 'securityScheme':
65
+ return isRawEntry(value)
66
+ ? (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
67
+ : undefined;
68
+ default: {
69
+ const _exhaustive = refType;
70
+ throw new Error(`Unhandled ref type: ${_exhaustive}`);
71
+ }
72
+ }
73
+ };
74
+ exports.toRefTargetV3 = toRefTargetV3;
@@ -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,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRefTargetV3 = void 0;
4
+ const isPlainObject_js_1 = require("../../isPlainObject.js");
5
+ const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
6
+ const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
7
+ const toResponseV3_js_1 = require("../response/toResponseV3.js");
8
+ const toRequestBodiesV3_js_1 = require("../requestBody/toRequestBodiesV3.js");
9
+ const toHeadersV3_js_1 = require("../header/toHeadersV3.js");
10
+ const toLinksV3_js_1 = require("../link/toLinksV3.js");
11
+ const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
12
+ const toSecuritySchemes_js_1 = require("../securitySchemes/toSecuritySchemes.js");
13
+ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
14
+ /**
15
+ * The raw value read as the OpenAPI type its parser takes, as the components
16
+ * parser reads `documentObject.components`: the parser checks what it reads.
17
+ */
18
+ const isRawEntry = (value) => (0, isPlainObject_js_1.isPlainObject)(value);
19
+ /**
20
+ * Parses the target of a ref that does not point at a component
21
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
22
+ * at its own position, with the parser that components of its kind use. Gives
23
+ * `undefined` when the target does not parse (the parser has logged why).
24
+ */
25
+ const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
26
+ switch (refType) {
27
+ case 'schema':
28
+ return isRawEntry(value)
29
+ ? (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas: { [name]: value }, stackTrail, context })?.[name]
30
+ : undefined;
31
+ case 'parameter':
32
+ return isRawEntry(value)
33
+ ? (0, toParameterV3_js_1.toOptionalParametersV3)({ parameters: { [name]: value }, stackTrail, context })?.[name]
34
+ : undefined;
35
+ case 'response':
36
+ return isRawEntry(value)
37
+ ? (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses: { [name]: value }, stackTrail, context })?.[name]
38
+ : undefined;
39
+ case 'requestBody':
40
+ return isRawEntry(value)
41
+ ? (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
42
+ : undefined;
43
+ case 'header':
44
+ return isRawEntry(value)
45
+ ? (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers: { [name]: value }, stackTrail, context })?.[name]
46
+ : undefined;
47
+ case 'link':
48
+ return isRawEntry(value)
49
+ ? (0, toLinksV3_js_1.toLinksV3)({ links: { [name]: value }, stackTrail, context })?.[name]
50
+ : undefined;
51
+ case 'example':
52
+ // No components parser reads a single example by key, so the target
53
+ // is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
54
+ return isRawEntry(value)
55
+ ? (0, tryParseAt_js_1.tryParseAt)({
56
+ stackTrail,
57
+ key: name,
58
+ context,
59
+ type: 'INVALID_EXAMPLE',
60
+ parent: value,
61
+ fn: st => (0, toExamplesV3_js_1.toExampleV3)({ example: value, stackTrail: st, context })
62
+ })
63
+ : undefined;
64
+ case 'securityScheme':
65
+ return isRawEntry(value)
66
+ ? (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
67
+ : undefined;
68
+ default: {
69
+ const _exhaustive = refType;
70
+ throw new Error(`Unhandled ref type: ${_exhaustive}`);
71
+ }
72
+ }
73
+ };
74
+ exports.toRefTargetV3 = toRefTargetV3;
@@ -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,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRefTargetV3 = void 0;
4
+ const isPlainObject_js_1 = require("../../isPlainObject.js");
5
+ const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
6
+ const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
7
+ const toResponseV3_js_1 = require("../response/toResponseV3.js");
8
+ const toRequestBodiesV3_js_1 = require("../requestBody/toRequestBodiesV3.js");
9
+ const toHeadersV3_js_1 = require("../header/toHeadersV3.js");
10
+ const toLinksV3_js_1 = require("../link/toLinksV3.js");
11
+ const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
12
+ const toSecuritySchemes_js_1 = require("../securitySchemes/toSecuritySchemes.js");
13
+ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
14
+ /**
15
+ * The raw value read as the OpenAPI type its parser takes, as the components
16
+ * parser reads `documentObject.components`: the parser checks what it reads.
17
+ */
18
+ const isRawEntry = (value) => (0, isPlainObject_js_1.isPlainObject)(value);
19
+ /**
20
+ * Parses the target of a ref that does not point at a component
21
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
22
+ * at its own position, with the parser that components of its kind use. Gives
23
+ * `undefined` when the target does not parse (the parser has logged why).
24
+ */
25
+ const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
26
+ switch (refType) {
27
+ case 'schema':
28
+ return isRawEntry(value)
29
+ ? (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas: { [name]: value }, stackTrail, context })?.[name]
30
+ : undefined;
31
+ case 'parameter':
32
+ return isRawEntry(value)
33
+ ? (0, toParameterV3_js_1.toOptionalParametersV3)({ parameters: { [name]: value }, stackTrail, context })?.[name]
34
+ : undefined;
35
+ case 'response':
36
+ return isRawEntry(value)
37
+ ? (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses: { [name]: value }, stackTrail, context })?.[name]
38
+ : undefined;
39
+ case 'requestBody':
40
+ return isRawEntry(value)
41
+ ? (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
42
+ : undefined;
43
+ case 'header':
44
+ return isRawEntry(value)
45
+ ? (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers: { [name]: value }, stackTrail, context })?.[name]
46
+ : undefined;
47
+ case 'link':
48
+ return isRawEntry(value)
49
+ ? (0, toLinksV3_js_1.toLinksV3)({ links: { [name]: value }, stackTrail, context })?.[name]
50
+ : undefined;
51
+ case 'example':
52
+ // No components parser reads a single example by key, so the target
53
+ // is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
54
+ return isRawEntry(value)
55
+ ? (0, tryParseAt_js_1.tryParseAt)({
56
+ stackTrail,
57
+ key: name,
58
+ context,
59
+ type: 'INVALID_EXAMPLE',
60
+ parent: value,
61
+ fn: st => (0, toExamplesV3_js_1.toExampleV3)({ example: value, stackTrail: st, context })
62
+ })
63
+ : undefined;
64
+ case 'securityScheme':
65
+ return isRawEntry(value)
66
+ ? (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
67
+ : undefined;
68
+ default: {
69
+ const _exhaustive = refType;
70
+ throw new Error(`Unhandled ref type: ${_exhaustive}`);
71
+ }
72
+ }
73
+ };
74
+ exports.toRefTargetV3 = toRefTargetV3;
@@ -43,7 +43,7 @@ import type { ModelEntry } from '../dsl/model/toModelEntry.js';
43
43
  *
44
44
  * const modelEntry = toModelEntry({
45
45
  * id: 'typescript-models',
46
- * transform: ({ context, refName }) => {}
46
+ * transform: ({ context, ref }) => {}
47
47
  * });
48
48
  * // modelEntry.type === 'model'
49
49
  * ```
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Caller options for projections.
3
3
  *
4
4
  * Options are typed data the CALLING generator passes when it inserts a
5
- * peer: `context.insertModel(Peer, refName, { options })`. Enrichments are
5
+ * peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
6
6
  * the user's per-subject configuration and a variant selects one of them;
7
7
  * options belong to the caller.
8
8
  *
@@ -3,7 +3,7 @@
3
3
  * @fileoverview Caller options for projections.
4
4
  *
5
5
  * Options are typed data the CALLING generator passes when it inserts a
6
- * peer: `context.insertModel(Peer, refName, { options })`. Enrichments are
6
+ * peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
7
7
  * the user's per-subject configuration and a variant selects one of them;
8
8
  * options belong to the caller.
9
9
  *
@@ -99,14 +99,14 @@ import type { Brand } from './Brand.js';
99
99
  * @example In generator contexts
100
100
  * ```typescript
101
101
  * class ModelGenerator extends ModelProjectionBase {
102
- * constructor(args: { refName: RefName; ... }) {
102
+ * constructor(args: { ref: RefParts; ... }) {
103
103
  * super(args);
104
- * // this.refName is guaranteed to be a valid schema reference
104
+ * // this.ref.refName is the name of the model's ref
105
105
  * }
106
106
  *
107
107
  * toDefinition(): Definition {
108
108
  * // RefName ensures we're working with valid schema identifiers
109
- * const schemaName = this.refName; // Type: RefName
109
+ * const schemaName = this.ref.refName; // Type: RefName
110
110
  * return new Definition({
111
111
  * identifier: createType(schemaName),
112
112
  * // ...
@@ -7,7 +7,7 @@ import type { GenerateContextType } from '../context/generateTypes.js';
7
7
  import type { CustomValue } from '../dsl/CustomValue.js';
8
8
  import type { OasVoid } from '../oas/void/Void.js';
9
9
  import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
10
- import type { RefName } from './RefName.js';
10
+ import type { RefParts } from '../helpers/refFns.js';
11
11
  /**
12
12
  * Union type representing all possible type system values in the SKMTC code generation system.
13
13
  *
@@ -539,8 +539,8 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
539
539
  destinationPath: string;
540
540
  /** The schema to transform */
541
541
  schema: Schema;
542
- /** Optional root reference name for schema references */
543
- rootRef?: RefName;
542
+ /** The ref of the model whose value tree holds the schema */
543
+ rootRef?: RefParts;
544
544
  /** Whether the schema field is required */
545
545
  required: boolean | undefined;
546
546
  };