@skmtc/core 0.35.1 → 0.35.3

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/StackTrail.js +3 -13
  2. package/esm/context/documentTrail.d.ts +17 -0
  3. package/esm/context/documentTrail.js +28 -0
  4. package/esm/parse/isPlainObject.d.ts +2 -0
  5. package/esm/parse/isPlainObject.js +2 -0
  6. package/esm/parse/pathParameters.d.ts +57 -0
  7. package/esm/parse/pathParameters.js +138 -0
  8. package/esm/parse/securityRequirements.d.ts +63 -0
  9. package/esm/parse/securityRequirements.js +128 -0
  10. package/esm/parse/toComponentEntries.js +1 -2
  11. package/esm/parse/v3-0/document/toDocumentFieldsV3.js +21 -7
  12. package/esm/parse/v3-0/operation/toOperationsV3.js +7 -1
  13. package/esm/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
  14. package/esm/parse/v3-0/parameter/toParameterV3.js +19 -11
  15. package/esm/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
  16. package/esm/parse/v3-0/pathItem/toPathItemV3.js +5 -3
  17. package/esm/parse/v3-0/securityRequirement/toSecurityRequirement.d.ts +2 -1
  18. package/esm/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
  19. package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
  20. package/esm/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
  21. package/esm/parse/v3-1/operation/toOperationsV3.js +7 -1
  22. package/esm/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
  23. package/esm/parse/v3-1/parameter/toParameterV3.js +19 -11
  24. package/esm/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
  25. package/esm/parse/v3-1/pathItem/toPathItemV3.js +5 -3
  26. package/esm/parse/v3-1/securityRequirement/toSecurityRequirement.d.ts +2 -1
  27. package/esm/parse/v3-1/securityRequirement/toSecurityRequirement.js +2 -4
  28. package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
  29. package/esm/parse/v3-2/document/toDocumentFieldsV3.js +21 -7
  30. package/esm/parse/v3-2/operation/toOperationsV3.js +11 -10
  31. package/esm/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
  32. package/esm/parse/v3-2/parameter/toParameterV3.js +30 -24
  33. package/esm/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
  34. package/esm/parse/v3-2/pathItem/toPathItemV3.js +5 -30
  35. package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.d.ts +2 -1
  36. package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
  37. package/esm/parse/v3-2/webhook/toWebhooksV3.js +11 -10
  38. package/package.json +1 -1
  39. package/script/context/StackTrail.js +3 -13
  40. package/script/context/documentTrail.d.ts +17 -0
  41. package/script/context/documentTrail.js +34 -0
  42. package/script/parse/isPlainObject.d.ts +2 -0
  43. package/script/parse/isPlainObject.js +4 -1
  44. package/script/parse/pathParameters.d.ts +57 -0
  45. package/script/parse/pathParameters.js +144 -0
  46. package/script/parse/securityRequirements.d.ts +63 -0
  47. package/script/parse/securityRequirements.js +134 -0
  48. package/script/parse/toComponentEntries.js +1 -2
  49. package/script/parse/v3-0/document/toDocumentFieldsV3.js +21 -7
  50. package/script/parse/v3-0/operation/toOperationsV3.js +7 -1
  51. package/script/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
  52. package/script/parse/v3-0/parameter/toParameterV3.js +22 -13
  53. package/script/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
  54. package/script/parse/v3-0/pathItem/toPathItemV3.js +4 -2
  55. package/script/parse/v3-0/securityRequirement/toSecurityRequirement.d.ts +2 -1
  56. package/script/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
  57. package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
  58. package/script/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
  59. package/script/parse/v3-1/operation/toOperationsV3.js +7 -1
  60. package/script/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
  61. package/script/parse/v3-1/parameter/toParameterV3.js +22 -13
  62. package/script/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
  63. package/script/parse/v3-1/pathItem/toPathItemV3.js +4 -2
  64. package/script/parse/v3-1/securityRequirement/toSecurityRequirement.d.ts +2 -1
  65. package/script/parse/v3-1/securityRequirement/toSecurityRequirement.js +2 -4
  66. package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
  67. package/script/parse/v3-2/document/toDocumentFieldsV3.js +21 -7
  68. package/script/parse/v3-2/operation/toOperationsV3.js +10 -9
  69. package/script/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
  70. package/script/parse/v3-2/parameter/toParameterV3.js +33 -26
  71. package/script/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
  72. package/script/parse/v3-2/pathItem/toPathItemV3.js +5 -31
  73. package/script/parse/v3-2/securityRequirement/toSecurityRequirement.d.ts +2 -1
  74. package/script/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
  75. package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
