@skmtc/core 0.34.0 → 0.35.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 (75) hide show
  1. package/esm/context/generateTypes.d.ts +2 -2
  2. package/esm/context/generateTypes.js +5 -0
  3. package/esm/parse/descriptiveFields.d.ts +36 -0
  4. package/esm/parse/descriptiveFields.js +56 -0
  5. package/esm/parse/isPlainObject.d.ts +2 -0
  6. package/esm/parse/isPlainObject.js +2 -0
  7. package/esm/parse/toComponentEntries.d.ts +29 -0
  8. package/esm/parse/toComponentEntries.js +31 -0
  9. package/esm/parse/toPresentInfo.d.ts +30 -0
  10. package/esm/parse/toPresentInfo.js +40 -0
  11. package/esm/parse/v3-0/components/toComponentsV3.js +2 -2
  12. package/esm/parse/v3-0/externalDocs/toExternalDocs.d.ts +3 -1
  13. package/esm/parse/v3-0/externalDocs/toExternalDocs.js +9 -8
  14. package/esm/parse/v3-0/header/toHeadersV3.d.ts +12 -0
  15. package/esm/parse/v3-0/header/toHeadersV3.js +20 -0
  16. package/esm/parse/v3-0/info/toInfoV3.d.ts +2 -1
  17. package/esm/parse/v3-0/info/toInfoV3.js +15 -4
  18. package/esm/parse/v3-0/requestBody/toRequestBodiesV3.js +9 -9
  19. package/esm/parse/v3-0/tag/toTagsV3.js +7 -2
  20. package/esm/parse/v3-1/components/toComponentsV3.js +2 -2
  21. package/esm/parse/v3-1/externalDocs/toExternalDocs.d.ts +3 -1
  22. package/esm/parse/v3-1/externalDocs/toExternalDocs.js +9 -8
  23. package/esm/parse/v3-1/header/toHeadersV3.d.ts +12 -0
  24. package/esm/parse/v3-1/header/toHeadersV3.js +20 -0
  25. package/esm/parse/v3-1/info/toInfoV3.d.ts +2 -1
  26. package/esm/parse/v3-1/info/toInfoV3.js +15 -4
  27. package/esm/parse/v3-1/requestBody/toRequestBodiesV3.js +9 -9
  28. package/esm/parse/v3-1/tag/toTagsV3.js +7 -2
  29. package/esm/parse/v3-2/components/toComponentsV3.js +2 -2
  30. package/esm/parse/v3-2/externalDocs/toExternalDocs.d.ts +3 -1
  31. package/esm/parse/v3-2/externalDocs/toExternalDocs.js +9 -8
  32. package/esm/parse/v3-2/header/toHeadersV3.d.ts +12 -0
  33. package/esm/parse/v3-2/header/toHeadersV3.js +20 -0
  34. package/esm/parse/v3-2/info/toInfoV3.d.ts +2 -1
  35. package/esm/parse/v3-2/info/toInfoV3.js +15 -4
  36. package/esm/parse/v3-2/requestBody/toRequestBodiesV3.js +9 -9
  37. package/esm/parse/v3-2/tag/toTagsV3.js +14 -7
  38. package/package.json +1 -1
  39. package/script/context/generateTypes.d.ts +2 -2
  40. package/script/context/generateTypes.js +5 -0
  41. package/script/parse/descriptiveFields.d.ts +36 -0
  42. package/script/parse/descriptiveFields.js +95 -0
  43. package/script/parse/isPlainObject.d.ts +2 -0
  44. package/script/parse/isPlainObject.js +6 -0
  45. package/script/parse/toComponentEntries.d.ts +29 -0
  46. package/script/parse/toComponentEntries.js +35 -0
  47. package/script/parse/toPresentInfo.d.ts +30 -0
  48. package/script/parse/toPresentInfo.js +45 -0
  49. package/script/parse/v3-0/components/toComponentsV3.js +1 -1
  50. package/script/parse/v3-0/externalDocs/toExternalDocs.d.ts +3 -1
  51. package/script/parse/v3-0/externalDocs/toExternalDocs.js +9 -41
  52. package/script/parse/v3-0/header/toHeadersV3.d.ts +12 -0
  53. package/script/parse/v3-0/header/toHeadersV3.js +22 -1
  54. package/script/parse/v3-0/info/toInfoV3.d.ts +2 -1
  55. package/script/parse/v3-0/info/toInfoV3.js +15 -4
  56. package/script/parse/v3-0/requestBody/toRequestBodiesV3.js +9 -9
  57. package/script/parse/v3-0/tag/toTagsV3.js +7 -2
  58. package/script/parse/v3-1/components/toComponentsV3.js +1 -1
  59. package/script/parse/v3-1/externalDocs/toExternalDocs.d.ts +3 -1
  60. package/script/parse/v3-1/externalDocs/toExternalDocs.js +9 -41
  61. package/script/parse/v3-1/header/toHeadersV3.d.ts +12 -0
  62. package/script/parse/v3-1/header/toHeadersV3.js +22 -1
  63. package/script/parse/v3-1/info/toInfoV3.d.ts +2 -1
  64. package/script/parse/v3-1/info/toInfoV3.js +15 -4
  65. package/script/parse/v3-1/requestBody/toRequestBodiesV3.js +9 -9
  66. package/script/parse/v3-1/tag/toTagsV3.js +7 -2
  67. package/script/parse/v3-2/components/toComponentsV3.js +1 -1
  68. package/script/parse/v3-2/externalDocs/toExternalDocs.d.ts +3 -1
  69. package/script/parse/v3-2/externalDocs/toExternalDocs.js +9 -41
  70. package/script/parse/v3-2/header/toHeadersV3.d.ts +12 -0
  71. package/script/parse/v3-2/header/toHeadersV3.js +22 -1
  72. package/script/parse/v3-2/info/toInfoV3.d.ts +2 -1
  73. package/script/parse/v3-2/info/toInfoV3.js +15 -4
  74. package/script/parse/v3-2/requestBody/toRequestBodiesV3.js +9 -9
  75. package/script/parse/v3-2/tag/toTagsV3.js +14 -7
