@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.
- package/esm/context/StackTrail.js +3 -13
- package/esm/context/documentTrail.d.ts +17 -0
- package/esm/context/documentTrail.js +28 -0
- package/esm/parse/isPlainObject.d.ts +2 -0
- package/esm/parse/isPlainObject.js +2 -0
- package/esm/parse/pathParameters.d.ts +57 -0
- package/esm/parse/pathParameters.js +138 -0
- package/esm/parse/securityRequirements.d.ts +63 -0
- package/esm/parse/securityRequirements.js +128 -0
- package/esm/parse/toComponentEntries.js +1 -2
- package/esm/parse/v3-0/document/toDocumentFieldsV3.js +21 -7
- package/esm/parse/v3-0/operation/toOperationsV3.js +7 -1
- package/esm/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-0/parameter/toParameterV3.js +19 -11
- package/esm/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
- package/esm/parse/v3-0/pathItem/toPathItemV3.js +5 -3
- package/esm/parse/v3-0/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
- package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
- package/esm/parse/v3-1/operation/toOperationsV3.js +7 -1
- package/esm/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-1/parameter/toParameterV3.js +19 -11
- package/esm/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
- package/esm/parse/v3-1/pathItem/toPathItemV3.js +5 -3
- package/esm/parse/v3-1/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-1/securityRequirement/toSecurityRequirement.js +2 -4
- package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-2/document/toDocumentFieldsV3.js +21 -7
- package/esm/parse/v3-2/operation/toOperationsV3.js +11 -10
- package/esm/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-2/parameter/toParameterV3.js +30 -24
- package/esm/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
- package/esm/parse/v3-2/pathItem/toPathItemV3.js +5 -30
- package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/esm/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
- package/esm/parse/v3-2/webhook/toWebhooksV3.js +11 -10
- package/package.json +1 -1
- package/script/context/StackTrail.js +3 -13
- package/script/context/documentTrail.d.ts +17 -0
- package/script/context/documentTrail.js +34 -0
- package/script/parse/isPlainObject.d.ts +2 -0
- package/script/parse/isPlainObject.js +4 -1
- package/script/parse/pathParameters.d.ts +57 -0
- package/script/parse/pathParameters.js +144 -0
- package/script/parse/securityRequirements.d.ts +63 -0
- package/script/parse/securityRequirements.js +134 -0
- package/script/parse/toComponentEntries.js +1 -2
- package/script/parse/v3-0/document/toDocumentFieldsV3.js +21 -7
- package/script/parse/v3-0/operation/toOperationsV3.js +7 -1
- package/script/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-0/parameter/toParameterV3.js +22 -13
- package/script/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
- package/script/parse/v3-0/pathItem/toPathItemV3.js +4 -2
- package/script/parse/v3-0/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-0/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-1/document/toDocumentFieldsV3.js +21 -7
- package/script/parse/v3-1/operation/toOperationsV3.js +7 -1
- package/script/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-1/parameter/toParameterV3.js +22 -13
- package/script/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
- package/script/parse/v3-1/pathItem/toPathItemV3.js +4 -2
- package/script/parse/v3-1/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-1/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-2/document/toDocumentFieldsV3.js +21 -7
- package/script/parse/v3-2/operation/toOperationsV3.js +10 -9
- package/script/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-2/parameter/toParameterV3.js +33 -26
- package/script/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
- package/script/parse/v3-2/pathItem/toPathItemV3.js +5 -31
- package/script/parse/v3-2/securityRequirement/toSecurityRequirement.d.ts +2 -1
- package/script/parse/v3-2/securityRequirement/toSecurityRequirement.js +2 -4
- package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
|
@@ -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
|
|
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;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toPathParameterListV3 } from '../parameter/toParameterV3.js';
|
|
2
2
|
import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
|
|
3
3
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
4
4
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
6
|
export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
7
7
|
const { summary, description, parameters, servers, ...skipped } = pathItem;
|
|
8
|
-
|
|
8
|
+
const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
|
|
9
|
+
const oasPathItem = new OasPathItem({
|
|
9
10
|
summary,
|
|
10
11
|
description,
|
|
11
|
-
parameters:
|
|
12
|
+
parameters: pathParameters.parameters,
|
|
12
13
|
servers: tryParseAt({
|
|
13
14
|
stackTrail,
|
|
14
15
|
key: 'servers',
|
|
@@ -25,4 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
|
25
26
|
parentType: 'pathItem'
|
|
26
27
|
})
|
|
27
28
|
});
|
|
29
|
+
return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
|
|
28
30
|
};
|
|
@@ -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
|
|
5
|
+
/** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
|
|
6
|
+
security: unknown;
|
|
6
7
|
stackTrail: StackTrail;
|
|
7
8
|
context: ParseContextType;
|
|
8
9
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
2
|
+
import { toSecurityRequirementObjects } from '../../securityRequirements.js';
|
|
2
3
|
export const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return security.map(requirement => {
|
|
4
|
+
return toSecurityRequirementObjects(security)?.map(requirement => {
|
|
7
5
|
return new OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
8
6
|
});
|
|
9
7
|
};
|
|
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
|
|
|
9
9
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
10
10
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
11
11
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
12
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
12
13
|
/**
|
|
13
14
|
* Parses a single webhook Operation Object into an {@link OasWebhook}.
|
|
14
15
|
*
|
|
@@ -85,9 +86,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
85
86
|
rest: pathItem,
|
|
86
87
|
methodObject: {}
|
|
87
88
|
});
|
|
88
|
-
const
|
|
89
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
89
90
|
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
|
|
90
91
|
: undefined;
|
|
92
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
93
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
91
94
|
return Object.entries(cleaned.methodObject)
|
|
92
95
|
.map(([method, operation]) => {
|
|
93
96
|
// Use `nameStack` (the trail with the webhook name already
|
|
@@ -97,6 +100,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
97
100
|
if (!operation) {
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
103
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
100
106
|
try {
|
|
101
107
|
return toWebhookV3({
|
|
102
108
|
operation,
|
|
@@ -7,6 +7,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
7
7
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
8
8
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
9
9
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
10
|
+
import { toOperationsWithValidSecurity, toSecurityCheck } from '../../securityRequirements.js';
|
|
10
11
|
export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
11
12
|
const { openapi, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
12
13
|
const extensionFields = toSpecificationExtensionsV3({
|
|
@@ -16,15 +17,28 @@ export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
|
16
17
|
stackTrail,
|
|
17
18
|
parentType: 'document'
|
|
18
19
|
});
|
|
20
|
+
const parsedInfo = stackTrail.trace('info', st => toInfoV3({ info, stackTrail: st, context }));
|
|
21
|
+
const parsedServers = stackTrail.trace('servers', st => toOptionalServersV3({ servers, stackTrail: st, context }));
|
|
22
|
+
const parsedOperations = stackTrail.trace('paths', st => toOperationsV3({ paths, stackTrail: st, context }));
|
|
23
|
+
const parsedWebhooks = stackTrail.trace('webhooks', st => toWebhooksV3({ webhooks, stackTrail: st, context }));
|
|
24
|
+
const parsedComponents = stackTrail.trace('components', st => toComponentsV3({ components, stackTrail: st, context }));
|
|
25
|
+
const parsedTags = stackTrail.trace('tags', st => toTagsV3({ tags, stackTrail: st, context }));
|
|
26
|
+
const securityCheck = stackTrail.trace('security', st => toSecurityCheck({
|
|
27
|
+
parse: () => toSecurityRequirementsV3({ security, stackTrail: st, context }),
|
|
28
|
+
declared: components?.securitySchemes,
|
|
29
|
+
parsed: parsedComponents?.securitySchemes,
|
|
30
|
+
stackTrail: st,
|
|
31
|
+
context
|
|
32
|
+
}));
|
|
19
33
|
return {
|
|
20
34
|
openapi,
|
|
21
|
-
info:
|
|
22
|
-
servers:
|
|
23
|
-
operations:
|
|
24
|
-
webhooks:
|
|
25
|
-
components:
|
|
26
|
-
tags:
|
|
27
|
-
security:
|
|
35
|
+
info: parsedInfo,
|
|
36
|
+
servers: parsedServers,
|
|
37
|
+
operations: toOperationsWithValidSecurity({ items: parsedOperations, check: securityCheck }),
|
|
38
|
+
webhooks: toOperationsWithValidSecurity({ items: parsedWebhooks, check: securityCheck }),
|
|
39
|
+
components: parsedComponents,
|
|
40
|
+
tags: parsedTags,
|
|
41
|
+
security: securityCheck.rootSecurity,
|
|
28
42
|
extensionFields,
|
|
29
43
|
externalDocs: stackTrail.trace('externalDocs', st => toExternalDocs({ externalDocs, stackTrail: st, context }))
|
|
30
44
|
};
|
|
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
|
|
|
9
9
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
10
10
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
11
11
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
12
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
12
13
|
export const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
|
|
13
14
|
const { method, path, pathItem } = operationInfo;
|
|
14
15
|
const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
|
|
@@ -73,9 +74,11 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
73
74
|
rest: pathItem,
|
|
74
75
|
methodObject: {}
|
|
75
76
|
});
|
|
76
|
-
const
|
|
77
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
77
78
|
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
|
|
78
79
|
: undefined;
|
|
80
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
81
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
79
82
|
return Object.entries(cleaned.methodObject)
|
|
80
83
|
.map(([method, operation]) => {
|
|
81
84
|
// Use `pathStack` (the trail with `path` already pushed),
|
|
@@ -87,6 +90,9 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
87
90
|
if (!operation) {
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
93
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
90
96
|
try {
|
|
91
97
|
return toOperationV3({
|
|
92
98
|
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;
|
|
@@ -8,6 +8,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
|
8
8
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
9
9
|
import * as v from 'valibot';
|
|
10
10
|
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
11
|
+
import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
|
|
11
12
|
const parameterLocation = v.enum({
|
|
12
13
|
query: 'query',
|
|
13
14
|
header: 'header',
|
|
@@ -23,18 +24,25 @@ const parameterStyle = v.enum({
|
|
|
23
24
|
pipeDelimited: 'pipeDelimited',
|
|
24
25
|
deepObject: 'deepObject'
|
|
25
26
|
});
|
|
26
|
-
export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
|
|
28
|
+
/**
|
|
29
|
+
* Path-level `parameters`: like {@link toParameterListV3}, but an entry
|
|
30
|
+
* that fails to parse is logged and returned in `broken` instead of
|
|
31
|
+
* throwing.
|
|
32
|
+
*/
|
|
33
|
+
export const toPathParameterListV3 = ({ parameters, stackTrail, context }) => toPathParameterList({
|
|
34
|
+
parameters,
|
|
35
|
+
stackTrail,
|
|
36
|
+
context,
|
|
37
|
+
toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
|
|
38
|
+
});
|
|
39
|
+
const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
|
|
40
|
+
if (isEmptyParameter(parameter)) {
|
|
41
|
+
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
42
|
+
return [];
|
|
29
43
|
}
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
44
|
+
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
45
|
+
});
|
|
38
46
|
export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
39
47
|
const output = {};
|
|
40
48
|
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
|
|
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;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toPathParameterListV3 } from '../parameter/toParameterV3.js';
|
|
2
2
|
import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
|
|
3
3
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
4
4
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
6
|
export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
7
7
|
const { summary, description, parameters, servers, ...skipped } = pathItem;
|
|
8
|
-
|
|
8
|
+
const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
|
|
9
|
+
const oasPathItem = new OasPathItem({
|
|
9
10
|
summary,
|
|
10
11
|
description,
|
|
11
|
-
parameters:
|
|
12
|
+
parameters: pathParameters.parameters,
|
|
12
13
|
servers: tryParseAt({
|
|
13
14
|
stackTrail,
|
|
14
15
|
key: 'servers',
|
|
@@ -25,4 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
|
25
26
|
parentType: 'pathItem'
|
|
26
27
|
})
|
|
27
28
|
});
|
|
29
|
+
return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
|
|
28
30
|
};
|
|
@@ -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
|
|
5
|
+
/** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
|
|
6
|
+
security: unknown;
|
|
6
7
|
stackTrail: StackTrail;
|
|
7
8
|
context: ParseContextType;
|
|
8
9
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
2
|
+
import { toSecurityRequirementObjects } from '../../securityRequirements.js';
|
|
2
3
|
export const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return security.map(requirement => {
|
|
4
|
+
return toSecurityRequirementObjects(security)?.map(requirement => {
|
|
7
5
|
return new OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
8
6
|
});
|
|
9
7
|
};
|
|
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
|
|
|
9
9
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
10
10
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
11
11
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
12
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
12
13
|
/**
|
|
13
14
|
* Parses a single webhook Operation Object into an {@link OasWebhook}.
|
|
14
15
|
*
|
|
@@ -85,9 +86,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
85
86
|
rest: pathItem,
|
|
86
87
|
methodObject: {}
|
|
87
88
|
});
|
|
88
|
-
const
|
|
89
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
89
90
|
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
|
|
90
91
|
: undefined;
|
|
92
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
93
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
91
94
|
return Object.entries(cleaned.methodObject)
|
|
92
95
|
.map(([method, operation]) => {
|
|
93
96
|
// Use `nameStack` (the trail with the webhook name already
|
|
@@ -97,6 +100,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
97
100
|
if (!operation) {
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
103
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
100
106
|
try {
|
|
101
107
|
return toWebhookV3({
|
|
102
108
|
operation,
|
|
@@ -7,6 +7,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
7
7
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
8
8
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
9
9
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
10
|
+
import { toOperationsWithValidSecurity, toSecurityCheck } from '../../securityRequirements.js';
|
|
10
11
|
export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
11
12
|
const { openapi, $self, info, paths, components, tags, servers, security, externalDocs, webhooks, ...skipped } = documentObject;
|
|
12
13
|
const extensionFields = toSpecificationExtensionsV3({
|
|
@@ -16,16 +17,29 @@ export const toDocumentFieldsV3 = ({ documentObject, stackTrail, context }) => {
|
|
|
16
17
|
stackTrail,
|
|
17
18
|
parentType: 'document'
|
|
18
19
|
});
|
|
20
|
+
const parsedInfo = stackTrail.trace('info', st => toInfoV3({ info, stackTrail: st, context }));
|
|
21
|
+
const parsedServers = stackTrail.trace('servers', st => toOptionalServersV3({ servers, stackTrail: st, context }));
|
|
22
|
+
const parsedOperations = stackTrail.trace('paths', st => toOperationsV3({ paths, stackTrail: st, context }));
|
|
23
|
+
const parsedWebhooks = stackTrail.trace('webhooks', st => toWebhooksV3({ webhooks, stackTrail: st, context }));
|
|
24
|
+
const parsedComponents = stackTrail.trace('components', st => toComponentsV3({ components, stackTrail: st, context }));
|
|
25
|
+
const parsedTags = stackTrail.trace('tags', st => toTagsV3({ tags, stackTrail: st, context }));
|
|
26
|
+
const securityCheck = stackTrail.trace('security', st => toSecurityCheck({
|
|
27
|
+
parse: () => toSecurityRequirementsV3({ security, stackTrail: st, context }),
|
|
28
|
+
declared: components?.securitySchemes,
|
|
29
|
+
parsed: parsedComponents?.securitySchemes,
|
|
30
|
+
stackTrail: st,
|
|
31
|
+
context
|
|
32
|
+
}));
|
|
19
33
|
return {
|
|
20
34
|
openapi,
|
|
21
35
|
$self,
|
|
22
|
-
info:
|
|
23
|
-
servers:
|
|
24
|
-
operations:
|
|
25
|
-
webhooks:
|
|
26
|
-
components:
|
|
27
|
-
tags:
|
|
28
|
-
security:
|
|
36
|
+
info: parsedInfo,
|
|
37
|
+
servers: parsedServers,
|
|
38
|
+
operations: toOperationsWithValidSecurity({ items: parsedOperations, check: securityCheck }),
|
|
39
|
+
webhooks: toOperationsWithValidSecurity({ items: parsedWebhooks, check: securityCheck }),
|
|
40
|
+
components: parsedComponents,
|
|
41
|
+
tags: parsedTags,
|
|
42
|
+
security: securityCheck.rootSecurity,
|
|
29
43
|
extensionFields,
|
|
30
44
|
externalDocs: stackTrail.trace('externalDocs', st => toExternalDocs({ externalDocs, stackTrail: st, context }))
|
|
31
45
|
};
|
|
@@ -2,7 +2,8 @@ import { toRequestBodyV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
|
2
2
|
import { toResponsesV3 } from '../response/toResponseV3.js';
|
|
3
3
|
import { toParameterListV3 } from '../parameter/toParameterV3.js';
|
|
4
4
|
import { OasOperation } from '../../../oas/operation/Operation.js';
|
|
5
|
-
import {
|
|
5
|
+
import { toPathItemV3 } from '../pathItem/toPathItemV3.js';
|
|
6
|
+
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
6
7
|
import { toPathItemMethod } from '../methods.js';
|
|
7
8
|
import { dropAdditionalOperationsV3 } from '../pathItem/dropAdditionalOperationsV3.js';
|
|
8
9
|
import { warnQuerystringConflictsV3 } from '../parameter/warnQuerystringConflictsV3.js';
|
|
@@ -10,6 +11,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
10
11
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
11
12
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
12
13
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
14
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
13
15
|
export const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
|
|
14
16
|
const { method, path, pathItem } = operationInfo;
|
|
15
17
|
const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
|
|
@@ -76,15 +78,11 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
76
78
|
rest: fixedFields,
|
|
77
79
|
methodObject: {}
|
|
78
80
|
});
|
|
79
|
-
const pathItemResult =
|
|
80
|
-
pathItem: cleaned.rest,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!pathItemResult.valid) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
const pathItemObject = pathItemResult.pathItem;
|
|
81
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
82
|
+
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
|
|
83
|
+
: undefined;
|
|
84
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
85
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
88
86
|
return Object.entries(cleaned.methodObject)
|
|
89
87
|
.map(([method, operation]) => {
|
|
90
88
|
// Use `pathStack` (the trail with `path` already pushed),
|
|
@@ -96,6 +94,9 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
96
94
|
if (!operation) {
|
|
97
95
|
return;
|
|
98
96
|
}
|
|
97
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
99
100
|
try {
|
|
100
101
|
return toOperationV3({
|
|
101
102
|
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;
|
|
@@ -9,31 +9,37 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
|
9
9
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
10
10
|
import * as v from 'valibot';
|
|
11
11
|
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
|
|
13
|
+
export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
|
|
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 const toPathParameterListV3 = ({ parameters, stackTrail, context }) => toPathParameterList({
|
|
20
|
+
parameters,
|
|
21
|
+
stackTrail,
|
|
22
|
+
context,
|
|
23
|
+
toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
|
|
24
|
+
});
|
|
25
|
+
const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => {
|
|
26
|
+
if (isEmptyParameter(parameter)) {
|
|
27
|
+
stackTrail.trace(`${index}`, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
28
|
+
return [];
|
|
15
29
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: 'INVALID_PARAMETER'
|
|
30
|
-
});
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
return [
|
|
34
|
-
stackTrail.trace(`${index}`, st => toParameterV3({ parameter, stackTrail: st, context }))
|
|
35
|
-
];
|
|
36
|
-
});
|
|
30
|
+
const querystringIssue = toQuerystringIssue(parameter);
|
|
31
|
+
if (querystringIssue) {
|
|
32
|
+
context.logIssue({
|
|
33
|
+
key: `${index}`,
|
|
34
|
+
parent: parameter,
|
|
35
|
+
level: 'error',
|
|
36
|
+
message: querystringIssue,
|
|
37
|
+
stackTrail,
|
|
38
|
+
type: 'INVALID_PARAMETER'
|
|
39
|
+
});
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return [stackTrail.trace(`${index}`, st => toParameterV3({ parameter, stackTrail: st, context }))];
|
|
37
43
|
};
|
|
38
44
|
/**
|
|
39
45
|
* A `querystring` parameter describes the whole query string, so it must
|
|
@@ -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,17 +8,9 @@ export type ToPathItemV3Args = {
|
|
|
7
8
|
stackTrail: StackTrail;
|
|
8
9
|
context: ParseContextType;
|
|
9
10
|
};
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} | {
|
|
15
|
-
valid: false;
|
|
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[];
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
* Parses a path item's shared fields without letting a throw escape. A
|
|
19
|
-
* path-level parameter that fails validation (for example `in: body`) logs
|
|
20
|
-
* one `INVALID_OPERATION` at the path and returns `{ valid: false }`, so
|
|
21
|
-
* the caller skips that path and keeps the rest.
|
|
22
|
-
*/
|
|
23
|
-
export declare const toPathItemResultV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemResult;
|
|
16
|
+
export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toPathParameterListV3 } from '../parameter/toParameterV3.js';
|
|
2
2
|
import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
|
|
3
3
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
4
4
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
|
-
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
7
6
|
export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
8
7
|
const { summary, description, parameters, servers, ...skipped } = pathItem;
|
|
9
|
-
|
|
8
|
+
const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
|
|
9
|
+
const oasPathItem = new OasPathItem({
|
|
10
10
|
summary,
|
|
11
11
|
description,
|
|
12
|
-
parameters:
|
|
12
|
+
parameters: pathParameters.parameters,
|
|
13
13
|
servers: tryParseAt({
|
|
14
14
|
stackTrail,
|
|
15
15
|
key: 'servers',
|
|
@@ -26,30 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
|
26
26
|
parentType: 'pathItem'
|
|
27
27
|
})
|
|
28
28
|
});
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Parses a path item's shared fields without letting a throw escape. A
|
|
32
|
-
* path-level parameter that fails validation (for example `in: body`) logs
|
|
33
|
-
* one `INVALID_OPERATION` at the path and returns `{ valid: false }`, so
|
|
34
|
-
* the caller skips that path and keeps the rest.
|
|
35
|
-
*/
|
|
36
|
-
export const toPathItemResultV3 = ({ pathItem, stackTrail, context }) => {
|
|
37
|
-
if (isEmpty(pathItem)) {
|
|
38
|
-
return { valid: true, pathItem: undefined };
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
return { valid: true, pathItem: toPathItemV3({ pathItem, stackTrail, context }) };
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
45
|
-
context.logIssueNoKey({
|
|
46
|
-
parent: pathItem,
|
|
47
|
-
level: 'error',
|
|
48
|
-
message: normalized.message,
|
|
49
|
-
cause: normalized,
|
|
50
|
-
stackTrail,
|
|
51
|
-
type: 'INVALID_OPERATION'
|
|
52
|
-
});
|
|
53
|
-
return { valid: false };
|
|
54
|
-
}
|
|
29
|
+
return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
|
|
55
30
|
};
|
|
@@ -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
|
|
5
|
+
/** Raw `security`; malformed input throws (see `toSecurityRequirementObjects`). */
|
|
6
|
+
security: unknown;
|
|
6
7
|
stackTrail: StackTrail;
|
|
7
8
|
context: ParseContextType;
|
|
8
9
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OasSecurityRequirement } from '../../../oas/securityRequirement/SecurityRequirement.js';
|
|
2
|
+
import { toSecurityRequirementObjects } from '../../securityRequirements.js';
|
|
2
3
|
export const toSecurityRequirementsV3 = ({ security, stackTrail, context }) => {
|
|
3
|
-
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return security.map(requirement => {
|
|
4
|
+
return toSecurityRequirementObjects(security)?.map(requirement => {
|
|
7
5
|
return new OasSecurityRequirement({ requirement }, context.oasDocument);
|
|
8
6
|
});
|
|
9
7
|
};
|