@@ -4,6 +4,7 @@ import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
+ import { type PathParameterList } from '../../pathParameters.js';
7
8
  type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
8
9
  type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
9
10
  export type ToParameterListV3Args = {
@@ -12,6 +13,12 @@ export type ToParameterListV3Args = {
12
13
  context: ParseContextType;
13
14
  };
14
15
  export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
16
+ /**
17
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
18
+ * that fails to parse is logged and returned in `broken` instead of
19
+ * throwing.
20
+ */
21
+ export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
15
22
  export type ToParametersV3Args = {
16
23
  parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
17
24
  stackTrail: StackTrail;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toParameterListV3 = void 0;
36
+ exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toPathParameterListV3 = exports.toParameterListV3 = void 0;
37
37
  const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
38
38
  const refFns_js_1 = require("../../../helpers/refFns.js");
39
39
  const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
@@ -44,6 +44,7 @@ const Parameter_js_1 = require("../../../oas/parameter/Parameter.js");
44
44
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
45
45
  const v = __importStar(require("valibot"));
46
46
  const emptyParameter_js_1 = require("../../emptyParameter.js");
47
+ const pathParameters_js_1 = require("../../pathParameters.js");
47
48
  const parameterLocation = v.enum({
48
49
  query: 'query',
49
50
  header: 'header',
@@ -59,19 +60,27 @@ const parameterStyle = v.enum({
59
60
  pipeDelimited: 'pipeDelimited',
60
61
  deepObject: 'deepObject'
61
62
  });
62
- const toParameterListV3 = ({ parameters, stackTrail, context }) => {
63
- if (!parameters) {
64
- return undefined;
65
- }
66
- return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
67
- if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
68
- (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context });
69
- return [];
70
- }
71
- return [toParameterV3({ parameter, stackTrail: st, context })];
72
- }));
73
- };
63
+ const toParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toParameterEntries)({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
74
64
  exports.toParameterListV3 = toParameterListV3;
65
+ /**
66
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
67
+ * that fails to parse is logged and returned in `broken` instead of
68
+ * throwing.
69
+ */
70
+ const toPathParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toPathParameterList)({
71
+ parameters,
72
+ stackTrail,
73
+ context,
74
+ toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
75
+ });
76
+ exports.toPathParameterListV3 = toPathParameterListV3;
77
+ const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
78
+ if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
79
+ (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context });
80
+ return [];
81
+ }
82
+ return [toParameterV3({ parameter, stackTrail: st, context })];
83
+ });
75
84
  const toParametersV3 = ({ parameters, stackTrail, context }) => {
76
85
  const output = {};
77
86
  const entries = Object.entries(parameters);
@@ -1,5 +1,6 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContextType } from '../../../context/parseTypes.js';
3
+ import type { BrokenPathParameter } from '../../pathParameters.js';
3
4
  import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
4
5
  import type { StackTrail } from '../../../context/StackTrail.js';
5
6
  export type ToPathItemV3Args = {
@@ -7,4 +8,9 @@ export type ToPathItemV3Args = {
7
8
  stackTrail: StackTrail;
8
9
  context: ParseContextType;
9
10
  };
10
- export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => OasPathItem;
11
+ export type PathItemV3 = {
12
+ pathItem: OasPathItem;
13
+ /** Path-level parameters that failed to parse; the caller drops each operation they apply to. */
14
+ brokenParameters: BrokenPathParameter[];
15
+ };
16
+ export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
@@ -8,10 +8,11 @@ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
8
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
9
9
  const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
10
10
  const { summary, description, parameters, servers, ...skipped } = pathItem;
11
- return new PathItem_js_1.OasPathItem({
11
+ const pathParameters = stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toPathParameterListV3)({ parameters, stackTrail: st, context }));
12
+ const oasPathItem = new PathItem_js_1.OasPathItem({
12
13
  summary,
13
14
  description,
14
- parameters: stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toParameterListV3)({ parameters, stackTrail: st, context })),
15
+ parameters: pathParameters.parameters,
15
16
  servers: (0, tryParseAt_js_1.tryParseAt)({
16
17
  stackTrail,
17
18
  key: 'servers',
@@ -28,5 +29,6 @@ const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
28
29
  parentType: 'pathItem'
29
30
  })
30
31
  });