@@ -9,6 +9,18 @@ export type ToHeadersV3Args = {
9
9
  context: ParseContextType;
10
10
  };
11
11
  export declare const toHeadersV3: ({ headers, stackTrail, context }: ToHeadersV3Args) => Record<string, OasHeader | OasRef<"header">> | undefined;
12
+ export type ToComponentHeadersV3Args = {
13
+ headers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.HeaderObject> | undefined;
14
+ stackTrail: StackTrail;
15
+ context: ParseContextType;
16
+ };
17
+ /**
18
+ * Parse `components.headers`. Each entry parses inside its own boundary: a
19
+ * broken one is dropped with an INVALID_HEADER error, and the others are
20
+ * kept. Headers inside a response stay with {@link toHeadersV3}, where a
21
+ * broken header drops the response.
22
+ */
23
+ export declare const toComponentHeadersV3: ({ headers, stackTrail, context }: ToComponentHeadersV3Args) => Record<string, OasHeader | OasRef<"header">> | undefined;
12
24
  export type ToHeaderV3Args = {
13
25
  header: OpenAPIV3.ReferenceObject | OpenAPIV3.HeaderObject;
14
26
  /** The header's name, used to key a singular `example` */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHeadersV3 = void 0;
3
+ exports.toComponentHeadersV3 = exports.toHeadersV3 = void 0;
4
4
  const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
5
5
  const toRefV31_js_1 = require("../ref/toRefV31.js");
6
6
  const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
@@ -8,6 +8,7 @@ const refFns_js_1 = require("../../../helpers/refFns.js");
8
8
  const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
9
9
  const Header_js_1 = require("../../../oas/header/Header.js");
10
10
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
11
+ const toComponentEntries_js_1 = require("../../toComponentEntries.js");
11
12
  const toHeadersV3 = ({ headers, stackTrail, context }) => {
12
13
  if (!headers) {
13
14
  return undefined;
@@ -20,6 +21,26 @@ const toHeadersV3 = ({ headers, stackTrail, context }) => {
20
21
  return output;
21
22
  };
22
23
  exports.toHeadersV3 = toHeadersV3;
24
+ /**
25
+ * Parse `components.headers`. Each entry parses inside its own boundary: a
26
+ * broken one is dropped with an INVALID_HEADER error, and the others are
27
+ * kept. Headers inside a response stay with {@link toHeadersV3}, where a
28
+ * broken header drops the response.
29
+ */
30
+ const toComponentHeadersV3 = ({ headers, stackTrail, context }) => {
31
+ if (!headers) {
32
+ return undefined;
33
+ }
34
+ return (0, toComponentEntries_js_1.toComponentEntries)({
35
+ entries: headers,
36
+ stackTrail,
37
+ context,
38
+ type: 'INVALID_HEADER',
39
+ label: 'Header',
40
+ parse: ({ key, entry, stackTrail: st }) => toHeaderV3({ header: entry, name: key, stackTrail: st, context })
41
+ });
42
+ };
43
+ exports.toComponentHeadersV3 = toComponentHeadersV3;
23
44
  const toHeaderV3 = ({ header, name, stackTrail, context }) => {
24
45
  if ((0, refFns_js_1.isRef)(header)) {
25
46
  return (0, toRefV31_js_1.toRefV31)({ ref: header, refType: 'header', stackTrail, context });
@@ -3,7 +3,8 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
3
3
  import { OasInfo } from '../../../oas/info/Info.js';
4
4
  import type { StackTrail } from '../../../context/StackTrail.js';
5
5
  export type ToInfoV3Args = {
6
- info: OpenAPIV3.InfoObject;
6
+ /** Required by the spec; a document without it still parses (see {@link toPresentInfo}). */
7
+ info: OpenAPIV3.InfoObject | null | undefined;
7
8
  stackTrail: StackTrail;
8
9
  context: ParseContextType;
9
10
  };
@@ -5,22 +5,33 @@ const Info_js_1 = require("../../../oas/info/Info.js");
5
5
  const toContactV3_js_1 = require("../contact/toContactV3.js");
6
6
  const toLicenseV3_js_1 = require("../license/toLicenseV3.js");
7
7
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
8
+ const toPresentInfo_js_1 = require("../../toPresentInfo.js");
8
9
  const toInfoV3 = ({ info, stackTrail, context }) => {
9
- const { title, description, termsOfService, contact, license, version, ...skipped } = info;
10
+ const presentInfo = (0, toPresentInfo_js_1.toPresentInfo)({ info, stackTrail, context });
11
+ if (presentInfo === undefined) {
12
+ return new Info_js_1.OasInfo({ title: '', version: '' });
13
+ }
14
+ const { title, description, termsOfService, contact, license, version, ...skipped } = presentInfo;
10
15
  const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
11
16
  skipped,
12
- parent: info,
17
+ parent: presentInfo,
13
18
  context,
14
19
  stackTrail,
15
20
  parentType: 'info'
16
21
  });
17
22
  return new Info_js_1.OasInfo({
18
- title,
23
+ title: (0, toPresentInfo_js_1.toInfoString)({ value: title, key: 'title', parent: presentInfo, stackTrail, context }),
19
24
  description,
20
25
  termsOfService,
21
26
  contact: contact ? (0, toContactV3_js_1.toContactV3)(contact, stackTrail, context) : undefined,
22
27
  license: license ? (0, toLicenseV3_js_1.toLicenseV3)(license, stackTrail, context) : undefined,
23
- version,
28
+ version: (0, toPresentInfo_js_1.toInfoString)({
29
+ value: version,
30
+ key: 'version',
31
+ parent: presentInfo,
32
+ stackTrail,
33
+ context
34
+ }),
24
35
  extensionFields
25
36
  });
26
37
  };
@@ -7,6 +7,7 @@ const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
7
7
  const RequestBody_js_1 = require("../../../oas/requestBody/RequestBody.js");
8
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
9
9
  const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
10
+ const toComponentEntries_js_1 = require("../../toComponentEntries.js");
10
11
  const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
11
12
  if (!requestBody) {
12
13
  return undefined;
@@ -39,14 +40,13 @@ const toRequestBodiesV3 = ({ requestBodies, stackTrail, context }) => {
39
40
  if (!requestBodies) {
40
41
  return undefined;
41
42
  }
42
- const entries = Object.entries(requestBodies)
43
- .map(([key, value]) => {
44
- return [
45
- key,
46
- stackTrail.trace(key, st => (0, exports.toRequestBodyV3)({ requestBody: value, stackTrail: st, context }))
47
- ];
48
- })
49
- .filter(([, value]) => Boolean(value));
50
- return Object.fromEntries(entries);
43
+ return (0, toComponentEntries_js_1.toComponentEntries)({
44
+ entries: requestBodies,
45
+ stackTrail,
46
+ context,
47
+ type: 'INVALID_REQUEST_BODY',
48
+ label: 'Request body',
49
+ parse: ({ entry, stackTrail: st }) => (0, exports.toRequestBodyV3)({ requestBody: entry, stackTrail: st, context })
50
+ });
51
51
  };
52
52
  exports.toRequestBodiesV3 = toRequestBodiesV3;
@@ -4,26 +4,33 @@ exports.toTagV3 = exports.toTagsV3 = void 0;
4
4
  const Tag_js_1 = require("../../../oas/tag/Tag.js");
5
5
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
6
6
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
7
+ const descriptiveFields_js_1 = require("../../descriptiveFields.js");
7
8
  const toTagsV3 = ({ tags, stackTrail, context }) => {
8
- if (!tags) {
9
+ if (tags === undefined) {
9
10
  return undefined;
10
11
  }
11
- const parents = new Map(tags.map(({ name, parent }) => [name, parent]));
12
- return tags.map(tag => {
12
+ // A malformed entry, or a `tags` that is not an array, is left out with a
13
+ // warning: tags do not change how an operation renders.
14
+ const validTags = (0, descriptiveFields_js_1.toTagList)({ tags, stackTrail, context })?.flatMap((tag, index) => stackTrail.trace(`${index}`, st => (0, descriptiveFields_js_1.isValidTag)({ tag, stackTrail: st, context }) ? [{ tag, index }] : []));
15
+ if (!validTags) {
16
+ return undefined;
17
+ }
18
+ const parents = new Map(validTags.map(({ tag: { name, parent } }) => [name, parent]));
19
+ return validTags.map(({ tag, index }) => stackTrail.trace(`${index}`, st => {
13
20
  const parentError = toParentError({ name: tag.name, parent: tag.parent, parents });
14
21
  if (!parentError) {
15
- return (0, exports.toTagV3)({ tag, stackTrail, context });
22
+ return (0, exports.toTagV3)({ tag, stackTrail: st, context });
16
23
  }
17
24
  context.logIssue({
18
25
  key: 'parent',
19
26
  level: 'warning',
20
27
  message: `Tag '${tag.name}' ${parentError}; dropping 'parent'`,
21
28
  parent: tag,
22
- stackTrail,
29
+ stackTrail: st,
23
30
  type: 'INVALID_TAG_PARENT'
24
31
  });
25
- return (0, exports.toTagV3)({ tag: { ...tag, parent: undefined }, stackTrail, context });
26
- });
32
+ return (0, exports.toTagV3)({ tag: { ...tag, parent: undefined }, stackTrail: st, context });
33
+ }));
27
34
  };
28
35
  exports.toTagsV3 = toTagsV3;
29
36
  /** Describes why the tag's `parent` is invalid, or returns undefined when it is valid. */