@skmtc/core 0.45.0 → 0.47.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 (187) 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.d.ts +3 -0
  7. package/esm/context/ParseContext.js +151 -39
  8. package/esm/context/generateTypes.d.ts +7 -6
  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/collateExamples.js +35 -17
  27. package/esm/helpers/refFns.d.ts +108 -43
  28. package/esm/helpers/refFns.js +166 -57
  29. package/esm/mod.d.ts +1 -0
  30. package/esm/mod.js +1 -0
  31. package/esm/oas/document/Document.d.ts +6 -0
  32. package/esm/oas/document/Document.js +44 -2
  33. package/esm/oas/intersection/Intersection.d.ts +122 -0
  34. package/esm/oas/intersection/Intersection.js +266 -0
  35. package/esm/oas/mediaType/jsonMediaType.d.ts +1 -1
  36. package/esm/oas/mediaType/jsonMediaType.js +3 -3
  37. package/esm/oas/ref/DanglingRefError.d.ts +5 -2
  38. package/esm/oas/ref/DanglingRefError.js +4 -3
  39. package/esm/oas/ref/Ref.d.ts +23 -12
  40. package/esm/oas/ref/Ref.js +68 -72
  41. package/esm/oas/requestBody/RequestBody.d.ts +1 -1
  42. package/esm/oas/requestBody/RequestBody.js +1 -1
  43. package/esm/oas/response/Response.d.ts +1 -1
  44. package/esm/oas/response/Response.js +1 -1
  45. package/esm/oas/schema/Schema.d.ts +4 -2
  46. package/esm/oas/schema/siblings.d.ts +10 -2
  47. package/esm/oas/schema/siblings.js +87 -22
  48. package/esm/oas/schemaPath/traverseSchema.d.ts +2 -0
  49. package/esm/oas/schemaPath/traverseSchema.js +51 -5
  50. package/esm/parse/allOfSystem.d.ts +3 -0
  51. package/esm/parse/allOfSystem.js +2 -1
  52. package/esm/parse/keptIntersection.d.ts +53 -0
  53. package/esm/parse/keptIntersection.js +155 -0
  54. package/esm/parse/keptRefs.d.ts +23 -0
  55. package/esm/parse/keptRefs.js +59 -0
  56. package/esm/parse/toCyclicRefs.d.ts +8 -0
  57. package/esm/parse/toCyclicRefs.js +126 -0
  58. package/esm/parse/toDeclaredTypes.d.ts +20 -0
  59. package/esm/parse/toDeclaredTypes.js +43 -0
  60. package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
  61. package/esm/parse/v3-0/_merge-all-of/merge-union.js +7 -1
  62. package/esm/parse/v3-0/_merge-all-of/merge.js +13 -0
  63. package/esm/parse/v3-0/_merge-all-of/types.d.ts +3 -0
  64. package/esm/parse/v3-0/intersection/toIntersection.d.ts +12 -0
  65. package/esm/parse/v3-0/intersection/toIntersection.js +61 -0
  66. package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  67. package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
  68. package/esm/parse/v3-0/schema/toSchemasV3.js +13 -1
  69. package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
  70. package/esm/parse/v3-1/_merge-all-of/merge-union.js +7 -1
  71. package/esm/parse/v3-1/_merge-all-of/merge.js +13 -0
  72. package/esm/parse/v3-1/_merge-all-of/types.d.ts +3 -0
  73. package/esm/parse/v3-1/intersection/toIntersection.d.ts +12 -0
  74. package/esm/parse/v3-1/intersection/toIntersection.js +61 -0
  75. package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  76. package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
  77. package/esm/parse/v3-1/schema/toSchemasV3.js +15 -2
  78. package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
  79. package/esm/parse/v3-2/_merge-all-of/merge-union.js +7 -1
  80. package/esm/parse/v3-2/_merge-all-of/merge.js +13 -0
  81. package/esm/parse/v3-2/_merge-all-of/types.d.ts +3 -0
  82. package/esm/parse/v3-2/intersection/toIntersection.d.ts +12 -0
  83. package/esm/parse/v3-2/intersection/toIntersection.js +61 -0
  84. package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  85. package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
  86. package/esm/parse/v3-2/schema/toSchemasV3.js +15 -2
  87. package/esm/types/GeneratorType.d.ts +1 -1
  88. package/esm/types/ProjectionOptions.d.ts +1 -1
  89. package/esm/types/ProjectionOptions.js +1 -1
  90. package/esm/types/RefName.d.ts +3 -3
  91. package/esm/types/Settings.d.ts +9 -0
  92. package/esm/types/Settings.js +2 -1
  93. package/esm/types/TypeSystem.d.ts +20 -5
  94. package/package.json +1 -1
  95. package/script/anchors/attribute.js +3 -2
  96. package/script/context/CoreContext.d.ts +1 -1
  97. package/script/context/CoreContext.js +1 -1
  98. package/script/context/GenerateContext.d.ts +13 -10
  99. package/script/context/GenerateContext.js +36 -25
  100. package/script/context/ParseContext.d.ts +3 -0
  101. package/script/context/ParseContext.js +150 -38
  102. package/script/context/generateTypes.d.ts +7 -6
  103. package/script/dsl/GeneratorKeys.d.ts +21 -15
  104. package/script/dsl/GeneratorKeys.js +16 -11
  105. package/script/dsl/Inserted.d.ts +1 -1
  106. package/script/dsl/Inserted.js +1 -1
  107. package/script/dsl/model/ModelDriver.d.ts +6 -5
  108. package/script/dsl/model/ModelDriver.js +22 -20
  109. package/script/dsl/model/toModelEntry.d.ts +18 -18
  110. package/script/dsl/model/toModelEntry.js +9 -9
  111. package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
  112. package/script/dsl/model/toModelProjectionBase.js +12 -8
  113. package/script/dsl/model/types.d.ts +26 -17
  114. package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  115. package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  116. package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  117. package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  118. package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  119. package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
  120. package/script/helpers/collateExamples.js +35 -17
  121. package/script/helpers/refFns.d.ts +108 -43
  122. package/script/helpers/refFns.js +180 -59
  123. package/script/mod.d.ts +1 -0
  124. package/script/mod.js +1 -0
  125. package/script/oas/document/Document.d.ts +6 -0
  126. package/script/oas/document/Document.js +44 -2
  127. package/script/oas/intersection/Intersection.d.ts +122 -0
  128. package/script/oas/intersection/Intersection.js +270 -0
  129. package/script/oas/mediaType/jsonMediaType.d.ts +1 -1
  130. package/script/oas/mediaType/jsonMediaType.js +3 -3
  131. package/script/oas/ref/DanglingRefError.d.ts +5 -2
  132. package/script/oas/ref/DanglingRefError.js +4 -3
  133. package/script/oas/ref/Ref.d.ts +23 -12
  134. package/script/oas/ref/Ref.js +67 -71
  135. package/script/oas/requestBody/RequestBody.d.ts +1 -1
  136. package/script/oas/requestBody/RequestBody.js +1 -1
  137. package/script/oas/response/Response.d.ts +1 -1
  138. package/script/oas/response/Response.js +1 -1
  139. package/script/oas/schema/Schema.d.ts +4 -2
  140. package/script/oas/schema/siblings.d.ts +10 -2
  141. package/script/oas/schema/siblings.js +89 -23
  142. package/script/oas/schemaPath/traverseSchema.d.ts +2 -0
  143. package/script/oas/schemaPath/traverseSchema.js +50 -4
  144. package/script/parse/allOfSystem.d.ts +3 -0
  145. package/script/parse/allOfSystem.js +2 -1
  146. package/script/parse/keptIntersection.d.ts +53 -0
  147. package/script/parse/keptIntersection.js +164 -0
  148. package/script/parse/keptRefs.d.ts +23 -0
  149. package/script/parse/keptRefs.js +63 -0
  150. package/script/parse/toCyclicRefs.d.ts +8 -0
  151. package/script/parse/toCyclicRefs.js +130 -0
  152. package/script/parse/toDeclaredTypes.d.ts +20 -0
  153. package/script/parse/toDeclaredTypes.js +48 -0
  154. package/script/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
  155. package/script/parse/v3-0/_merge-all-of/merge-union.js +7 -1
  156. package/script/parse/v3-0/_merge-all-of/merge.js +13 -0
  157. package/script/parse/v3-0/_merge-all-of/types.d.ts +3 -0
  158. package/script/parse/v3-0/intersection/toIntersection.d.ts +12 -0
  159. package/script/parse/v3-0/intersection/toIntersection.js +65 -0
  160. package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  161. package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
  162. package/script/parse/v3-0/schema/toSchemasV3.js +13 -1
  163. package/script/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
  164. package/script/parse/v3-1/_merge-all-of/merge-union.js +7 -1
  165. package/script/parse/v3-1/_merge-all-of/merge.js +13 -0
  166. package/script/parse/v3-1/_merge-all-of/types.d.ts +3 -0
  167. package/script/parse/v3-1/intersection/toIntersection.d.ts +12 -0
  168. package/script/parse/v3-1/intersection/toIntersection.js +65 -0
  169. package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  170. package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
  171. package/script/parse/v3-1/schema/toSchemasV3.js +15 -2
  172. package/script/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
  173. package/script/parse/v3-2/_merge-all-of/merge-union.js +7 -1
  174. package/script/parse/v3-2/_merge-all-of/merge.js +13 -0
  175. package/script/parse/v3-2/_merge-all-of/types.d.ts +3 -0
  176. package/script/parse/v3-2/intersection/toIntersection.d.ts +12 -0
  177. package/script/parse/v3-2/intersection/toIntersection.js +65 -0
  178. package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  179. package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
  180. package/script/parse/v3-2/schema/toSchemasV3.js +15 -2
  181. package/script/types/GeneratorType.d.ts +1 -1
  182. package/script/types/ProjectionOptions.d.ts +1 -1
  183. package/script/types/ProjectionOptions.js +1 -1
  184. package/script/types/RefName.d.ts +3 -3
  185. package/script/types/Settings.d.ts +9 -0
  186. package/script/types/Settings.js +2 -1
  187. package/script/types/TypeSystem.d.ts +20 -5