32
+ return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
31
33
  };
32
34
  exports.toPathItemV3 = toPathItemV3;
@@ -2,7 +2,8 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
2
2
  import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
3
3
  import type { StackTrail } from '../../../context/StackTrail.js';
4
4
  export type ToSecurityRequirementsV3Args = {
5
- security: Record<string, string[]>[] | undefined;
5
+ /** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
6
+ security: unknown;
6
7
  stackTrail: StackTrail;
7
8
  context: ParseContextType;
8
9
  };
@@ -2,11 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toSecurityRequirementsV3 = void 0;
4
4
  const SecurityRequirement_js_1 = require("../../../oas/securityRequirement/SecurityRequirement.js");
5
+ const securityRequirements_js_1 = require("../../securityRequirements.js");
5
6
  const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
6
- if (!security) {
7
- return undefined;
8
- }
9
- return security.map(requirement => {
7
+ return (0, securityRequirements_js_1.toSecurityRequirementObjects)(security)?.map(requirement => {
10
8
  return new SecurityRequirement_js_1.OasSecurityRequirement({ requirement }, context.oasDocument);
11
9
  });
12
10
  };
@@ -12,6 +12,7 @@ const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityReq
12
12
  const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
13
13
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
14
14
  const toServerV3_js_1 = require("../server/toServerV3.js");
15
+ const pathParameters_js_1 = require("../../pathParameters.js");
15
16
  /**
16
17
  * Parses a single webhook Operation Object into an {@link OasWebhook}.
17
18
  *
@@ -89,9 +90,11 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
89
90
  rest: pathItem,
90
91
  methodObject: {}
91
92
  });
92
- const pathItemObject = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
93
+ const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
93
94
  ? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: nameStack, context })
94
95
  : undefined;
96
+ const pathItemObject = pathItemResult?.pathItem;
97
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
95
98
  return Object.entries(cleaned.methodObject)
96
99
  .map(([method, operation]) => {
97
100
  // Use `nameStack` (the trail with the webhook name already
@@ -101,6 +104,9 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
101
104
  if (!operation) {
102
105
  return;
103
106
  }
107
+ if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
108
+ return undefined;
109
+ }
104
110
  try {
105
111
  return (0, exports.toWebhookV3)({
106
112
  operation,
@@ -10,6 +10,7 @@ const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toS
10
10
  const toServerV3_js_1 = require("../server/toServerV3.js");
11
11
  const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityRequirement.js");
12
12
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
13
+ const securityRequirements_js_1 = require("../../securityRequirements.js");
13
14
  const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
14
15
  const { openapi, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
15
16
  const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
@@ -19,15 +20,28 @@ const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
19
20
  stackTrail,
20
21
  parentType: 'document'
21
22
  });
23
+ const parsedInfo = stackTrail.trace('info', st => (0, toInfoV3_js_1.toInfoV3)({ info, stackTrail: st, context }));
24
+ const parsedServers = stackTrail.trace('servers', st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context }));
25
+ const parsedOperations = stackTrail.trace('paths', st => (0, toOperationsV3_js_1.toOperationsV3)({ paths, stackTrail: st, context }));
26
+ const parsedWebhooks = stackTrail.trace('webhooks', st => (0, toWebhooksV3_js_1.toWebhooksV3)({ webhooks, stackTrail: st, context }));
27
+ const parsedComponents = stackTrail.trace('components', st => (0, toComponentsV3_js_1.toComponentsV3)({ components, stackTrail: st, context }));
28
+ const parsedTags = stackTrail.trace('tags', st => (0, toTagsV3_js_1.toTagsV3)({ tags, stackTrail: st, context }));
29
+ const securityCheck = stackTrail.trace('security', st => (0, securityRequirements_js_1.toSecurityCheck)({
30
+ parse: () => (0, toSecurityRequirement_js_1.toSecurityRequirementsV3)({ security, stackTrail: st, context }),
31
+ declared: components?.securitySchemes,
32
+ parsed: parsedComponents?.securitySchemes,
33
+ stackTrail: st,
34
+ context
35
+ }));
22
36
  return {
23
37
  openapi,
24
- info: stackTrail.trace('info', st => (0, toInfoV3_js_1.toInfoV3)({ info, stackTrail: st, context })),
25
- servers: stackTrail.trace('servers', st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context })),
26
- operations: stackTrail.trace('paths', st => (0, toOperationsV3_js_1.toOperationsV3)({ paths, stackTrail: st, context })),
27
- webhooks: stackTrail.trace('webhooks', st => (0, toWebhooksV3_js_1.toWebhooksV3)({ webhooks, stackTrail: st, context })),
28
- components: stackTrail.trace('components', st => (0, toComponentsV3_js_1.toComponentsV3)({ components, stackTrail: st, context })),
29
- tags: stackTrail.trace('tags', st => (0, toTagsV3_js_1.toTagsV3)({ tags, stackTrail: st, context })),
30
- security: stackTrail.trace('security', st => (0, toSecurityRequirement_js_1.toSecurityRequirementsV3)({ security, stackTrail: st, context })),
38
+ info: parsedInfo,
39
+ servers: parsedServers,
40
+ operations: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedOperations, check: securityCheck }),
41
+ webhooks: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedWebhooks, check: securityCheck }),
42
+ components: parsedComponents,
43
+ tags: parsedTags,
44
+ security: securityCheck.rootSecurity,
31
45
  extensionFields,
32
46
  externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context }))
33
47
  };
@@ -12,6 +12,7 @@ const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityReq
12
12
  const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
13
13
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
14
14
  const toServerV3_js_1 = require("../server/toServerV3.js");
15
+ const pathParameters_js_1 = require("../../pathParameters.js");
15
16
  const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
16
17
  const { method, path, pathItem } = operationInfo;
17
18
  const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
@@ -77,9 +78,11 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
77
78
  rest: pathItem,
78
79
  methodObject: {}
79
80
  });
80
- const pathItemObject = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
81
+ const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
81
82
  ? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: pathStack, context })
82
83
  : undefined;
84
+ const pathItemObject = pathItemResult?.pathItem;
85
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
83
86
  return Object.entries(cleaned.methodObject)
84
87
  .map(([method, operation]) => {
85
88
  // Use `pathStack` (the trail with `path` already pushed),
@@ -91,6 +94,9 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
91
94
  if (!operation) {
92
95
  return;
93
96
  }
97
+ if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
98
+ return undefined;
99
+ }
94
100
  try {
95
101
  return (0, exports.toOperationV3)({
96
102
  operation,
@@ -4,6 +4,7 @@ import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
+ import { type PathParameterList } from '../../pathParameters.js';
7
8
  type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
8
9
  type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
9
10
  export type ToParameterListV3Args = {
@@ -12,6 +13,12 @@ export type ToParameterListV3Args = {
12
13
  context: ParseContextType;
13
14
  };
14
15
  export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
16
+ /**
17
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
18
+ * that fails to parse is logged and returned in `broken` instead of
19
+ * throwing.
20
+ */
21
+ export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
15
22
  export type ToParametersV3Args = {
16
23
  parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
17
24
  stackTrail: StackTrail;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toParameterListV3 = void 0;
36
+ exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toPathParameterListV3 = exports.toParameterListV3 = void 0;
37
37
  const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
38
38
  const refFns_js_1 = require("../../../helpers/refFns.js");
39
39
  const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
@@ -44,6 +44,7 @@ const Parameter_js_1 = require("../../../oas/parameter/Parameter.js");
44
44
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
45
45
  const v = __importStar(require("valibot"));
46
46
  const emptyParameter_js_1 = require("../../emptyParameter.js");
47
+ const pathParameters_js_1 = require("../../pathParameters.js");
47
48
  const parameterLocation = v.enum({
48
49
  query: 'query',
49
50
  header: 'header',
@@ -59,19 +60,27 @@ const parameterStyle = v.enum({
59
60
  pipeDelimited: 'pipeDelimited',
60
61
  deepObject: 'deepObject'
61
62
  });
62
- const toParameterListV3 = ({ parameters, stackTrail, context }) => {
63
- if (!parameters) {
64
- return undefined;
65
- }
66
- return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
67
- if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
68
- (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context });
69
- return [];
70
- }
71
- return [toParameterV3({ parameter, stackTrail: st, context })];
72
- }));
73
- };
63
+ const toParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toParameterEntries)({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
74
64
  exports.toParameterListV3 = toParameterListV3;
65
+ /**
66
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
67
+ * that fails to parse is logged and returned in `broken` instead of
68
+ * throwing.
69
+ */
70
+ const toPathParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toPathParameterList)({
71
+ parameters,
72
+ stackTrail,
73
+ context,
74
+ toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
75
+ });
76
+ exports.toPathParameterListV3 = toPathParameterListV3;
77
+ const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
78
+ if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
79
+ (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context });
80
+ return [];
81
+ }
82
+ return [toParameterV3({ parameter, stackTrail: st, context })];
83
+ });
75
84
  const toParametersV3 = ({ parameters, stackTrail, context }) => {
76
85
  const output = {};
77
86
  const entries = Object.entries(parameters);
@@ -1,5 +1,6 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContextType } from '../../../context/parseTypes.js';
3
+ import type { BrokenPathParameter } from '../../pathParameters.js';
3
4
  import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
