@skmtc/core 0.40.0 → 0.41.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 (77) hide show
  1. package/esm/context/GenerateContext.d.ts +1 -1
  2. package/esm/context/GenerateContext.js +4 -3
  3. package/esm/context/ParseContext.d.ts +9 -0
  4. package/esm/context/ParseContext.js +90 -2
  5. package/esm/context/generateTypes.d.ts +16 -2
  6. package/esm/context/generateTypes.js +2 -0
  7. package/esm/context/tryParseAt.d.ts +4 -1
  8. package/esm/context/tryParseAt.js +10 -3
  9. package/esm/helpers/collateExamples.js +15 -5
  10. package/esm/helpers/refFns.d.ts +6 -2
  11. package/esm/helpers/refFns.js +24 -7
  12. package/esm/mod.d.ts +1 -0
  13. package/esm/mod.js +1 -0
  14. package/esm/oas/operation/Operation.d.ts +4 -1
  15. package/esm/oas/operation/Operation.js +6 -5
  16. package/esm/oas/operation/toEffectiveParameters.d.ts +8 -0
  17. package/esm/oas/operation/toEffectiveParameters.js +32 -3
  18. package/esm/oas/ref/DanglingRefError.d.ts +22 -0
  19. package/esm/oas/ref/DanglingRefError.js +33 -0
  20. package/esm/oas/ref/Ref.d.ts +5 -0
  21. package/esm/oas/ref/Ref.js +28 -2
  22. package/esm/oas/schema/siblings.js +12 -2
  23. package/esm/oas/union/Union.d.ts +2 -1
  24. package/esm/oas/union/Union.js +23 -12
  25. package/esm/oas/webhook/Webhook.js +2 -4
  26. package/esm/parse/securityRequirements.d.ts +6 -0
  27. package/esm/parse/securityRequirements.js +8 -0
  28. package/esm/parse/v3-0/mediaType/toMediaTypeItemV3.js +4 -3
  29. package/esm/parse/v3-0/parameter/toParameterV3.js +4 -3
  30. package/esm/parse/v3-0/ref/toRefV31.js +5 -2
  31. package/esm/parse/v3-1/mediaType/toMediaTypeItemV3.js +4 -3
  32. package/esm/parse/v3-1/parameter/toParameterV3.js +4 -3
  33. package/esm/parse/v3-1/ref/toRefV31.js +5 -2
  34. package/esm/parse/v3-2/mediaType/toMediaTypeItemV3.js +4 -3
  35. package/esm/parse/v3-2/parameter/toParameterV3.js +4 -3
  36. package/esm/parse/v3-2/ref/toRefV31.js +5 -2
  37. package/esm/types/Settings.d.ts +10 -0
  38. package/esm/types/Settings.js +2 -1
  39. package/package.json +5 -1
  40. package/script/context/GenerateContext.d.ts +1 -1
  41. package/script/context/GenerateContext.js +4 -3
  42. package/script/context/ParseContext.d.ts +9 -0
  43. package/script/context/ParseContext.js +90 -2
  44. package/script/context/generateTypes.d.ts +16 -2
  45. package/script/context/generateTypes.js +2 -0
  46. package/script/context/tryParseAt.d.ts +4 -1
  47. package/script/context/tryParseAt.js +10 -3
  48. package/script/helpers/collateExamples.js +15 -5
  49. package/script/helpers/refFns.d.ts +6 -2
  50. package/script/helpers/refFns.js +24 -7
  51. package/script/mod.d.ts +1 -0
  52. package/script/mod.js +1 -0
  53. package/script/oas/operation/Operation.d.ts +4 -1
  54. package/script/oas/operation/Operation.js +5 -4
  55. package/script/oas/operation/toEffectiveParameters.d.ts +8 -0
  56. package/script/oas/operation/toEffectiveParameters.js +34 -4
  57. package/script/oas/ref/DanglingRefError.d.ts +22 -0
  58. package/script/oas/ref/DanglingRefError.js +37 -0
  59. package/script/oas/ref/Ref.d.ts +5 -0
  60. package/script/oas/ref/Ref.js +28 -2
  61. package/script/oas/schema/siblings.js +12 -2
  62. package/script/oas/union/Union.d.ts +2 -1
  63. package/script/oas/union/Union.js +23 -12
  64. package/script/oas/webhook/Webhook.js +1 -3
  65. package/script/parse/securityRequirements.d.ts +6 -0
  66. package/script/parse/securityRequirements.js +8 -0
  67. package/script/parse/v3-0/mediaType/toMediaTypeItemV3.js +4 -3
  68. package/script/parse/v3-0/parameter/toParameterV3.js +4 -3
  69. package/script/parse/v3-0/ref/toRefV31.js +5 -2
  70. package/script/parse/v3-1/mediaType/toMediaTypeItemV3.js +4 -3
  71. package/script/parse/v3-1/parameter/toParameterV3.js +4 -3
  72. package/script/parse/v3-1/ref/toRefV31.js +5 -2
  73. package/script/parse/v3-2/mediaType/toMediaTypeItemV3.js +4 -3
  74. package/script/parse/v3-2/parameter/toParameterV3.js +4 -3
  75. package/script/parse/v3-2/ref/toRefV31.js +5 -2
  76. package/script/types/Settings.d.ts +10 -0
  77. package/script/types/Settings.js +2 -1