@@ -0,0 +1,122 @@
1
+ import type { OasUnknown } from '../unknown/Unknown.js';
2
+ import type { SchemaPath } from '../../types/SchemaPath.js';
3
+ import type { OasExternalDocs } from '../externalDocs/ExternalDocs.js';
4
+ import type { OasSchema, ToJsonSchemaOptions } from '../schema/Schema.js';
5
+ import type { OasRef } from '../ref/Ref.js';
6
+ import type { OpenAPIV3 } from 'openapi-types';
7
+ import { OasBase } from '../../types/OasBase.js';
8
+ import type { ParseContextType } from '../../context/parseTypes.js';
9
+ /**
10
+ * Constructor fields for {@link OasIntersection}.
11
+ */
12
+ export type IntersectionFields = {
13
+ /** A short summary of the intersection */
14
+ title?: string;
15
+ /** A description of the intersection */
16
+ description?: string;
17
+ /** External documentation for the intersection */
18
+ externalDocs?: OasExternalDocs | undefined;
19
+ /** Whether the value can be null */
20
+ nullable?: boolean;
21
+ /** Whether the value is sent by the API only */
22
+ readOnly?: boolean;
23
+ /** Whether the value is sent in a request only */
24
+ writeOnly?: boolean;
25
+ /** Whether the value is deprecated */
26
+ deprecated?: boolean;
27
+ /** Example value */
28
+ example?: unknown;
29
+ /** Default value */
30
+ default?: unknown;
31
+ /** The schemas a value matches all of */
32
+ members: (OasSchema | OasRef<'schema'>)[];
33
+ /** Custom extension fields (x-* properties) */
34
+ extensionFields?: Record<string, unknown>;
35
+ };
36
+ /**
37
+ * An `allOf` that keeps at least one reference: a value matches every member.
38
+ *
39
+ * Core merges the members of an `allOf` into one schema. A reference that
40
+ * `client.json` `system.intersections` keeps is not merged: the schema is an
41
+ * `OasIntersection` of the kept references, and at most one other member, which
42
+ * the other members of the `allOf` merge into. By default those are the
43
+ * references that close a cycle.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // LineString: { allOf: [{ $ref: Geometry }, { properties: { coordinates } }] },
48
+ * // where a property of Geometry leads back to LineString
49
+ * lineString.members // [OasRef Geometry, OasObject { coordinates }]
50
+ * ```
51
+ */
52
+ export declare class OasIntersection extends OasBase {
53
+ #private;
54
+ /**
55
+ * Object is part the 'schema' set which is used
56
+ * to define data types in an OpenAPI document.
57
+ */
58
+ oasType: "schema";
59
+ /**
60
+ * Constant value 'intersection' useful for type narrowing and tagged unions.
61
+ */
62
+ type: "intersection";
63
+ /** A short summary of the intersection. */
64
+ title: string | undefined;
65
+ /** A description of the intersection. */
66
+ description: string | undefined;
67
+ /** External documentation for the intersection. */
68
+ externalDocs: OasExternalDocs | undefined;
69
+ /** Indicates whether the value can be null. */
70
+ nullable: boolean | undefined;
71
+ /** Whether the value is sent by the API only. */
72
+ readOnly: boolean | undefined;
73
+ /** Whether the value is sent in a request only. */
74
+ writeOnly: boolean | undefined;
75
+ /** Whether the value is deprecated. */
76
+ deprecated: boolean | undefined;
77
+ /** The schemas, or references to schemas, that a value matches all of. */
78
+ members: (OasSchema | OasRef<'schema'>)[];
79
+ /** Specification Extension fields */
80
+ extensionFields: Record<string, unknown> | undefined;
81
+ /** An example of the value. */
82
+ example?: unknown;
83
+ /** The default value. */
84
+ default?: unknown;
85
+ /**
86
+ * The schema's `not`, kept as an `OasUnknown` under `client.json`
87
+ * `system.not: unknown`. `undefined` otherwise.
88
+ */
89
+ not: OasUnknown | undefined;
90
+ constructor(fields: IntersectionFields, context?: ParseContextType);
91
+ isRef(): this is OasRef<'schema'>;
92
+ /** Whether the value is `readOnly`: the intersection or one of its members is. */
93
+ isReadOnly(): boolean;
94
+ /** Whether the value is `writeOnly`: the intersection or one of its members is. */
95
+ isWriteOnly(): boolean;
96
+ /**
97
+ * The schemas a value matches all of, with each reference resolved and each
98
+ * intersection inside replaced by its own members. Each is given once, so a
99
+ * member that leads back to an intersection ends. A reference that names
100
+ * nothing is left out.
101
+ */
102
+ toParts(): Exclude<OasSchema, OasIntersection>[];
103
+ /**
104
+ * {@link toParts} without the keywords next to the references. `clone` reads
105
+ * these while a reference to this intersection resolves, so no reference may
106
+ * be resolved with its keywords here.
107
+ */
108
+ toTargetParts(): Exclude<OasSchema, OasIntersection>[];
109
+ /**
110
+ * A copy of this schema with what `ref` adds at its site applied, as
111
+ * {@link OasUnion.clone} does: the keywords that this type takes, a
112
+ * sibling's value winning. The keywords of an object next to `ref`
113
+ * (`properties`, `required`) are one more member, unless the members say
114
+ * the same. This schema does not
115
+ * change, and the copy shares its members.
116
+ */
117
+ clone(ref?: OasRef<'schema'>): OasIntersection;
118
+ traverse(path: SchemaPath): OasSchema | OasRef<'schema'>;
119
+ resolve(): OasIntersection;
120
+ resolveOnce(): OasIntersection;
121
+ toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.NonArraySchemaObject;
122
+ }
@@ -0,0 +1,266 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _OasIntersection_instances, _OasIntersection_toMembersInside;
7
+ import { traverseSchema } from '../schemaPath/traverseSchema.js';
8
+ import { OasObject } from '../object/Object.js';
9
+ import { toChangedObjectKeywords, toSiblingAnnotations } from '../schema/siblings.js';
10
+ import { OasBase } from '../../types/OasBase.js';
11
+ import { DanglingRefError } from '../ref/DanglingRefError.js';
12
+ /**
13
+ * An `allOf` that keeps at least one reference: a value matches every member.
14
+ *
15
+ * Core merges the members of an `allOf` into one schema. A reference that
16
+ * `client.json` `system.intersections` keeps is not merged: the schema is an
17
+ * `OasIntersection` of the kept references, and at most one other member, which
18
+ * the other members of the `allOf` merge into. By default those are the
19
+ * references that close a cycle.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // LineString: { allOf: [{ $ref: Geometry }, { properties: { coordinates } }] },
24
+ * // where a property of Geometry leads back to LineString
25
+ * lineString.members // [OasRef Geometry, OasObject { coordinates }]
26
+ * ```
27
+ */
28
+ export class OasIntersection extends OasBase {
29
+ constructor(fields, context) {
30
+ super(context);
31
+ _OasIntersection_instances.add(this);
32
+ /**
33
+ * Object is part the 'schema' set which is used
34
+ * to define data types in an OpenAPI document.
35
+ */
36
+ Object.defineProperty(this, "oasType", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: 'schema'
41
+ });
42
+ /**
43
+ * Constant value 'intersection' useful for type narrowing and tagged unions.
44
+ */
45
+ Object.defineProperty(this, "type", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: 'intersection'
50
+ });
51
+ /** A short summary of the intersection. */
52
+ Object.defineProperty(this, "title", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: void 0
57
+ });
58
+ /** A description of the intersection. */
59
+ Object.defineProperty(this, "description", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ /** External documentation for the intersection. */
66
+ Object.defineProperty(this, "externalDocs", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ /** Indicates whether the value can be null. */
73
+ Object.defineProperty(this, "nullable", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+ /** Whether the value is sent by the API only. */
80
+ Object.defineProperty(this, "readOnly", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
86
+ /** Whether the value is sent in a request only. */
87
+ Object.defineProperty(this, "writeOnly", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
93
+ /** Whether the value is deprecated. */
94
+ Object.defineProperty(this, "deprecated", {
95
+ enumerable: true,
96
+ configurable: true,
97
+ writable: true,
98
+ value: void 0
99
+ });
100
+ /** The schemas, or references to schemas, that a value matches all of. */
101
+ Object.defineProperty(this, "members", {
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true,
105
+ value: void 0
106
+ });
107
+ /** Specification Extension fields */
108
+ Object.defineProperty(this, "extensionFields", {
109
+ enumerable: true,
110
+ configurable: true,
111
+ writable: true,
112
+ value: void 0
113
+ });
114
+ /** An example of the value. */
115
+ Object.defineProperty(this, "example", {
116
+ enumerable: true,
117
+ configurable: true,
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+ /** The default value. */
122
+ Object.defineProperty(this, "default", {
123
+ enumerable: true,
124
+ configurable: true,
125
+ writable: true,
126
+ value: void 0
127
+ });
128
+ /**
129
+ * The schema's `not`, kept as an `OasUnknown` under `client.json`
130
+ * `system.not: unknown`. `undefined` otherwise.
131
+ */
132
+ Object.defineProperty(this, "not", {
133
+ enumerable: true,
134
+ configurable: true,
135
+ writable: true,
136
+ value: undefined
137
+ });
138
+ this.title = fields.title;
139
+ this.description = fields.description;
140
+ this.externalDocs = fields.externalDocs;
141
+ this.nullable = fields.nullable;
142
+ this.readOnly = fields.readOnly;
143
+ this.writeOnly = fields.writeOnly;
144
+ this.deprecated = fields.deprecated;
145
+ this.members = fields.members;
146
+ this.extensionFields = fields.extensionFields;
147
+ this.example = fields.example;
148
+ this.default = fields.default;
149
+ }
150
+ isRef() {
151
+ return false;
152
+ }
153
+ /** Whether the value is `readOnly`: the intersection or one of its members is. */
154
+ isReadOnly() {
155
+ return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this).some(member => member.isRef() || member.type === 'intersection' ? member.readOnly === true : member.isReadOnly());
156
+ }
157
+ /** Whether the value is `writeOnly`: the intersection or one of its members is. */
158
+ isWriteOnly() {
159
+ return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this).some(member => member.isRef() || member.type === 'intersection' ? member.writeOnly === true : member.isWriteOnly());
160
+ }
161
+ /**
162
+ * The schemas a value matches all of, with each reference resolved and each
163
+ * intersection inside replaced by its own members. Each is given once, so a
164
+ * member that leads back to an intersection ends. A reference that names
165
+ * nothing is left out.
166
+ */
167
+ toParts() {
168
+ return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this).filter(isPart);
169
+ }
170
+ /**
171
+ * {@link toParts} without the keywords next to the references. `clone` reads
172
+ * these while a reference to this intersection resolves, so no reference may
173
+ * be resolved with its keywords here.
174
+ */
175
+ toTargetParts() {
176
+ return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this, ref => ref.resolveOnce()).filter(isPart);
177
+ }
178
+ /**
179
+ * A copy of this schema with what `ref` adds at its site applied, as
180
+ * {@link OasUnion.clone} does: the keywords that this type takes, a
181
+ * sibling's value winning. The keywords of an object next to `ref`
182
+ * (`properties`, `required`) are one more member, unless the members say
183
+ * the same. This schema does not
184
+ * change, and the copy shares its members.
185
+ */
186
+ clone(ref) {
187
+ const copy = new OasIntersection({
188
+ ...toSiblingAnnotations(this, ref),
189
+ example: ref?.example ?? this.example,
190
+ externalDocs: this.externalDocs,
191
+ nullable: this.nullable || ref?.nullable || undefined,
192
+ readOnly: this.readOnly || ref?.readOnly || undefined,
193
+ writeOnly: this.writeOnly || ref?.writeOnly || undefined,
194
+ deprecated: ref?.deprecated ?? this.deprecated,
195
+ members: ref !== undefined && toChangedObjectKeywords(this, ref).length > 0 ? [...this.members, toSiblingMember(ref)] : this.members,
196
+ default: ref?.default ?? this.default
197
+ });
198
+ copy.stackTrail = this.stackTrail;
199
+ copy.not = this.not;
200
+ return copy;
201
+ }
202
+ traverse(path) {
203
+ return traverseSchema(this, path);
204
+ }
205
+ resolve() {
206
+ return this;
207
+ }
208
+ resolveOnce() {
209
+ return this;
210
+ }
211
+ toJsonSchema(options) {
212
+ return {
213
+ title: this.title,
214
+ description: this.description,
215
+ nullable: this.nullable,
216
+ readOnly: this.readOnly,
217
+ writeOnly: this.writeOnly,
218
+ deprecated: this.deprecated,
219
+ example: this.example,
220
+ default: this.default,
221
+ allOf: this.members.map(member => member.toJsonSchema(options))
222
+ };
223
+ }
224
+ }
225
+ _OasIntersection_instances = new WeakSet(), _OasIntersection_toMembersInside = function _OasIntersection_toMembersInside(follow = ref => ref.resolve()) {
226
+ const found = new Set();
227
+ const visit = (item) => {
228
+ if (item === undefined || found.has(item)) {
229
+ return;
230
+ }
231
+ found.add(item);
232
+ if (item.isRef()) {
233
+ visit(toTarget(() => follow(item)));
234
+ }
235
+ else if (item.type === 'intersection') {
236
+ item.members.forEach(visit);
237
+ }
238
+ };
239
+ visit(this);
240
+ return [...found];
241
+ };
242
+ /** The keywords of an object next to a reference, as an object. */
243
+ const toSiblingMember = (ref) => {
244
+ const member = new OasObject({
245
+ properties: ref.properties,
246
+ required: ref.required,
247
+ additionalProperties: ref.additionalProperties,
248
+ minProperties: ref.minProperties,
249
+ maxProperties: ref.maxProperties
250
+ });
251
+ member.stackTrail = ref.stackTrail;
252
+ return member;
253
+ };
254
+ const isPart = (member) => !member.isRef() && member.type !== 'intersection';
255
+ /** What following a reference gives, or `undefined` when it names nothing. */
256
+ const toTarget = (follow) => {
257
+ try {
258
+ return follow();
259
+ }
260
+ catch (error) {
261
+ if (DanglingRefError.is(error)) {
262
+ return undefined;
263
+ }
264
+ throw error;
265
+ }
266
+ };
@@ -40,7 +40,7 @@ export type JsonContent = {
40
40
  * Choose the media type a body is read from: `application/json` exactly when
41
41
  * it is a key, else the first JSON-like key in document order (see
42
42
  * {@link isJsonMediaType}), else the `*\/*` key when its schema is an object,
43
- * array, union or `$ref`. `*\/*` admits JSON, and documents use it for JSON
43
+ * array, union, intersection or `$ref`. `*\/*` admits JSON, and documents use it for JSON
44
44
  * bodies (springdoc writes it for every response); the parser logs
45
45
  * `WILDCARD_MEDIA_TYPE` for every body read this way. `undefined` otherwise:
46
46
  * there is no fall back to a specific non-JSON type, to a narrower range such
@@ -27,16 +27,16 @@ export const isJsonMediaType = (mediaType) => {
27
27
  export const isAnyMediaType = (mediaType) => toMediaTypeEssence(mediaType) === '*/*';
28
28
  /**
29
29
  * True when a schema under `*\/*` can be read as one JSON value: an object,
30
- * array, union or `$ref`. A scalar is not: under `*\/*` a `string` is usually
30
+ * array, union, intersection or `$ref`. A scalar is not: under `*\/*` a `string` is usually
31
31
  * a text body, and `string` with `format: binary` a file.
32
32
  */
33
33
  const isJsonShaped = (schema) => schema !== undefined &&
34
- (schema.isRef() || schema.type === 'object' || schema.type === 'array' || schema.type === 'union');
34
+ (schema.isRef() || ['object', 'array', 'union', 'intersection'].includes(schema.type));
35
35
  /**
36
36
  * Choose the media type a body is read from: `application/json` exactly when
37
37
  * it is a key, else the first JSON-like key in document order (see
38
38
  * {@link isJsonMediaType}), else the `*\/*` key when its schema is an object,
39
- * array, union or `$ref`. `*\/*` admits JSON, and documents use it for JSON
39
+ * array, union, intersection or `$ref`. `*\/*` admits JSON, and documents use it for JSON
40
40
  * bodies (springdoc writes it for every response); the parser logs
41
41
  * `WILDCARD_MEDIA_TYPE` for every body read this way. `undefined` otherwise:
42
42
  * there is no fall back to a specific non-JSON type, to a narrower range such
@@ -7,10 +7,13 @@ type DanglingRefErrorOptions = {
7
7
  * `['#/components/schemas/B', '#/components/schemas/A']`.
8
8
  */
9
9
  loop?: string[];
10
+ /** The `$ref` points outside the document, which core does not fetch. */
11
+ remote?: boolean;
10
12
  };
11
13
  /**
12
14
  * Thrown when a reference that names nothing in the document is resolved:
13
- * no component has its name, or its chain of `$ref`s comes back to one it
15
+ * no component has its name, it points outside the document (core does not
16
+ * fetch), or its chain of `$ref`s comes back to one it
14
17
  * has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
15
18
  * component.
16
19
  *
@@ -25,7 +28,7 @@ export declare class DanglingRefError extends Error {
25
28
  ref: string;
26
29
  /** When the chain of `$ref`s loops: see {@link DanglingRefErrorOptions.loop}. */
27
30
  loop: string[] | undefined;
28
- constructor(ref: string, { loop }?: DanglingRefErrorOptions);
31
+ constructor(ref: string, { loop, remote }?: DanglingRefErrorOptions);
29
32
  /**
30
33
  * True when `error` is a `DanglingRefError`. It reads the error's name,
31
34
  * not its class, so it is also true for one thrown by another copy of
@@ -1,7 +1,8 @@
1
1
  import "../../_dnt.polyfills.js";
2
2
  /**
3
3
  * Thrown when a reference that names nothing in the document is resolved:
4
- * no component has its name, or its chain of `$ref`s comes back to one it
4
+ * no component has its name, it points outside the document (core does not
5
+ * fetch), or its chain of `$ref`s comes back to one it
5
6
  * has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
6
7
  * component.
7
8
  *
@@ -12,9 +13,9 @@ import "../../_dnt.polyfills.js";
12
13
  * {@link DanglingRefError.is}, not `instanceof`.
13
14
  */
14
15
  export class DanglingRefError extends Error {
15
- constructor(ref, { loop } = {}) {
16
+ constructor(ref, { loop, remote = false } = {}) {
16
17
  super(loop === undefined
17
- ? `Ref "${ref}" names nothing in the document`
18
+ ? `Ref "${ref}" ${remote ? 'points outside the document; bundle the files into one document first' : 'names nothing in the document'}`
18
19
  : `Ref "${ref}" leads into a loop of $refs (${[...loop, ...loop.slice(0, 1)].join(' → ')}) and never reaches a component`);
19
20
  /** The `$ref`, or the component name, that names nothing. */
20
21
  Object.defineProperty(this, "ref", {
@@ -92,8 +92,8 @@ export type RefFields<T extends OasRefData['refType']> = SiblingKeywords & {
92
92
  * function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
93
93
  * if (schema.isRef()) {
94
94
  * // Handle reference
95
- * const refName = schema.toRefName();
96
- * console.log(`Processing reference: ${refName}`);
95
+ * const { refName, refPath } = schema;
96
+ * console.log(`Processing reference: ${refName} in ${refPath}`);
97
97
  *
98
98
  * // Resolve only when needed
99
99
  * const resolved = schema.resolve();
@@ -128,8 +128,25 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
128
128
  type: 'ref';
129
129
  /** The kind of component the reference points to. */
130
130
  refType: T;
131
- /** The JSON Reference: `#/components/<bucket>/<name>`. */
131
+ /**
132
+ * The JSON Reference, as written: a component (`#/components/<bucket>/<name>`)
133
+ * or any other place in the document (`#/components/schemas/Pet/properties/tag`).
134
+ */
132
135
  $ref: string;
136
+ /**
137
+ * The last segment of the `$ref`'s pointer, unescaped: `Pet` for
138
+ * `#/components/schemas/Pet`, `schema0` for
139
+ * `#/components/schemas/__sharedInput/$defs/schema0`. Empty for a `$ref`
140
+ * that ends in `/`, which names nothing.
141
+ */
142
+ refName: RefName;
143
+ /**
144
+ * The pointer before {@link refName}, with no percent escapes: `#/components/schemas`
145
+ * for a schema component, `#/components/schemas/__sharedInput/$defs` for
146
+ * the `$defs` entry above. A generator that names by {@link refName} alone
147
+ * may ignore it.
148
+ */
149
+ refPath: string;
133
150
  /**
134
151
  * Use-site nullability (see {@link SiblingKeywords.nullable}). Assigned
135
152
  * even when `undefined`, so `'nullable' in ref` is always true and the
@@ -241,8 +258,9 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
241
258
  toLoop(): OasRef<T>[] | undefined;
242
259
  /**
243
260
  * Resolves this reference one level. Dispatches on the document's
244
- * protocol — OAS reads from `document.components.<bucket>`; GQL
245
- * reads from `document.registry.schemas`.
261
+ * protocol — OAS reads a component from `document.components.<bucket>`,
262
+ * and any other target from the targets the parser kept by pointer
263
+ * (`OasDocument.toRefTarget`); GQL reads from `document.registry.schemas`.
246
264
  *
247
265
  * @returns Either the resolved component or another reference in the chain
248
266
  * @throws {DanglingRefError} when the reference names nothing in the
@@ -252,13 +270,6 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
252
270
  * `requestBody` ref to `#/components/schemas/…`
253
271
  */
254
272
  resolveOnce(): OasRef<T> | ResolvedRef<T>;
255
- /**
256
- * The component name the reference looks up.
257
- *
258
- * @throws {DanglingRefError} when the `$ref` has no name, such as
259
- * `#/components/schemas/`: it names nothing
260
- */
261
- toRefName(): RefName;
262
273
  /**
263
274
  * Narrows this reference to a schema reference.
264
275
  *