4
5
  import type { StackTrail } from '../../../context/StackTrail.js';
5
6
  export type ToPathItemV3Args = {
@@ -7,4 +8,9 @@ export type ToPathItemV3Args = {
7
8
  stackTrail: StackTrail;
8
9
  context: ParseContextType;
9
10
  };
10
- export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => OasPathItem;
11
+ export type PathItemV3 = {
12
+ pathItem: OasPathItem;
13
+ /** Path-level parameters that failed to parse; the caller drops each operation they apply to. */
14
+ brokenParameters: BrokenPathParameter[];
15
+ };
16
+ export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
@@ -8,10 +8,11 @@ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
8
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
9
9
  const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
10
10
  const { summary, description, parameters, servers, ...skipped } = pathItem;
11
- return new PathItem_js_1.OasPathItem({
11
+ const pathParameters = stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toPathParameterListV3)({ parameters, stackTrail: st, context }));
12
+ const oasPathItem = new PathItem_js_1.OasPathItem({
12
13
  summary,
13
14
  description,
14
- parameters: stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toParameterListV3)({ parameters, stackTrail: st, context })),
15
+ parameters: pathParameters.parameters,
15
16
  servers: (0, tryParseAt_js_1.tryParseAt)({
16
17
  stackTrail,
17
18
  key: 'servers',
@@ -28,5 +29,6 @@ const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
28
29
  parentType: 'pathItem'
29
30
  })
30
31
  });