@@ -112,6 +112,12 @@ exports.toSecurityCheck = toSecurityCheck;
112
112
  * failed to parse or is not defined, or that has no `security` and
113
113
  * inherits an unusable root. Each dropped item logs one `INVALID_OPERATION`
114
114
  * error on its own trail. `security: []` inherits nothing and is kept.
115
+ *
116
+ * A kept item depends on each scheme its security names (its own, else the
117
+ * root's), as it would on a `$ref` to it, so it is registered as a consumer
118
+ * of the scheme. When the parser removes the scheme later (one that is a
119
+ * `$ref` that names nothing), the item goes with it, and so is never kept
120
+ * without its auth.
115
121
  */
116
122
  const toOperationsWithValidSecurity = ({ items, check }) => {
117
123
  return items.filter(item => {
@@ -119,6 +125,8 @@ const toOperationsWithValidSecurity = ({ items, check }) => {
119
125
  ? toSchemeProblems(item.security, check).map(capitalize).join('. ') || undefined
120
126
  : check.rootProblem;
121
127
  if (message === undefined) {
128
+ const names = (item.security ?? check.rootSecurity ?? []).flatMap(({ requirement }) => Object.keys(requirement));
129
+ new Set(names).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
122
130
  return true;
123
131
  }
124
132
  check.context.logIssueNoKey({
@@ -120,13 +120,14 @@ const toMediaTypeItemV3 = ({ mediaTypeItem, mediaType, stackTrail, context }) =>
120
120
  mediaType,
121
121
  encoding,
122
122
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
123
- examples: stackTrail.trace('examples', st => (0, toExamplesV3_js_1.toExamplesV3)({
123
+ // toExamplesV3 traces `examples` (or `example`) itself.
124
+ examples: (0, toExamplesV3_js_1.toExamplesV3)({
124
125
  example,
125
126
  examples,
126
127
  exampleKey: mediaType,
127
- stackTrail: st,
128
+ stackTrail,
128
129
  context
129
- })),
130
+ }),
130
131
  extensionFields
131
132
  };
132
133
  return context.withStackTrail(stackTrail, () => new MediaType_js_1.OasMediaType(fields, context));
@@ -141,13 +141,14 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
141
141
  allowEmptyValue,
142
142
  allowReserved,
143
143
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
144
- examples: stackTrail.trace('examples', st => (0, toExamplesV3_js_1.toExamplesV3)({
144
+ // toExamplesV3 traces `examples` (or `example`) itself.
145
+ examples: (0, toExamplesV3_js_1.toExamplesV3)({
145
146
  examples,
146
147
  example,
147
148
  exampleKey: `${name}-${parsedLocation}`,
148
- stackTrail: st,
149
+ stackTrail,
149
150
  context
150
- })),
151
+ }),
151
152
  content: stackTrail.trace('content', st => (0, toMediaTypeItemV3_js_1.toOptionalMediaTypeItemsV3)({ content, stackTrail: st, context })),
152
153
  extensionFields
153
154
  };
@@ -8,7 +8,10 @@ const toRefV31 = ({ ref, refType, stackTrail, context, nullable, readOnly, write
8
8
  if (!(0, isEmpty_js_1.isEmpty)(skipped)) {
9
9
  context.logSkippedFields({ skipped, parent: ref, parentType: 'ref', stackTrail });
10
10
  }
11
- context.registerRef(stackTrail.clone(), $ref);
12
- return context.withStackTrail(stackTrail, () => new Ref_js_1.OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
11
+ const oasRef = context.withStackTrail(stackTrail, () => new Ref_js_1.OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
12
+ // The parse context checks each ref once the document is parsed, and
13
+ // removes what holds a ref that names nothing (`system.danglingRefs`).
14
+ context.registerOasRef(stackTrail.clone(), oasRef);
15
+ return oasRef;
13
16
  };
14
17
  exports.toRefV31 = toRefV31;
@@ -120,13 +120,14 @@ const toMediaTypeItemV3 = ({ mediaTypeItem, mediaType, stackTrail, context }) =>
120
120
  mediaType,
121
121
  encoding,
122
122
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
123
- examples: stackTrail.trace('examples', st => (0, toExamplesV3_js_1.toExamplesV3)({
123
+ // toExamplesV3 traces `examples` (or `example`) itself.
124
+ examples: (0, toExamplesV3_js_1.toExamplesV3)({
124
125
  example,
125
126
  examples,
126
127
  exampleKey: mediaType,
127
- stackTrail: st,
128
+ stackTrail,
128
129
  context
129
- })),
130
+ }),
130
131
  extensionFields
131
132
  };
132
133
  return context.withStackTrail(stackTrail, () => new MediaType_js_1.OasMediaType(fields, context));
@@ -141,13 +141,14 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
141
141
  allowEmptyValue,
142
142
  allowReserved,
143
143
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
144
- examples: stackTrail.trace('examples', st => (0, toExamplesV3_js_1.toExamplesV3)({
144
+ // toExamplesV3 traces `examples` (or `example`) itself.
145
+ examples: (0, toExamplesV3_js_1.toExamplesV3)({
145
146
  examples,
146
147
  example,
147
148
  exampleKey: `${name}-${parsedLocation}`,
148
- stackTrail: st,
149
+ stackTrail,
149
150
  context
150
- })),
151
+ }),
151
152
  content: stackTrail.trace('content', st => (0, toMediaTypeItemV3_js_1.toOptionalMediaTypeItemsV3)({ content, stackTrail: st, context })),
152
153
  extensionFields
153
154
  };
@@ -8,7 +8,10 @@ const toRefV31 = ({ ref, refType, stackTrail, context, nullable, readOnly, write
8
8
  if (!(0, isEmpty_js_1.isEmpty)(skipped)) {
9
9
  context.logSkippedFields({ skipped, parent: ref, parentType: 'ref', stackTrail });
10
10
  }
11
- context.registerRef(stackTrail.clone(), $ref);
12
- return context.withStackTrail(stackTrail, () => new Ref_js_1.OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
11
+ const oasRef = context.withStackTrail(stackTrail, () => new Ref_js_1.OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
12
+ // The parse context checks each ref once the document is parsed, and
13
+ // removes what holds a ref that names nothing (`system.danglingRefs`).
14
+ context.registerOasRef(stackTrail.clone(), oasRef);
15
+ return oasRef;
13
16
  };
14
17
  exports.toRefV31 = toRefV31;
@@ -135,13 +135,14 @@ const toMediaTypeItemV3 = ({ mediaTypeItem, mediaType, stackTrail, context }) =>
135
135
  itemEncoding,
136
136
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
137
137
  itemSchema: stackTrail.trace('itemSchema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema: itemSchema, stackTrail: st, context })),
138
- examples: stackTrail.trace('examples', st => (0, toExamplesV3_js_1.toExamplesV3)({
138
+ // toExamplesV3 traces `examples` (or `example`) itself.
139
+ examples: (0, toExamplesV3_js_1.toExamplesV3)({
139
140
  example,
140
141
  examples,
141
142
  exampleKey: mediaType,
142
- stackTrail: st,
143
+ stackTrail,
143
144
  context
144
- })),
145
+ }),
145
146
  extensionFields
146
147
  };
147
148
  return context.withStackTrail(stackTrail, () => new MediaType_js_1.OasMediaType(fields, context));
@@ -158,13 +158,14 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
158
158
  allowEmptyValue,
159
159
  allowReserved,
160
160
  schema: stackTrail.trace('schema', st => (0, toSchemasV3_js_1.toOptionalSchemaV3)({ schema, stackTrail: st, context })),
161
- examples: stackTrail.trace('examples', st => (0, toExamplesV3_js_1.toExamplesV3)({
161
+ // toExamplesV3 traces `examples` (or `example`) itself.
162
+ examples: (0, toExamplesV3_js_1.toExamplesV3)({
162
163
  examples,
163
164
  example,
164
165
  exampleKey: `${name}-${parsedLocation}`,
165
- stackTrail: st,
166
+ stackTrail,
166
167
  context
167
- })),
168
+ }),
168
169
  content: stackTrail.trace('content', st => (0, toMediaTypeItemV3_js_1.toOptionalMediaTypeItemsV3)({ content, stackTrail: st, context })),
169
170
  extensionFields
170
171
  };
@@ -8,7 +8,10 @@ const toRefV31 = ({ ref, refType, stackTrail, context, nullable, readOnly, write
8
8
  if (!(0, isEmpty_js_1.isEmpty)(skipped)) {
9
9
  context.logSkippedFields({ skipped, parent: ref, parentType: 'ref', stackTrail });
10
10
  }
11
- context.registerRef(stackTrail.clone(), $ref);
12
- return context.withStackTrail(stackTrail, () => new Ref_js_1.OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
11
+ const oasRef = context.withStackTrail(stackTrail, () => new Ref_js_1.OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
12
+ // The parse context checks each ref once the document is parsed, and
13
+ // removes what holds a ref that names nothing (`system.danglingRefs`).
14
+ context.registerOasRef(stackTrail.clone(), oasRef);
15
+ return oasRef;
13
16
  };
14
17
  exports.toRefV31 = toRefV31;
@@ -449,6 +449,16 @@ export type SystemSettings = {
449
449
  * keywords and without the `anyOf`, with one warning for each schema.
450
450
  */
451
451
  anyOf?: 'union' | 'unknown';
452
+ /**
453
+ * `strict` (the default): a `$ref` that names nothing in the document is a
454
+ * parse error, and what holds it is removed, with what uses that. `keep`:
455
+ * the `$ref` stays, with a warning, and resolving it throws
456
+ * `DanglingRefError`, which a generator can catch to render something
457
+ * else. With either, a `$ref` to an example or a link is a warning and
458
+ * stays, and a `$ref` that core resolves while it parses (an `allOf`
459
+ * member that it merges) is an error, and what holds it is removed.
460
+ */
461
+ danglingRefs?: 'strict' | 'keep';
452
462
  };
453
463
  export type ClientSettings = {
454
464
  /** Base output path for generated files */
@@ -210,7 +210,8 @@ exports.systemSettings = v.object({
210
210
  allOf: v.optional(v.picklist(['strict', 'latestWins'])),
211
211
  responseContradictions: v.optional(v.picklist(['strict', 'unknown'])),
212
212
  not: v.optional(v.picklist(['strict', 'unknown'])),
213
- anyOf: v.optional(v.picklist(['union', 'unknown']))
213
+ anyOf: v.optional(v.picklist(['union', 'unknown'])),
214
+ danglingRefs: v.optional(v.picklist(['strict', 'keep']))
214
215
  });
215
216
  exports.clientSettings = v.object({
216
217
  basePath: v.optional(v.pipe(v.string(), v.check(basePath => !(0, normalizeWorkspacePath_js_1.isAbsolutePath)(basePath), 'basePath must be relative to the SKMTC root (the directory containing .skmtc/); ' +