32
+ return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
31
33
  };
32
34
  exports.toPathItemV3 = toPathItemV3;
@@ -2,7 +2,8 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
2
2
  import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
3
3
  import type { StackTrail } from '../../../context/StackTrail.js';
4
4
  export type ToSecurityRequirementsV3Args = {
5
- security: Record<string, string[]>[] | undefined;
5
+ /** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
6
+ security: unknown;
6
7
  stackTrail: StackTrail;
7
8
  context: ParseContextType;
8
9
  };
@@ -2,11 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toSecurityRequirementsV3 = void 0;
4
4
  const SecurityRequirement_js_1 = require("../../../oas/securityRequirement/SecurityRequirement.js");
5
+ const securityRequirements_js_1 = require("../../securityRequirements.js");
5
6
  const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
6
- if (!security) {
7
- return undefined;
8
- }
9
- return security.map(requirement => {
7
+ return (0, securityRequirements_js_1.toSecurityRequirementObjects)(security)?.map(requirement => {
10
8
  return new SecurityRequirement_js_1.OasSecurityRequirement({ requirement }, context.oasDocument);
11
9
  });
12
10
  };
@@ -12,6 +12,7 @@ const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityReq
12
12
  const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
13
13
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
14
14
  const toServerV3_js_1 = require("../server/toServerV3.js");
15
+ const pathParameters_js_1 = require("../../pathParameters.js");
15
16
  /**
16
17
  * Parses a single webhook Operation Object into an {@link OasWebhook}.
17
18
  *
@@ -89,9 +90,11 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
89
90
  rest: pathItem,
90
91
  methodObject: {}
91
92
  });
92
- const pathItemObject = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
93
+ const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
93
94
  ? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: nameStack, context })
94
95
  : undefined;
96
+ const pathItemObject = pathItemResult?.pathItem;
97
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
95
98
  return Object.entries(cleaned.methodObject)
96
99
  .map(([method, operation]) => {
97
100
  // Use `nameStack` (the trail with the webhook name already
@@ -101,6 +104,9 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
101
104
  if (!operation) {
102
105
  return;
103
106
  }
107
+ if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
108
+ return undefined;
109
+ }
104
110
  try {
105
111
  return (0, exports.toWebhookV3)({
106
112
  operation,
@@ -10,6 +10,7 @@ const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toS
10
10
  const toServerV3_js_1 = require("../server/toServerV3.js");
11
11
  const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityRequirement.js");
12
12
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
13
+ const securityRequirements_js_1 = require("../../securityRequirements.js");
13
14
  const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
14
15
  const { openapi, $self, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
15
16
  const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
@@ -19,16 +20,29 @@ const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
19
20
  stackTrail,
20
21
  parentType: 'document'
21
22
  });
23
+ const parsedInfo = stackTrail.trace('info', st => (0, toInfoV3_js_1.toInfoV3)({ info, stackTrail: st, context }));
24
+ const parsedServers = stackTrail.trace('servers', st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context }));
25
+ const parsedOperations = stackTrail.trace('paths', st => (0, toOperationsV3_js_1.toOperationsV3)({ paths, stackTrail: st, context }));
26
+ const parsedWebhooks = stackTrail.trace('webhooks', st => (0, toWebhooksV3_js_1.toWebhooksV3)({ webhooks, stackTrail: st, context }));
27
+ const parsedComponents = stackTrail.trace('components', st => (0, toComponentsV3_js_1.toComponentsV3)({ components, stackTrail: st, context }));
28
+ const parsedTags = stackTrail.trace('tags', st => (0, toTagsV3_js_1.toTagsV3)({ tags, stackTrail: st, context }));
29
+ const securityCheck = stackTrail.trace('security', st => (0, securityRequirements_js_1.toSecurityCheck)({
30
+ parse: () => (0, toSecurityRequirement_js_1.toSecurityRequirementsV3)({ security, stackTrail: st, context }),
31
+ declared: components?.securitySchemes,
32
+ parsed: parsedComponents?.securitySchemes,
33
+ stackTrail: st,
34
+ context
35
+ }));
22
36
  return {
23
37
  openapi,
24
38
  $self,
25
- info: stackTrail.trace('info', st => (0, toInfoV3_js_1.toInfoV3)({ info, stackTrail: st, context })),
26
- servers: stackTrail.trace('servers', st => (0, toServerV3_js_1.toOptionalServersV3)({ servers, stackTrail: st, context })),
27
- operations: stackTrail.trace('paths', st => (0, toOperationsV3_js_1.toOperationsV3)({ paths, stackTrail: st, context })),
28
- webhooks: stackTrail.trace('webhooks', st => (0, toWebhooksV3_js_1.toWebhooksV3)({ webhooks, stackTrail: st, context })),
29
- components: stackTrail.trace('components', st => (0, toComponentsV3_js_1.toComponentsV3)({ components, stackTrail: st, context })),
30
- tags: stackTrail.trace('tags', st => (0, toTagsV3_js_1.toTagsV3)({ tags, stackTrail: st, context })),
31
- security: stackTrail.trace('security', st => (0, toSecurityRequirement_js_1.toSecurityRequirementsV3)({ security, stackTrail: st, context })),
39
+ info: parsedInfo,
40
+ servers: parsedServers,
41
+ operations: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedOperations, check: securityCheck }),
42
+ webhooks: (0, securityRequirements_js_1.toOperationsWithValidSecurity)({ items: parsedWebhooks, check: securityCheck }),
43
+ components: parsedComponents,
44
+ tags: parsedTags,
45
+ security: securityCheck.rootSecurity,
32
46
  extensionFields,
33
47
  externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context }))
34
48
  };
@@ -6,6 +6,7 @@ const toResponseV3_js_1 = require("../response/toResponseV3.js");
6
6
  const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
7
7
  const Operation_js_1 = require("../../../oas/operation/Operation.js");
8
8
  const toPathItemV3_js_1 = require("../pathItem/toPathItemV3.js");
9
+ const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
9
10
  const methods_js_1 = require("../methods.js");
10
11
  const dropAdditionalOperationsV3_js_1 = require("../pathItem/dropAdditionalOperationsV3.js");
11
12
  const warnQuerystringConflictsV3_js_1 = require("../parameter/warnQuerystringConflictsV3.js");
@@ -13,6 +14,7 @@ const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toS
13
14
  const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityRequirement.js");
14
15
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
15
16
  const toServerV3_js_1 = require("../server/toServerV3.js");
17
+ const pathParameters_js_1 = require("../../pathParameters.js");
16
18
  const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
17
19
  const { method, path, pathItem } = operationInfo;
18
20
  const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
@@ -80,15 +82,11 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
80
82
  rest: fixedFields,
81
83
  methodObject: {}
82
84
  });
83
- const pathItemResult = (0, toPathItemV3_js_1.toPathItemResultV3)({
84
- pathItem: cleaned.rest,
85
- stackTrail: pathStack,
86
- context
87
- });
88
- if (!pathItemResult.valid) {
89
- return [];
90
- }
91
- const pathItemObject = pathItemResult.pathItem;
85
+ const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
86
+ ? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: pathStack, context })
87
+ : undefined;
88
+ const pathItemObject = pathItemResult?.pathItem;
89
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
92
90
  return Object.entries(cleaned.methodObject)
93
91
  .map(([method, operation]) => {
94
92
  // Use `pathStack` (the trail with `path` already pushed),
@@ -100,6 +98,9 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
100
98
  if (!operation) {
101
99
  return;
102
100
  }
101
+ if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
102
+ return undefined;
103
+ }
103
104
  try {
104
105
  return (0, exports.toOperationV3)({
105
106
  operation,
@@ -4,12 +4,19 @@ import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
+ import { type PathParameterList } from '../../pathParameters.js';
7
8
  export type ToParameterListV3Args = {
8
9
  parameters: (OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject)[] | undefined;
9
10
  stackTrail: StackTrail;
10
11
  context: ParseContextType;
11
12
  };
12
13
  export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
14
+ /**
15
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
16
+ * that fails to parse is logged and returned in `broken` instead of
17
+ * throwing.
18
+ */
19
+ export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
13
20
  export type ToParametersV3Args = {
14
21
  parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
15
22
  stackTrail: StackTrail;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toParameterListV3 = void 0;
36
+ exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toPathParameterListV3 = exports.toParameterListV3 = void 0;
37
37
  const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
38
38
  const refFns_js_1 = require("../../../helpers/refFns.js");
39
39
  const parameter_types_js_1 = require("../../../oas/parameter/parameter-types.js");
@@ -45,33 +45,40 @@ const Parameter_js_1 = require("../../../oas/parameter/Parameter.js");
45
45
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
46
46
  const v = __importStar(require("valibot"));
47
47
  const emptyParameter_js_1 = require("../../emptyParameter.js");
48
- const toParameterListV3 = ({ parameters, stackTrail, context }) => {
49
- if (!parameters) {
50
- return undefined;
48
+ const pathParameters_js_1 = require("../../pathParameters.js");
49
+ const toParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toParameterEntries)({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
50
+ exports.toParameterListV3 = toParameterListV3;
51
+ /**
52
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
53
+ * that fails to parse is logged and returned in `broken` instead of
54
+ * throwing.
55
+ */
56
+ const toPathParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toPathParameterList)({
57
+ parameters,
58
+ stackTrail,
59
+ context,
60
+ toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
61
+ });
62
+ exports.toPathParameterListV3 = toPathParameterListV3;
63
+ const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => {
64
+ if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
65
+ stackTrail.trace(`${index}`, st => (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context }));
66
+ return [];
51
67
  }
52
- return parameters.flatMap((parameter, index) => {
53
- if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
54
- stackTrail.trace(`${index}`, st => (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context }));
55
- return [];
56
- }
57
- const querystringIssue = toQuerystringIssue(parameter);
58
- if (querystringIssue) {
59
- context.logIssue({
60
- key: `${index}`,
61
- parent: parameter,
62
- level: 'error',
63
- message: querystringIssue,
64
- stackTrail,
65
- type: 'INVALID_PARAMETER'
66
- });
67
- return [];
68
- }
69
- return [
70
- stackTrail.trace(`${index}`, st => toParameterV3({ parameter, stackTrail: st, context }))
71
- ];
72
- });
68
+ const querystringIssue = toQuerystringIssue(parameter);
69
+ if (querystringIssue) {
70
+ context.logIssue({
71
+ key: `${index}`,
72
+ parent: parameter,
73
+ level: 'error',
74
+ message: querystringIssue,
75
+ stackTrail,
76
+ type: 'INVALID_PARAMETER'
77
+ });
78
+ return [];
79
+ }
80
+ return [stackTrail.trace(`${index}`, st => toParameterV3({ parameter, stackTrail: st, context }))];
73
81
  };
74
- exports.toParameterListV3 = toParameterListV3;
75
82
  /**
76
83
  * A `querystring` parameter describes the whole query string, so it must
77
84
  * carry `content` with exactly one media type, and no `schema`. Returns