@skmtc/core 0.33.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.
- package/esm/context/CoreContext.d.ts +8 -21
- package/esm/context/CoreContext.js +9 -22
- package/esm/context/GenerateContext.js +7 -7
- package/esm/context/ParseContext.d.ts +1 -1
- package/esm/context/ParseContext.js +2 -2
- package/esm/context/StackTrail.d.ts +30 -13
- package/esm/context/StackTrail.js +36 -14
- package/esm/context/generateTypes.d.ts +2 -2
- package/esm/context/generateTypes.js +5 -0
- package/esm/helpers/ResultsLog.d.ts +19 -181
- package/esm/helpers/ResultsLog.js +46 -205
- package/esm/parse/descriptiveFields.d.ts +36 -0
- package/esm/parse/descriptiveFields.js +56 -0
- package/esm/parse/isPlainObject.d.ts +2 -0
- package/esm/parse/isPlainObject.js +2 -0
- package/esm/parse/toComponentEntries.d.ts +29 -0
- package/esm/parse/toComponentEntries.js +31 -0
- package/esm/parse/toPresentInfo.d.ts +30 -0
- package/esm/parse/toPresentInfo.js +40 -0
- package/esm/parse/v3-0/components/toComponentsV3.js +2 -2
- package/esm/parse/v3-0/externalDocs/toExternalDocs.d.ts +3 -1
- package/esm/parse/v3-0/externalDocs/toExternalDocs.js +9 -8
- package/esm/parse/v3-0/header/toHeadersV3.d.ts +12 -0
- package/esm/parse/v3-0/header/toHeadersV3.js +20 -0
- package/esm/parse/v3-0/info/toInfoV3.d.ts +2 -1
- package/esm/parse/v3-0/info/toInfoV3.js +15 -4
- package/esm/parse/v3-0/requestBody/toRequestBodiesV3.js +9 -9
- package/esm/parse/v3-0/tag/toTagsV3.js +7 -2
- package/esm/parse/v3-1/components/toComponentsV3.js +2 -2
- package/esm/parse/v3-1/externalDocs/toExternalDocs.d.ts +3 -1
- package/esm/parse/v3-1/externalDocs/toExternalDocs.js +9 -8
- package/esm/parse/v3-1/header/toHeadersV3.d.ts +12 -0
- package/esm/parse/v3-1/header/toHeadersV3.js +20 -0
- package/esm/parse/v3-1/info/toInfoV3.d.ts +2 -1
- package/esm/parse/v3-1/info/toInfoV3.js +15 -4
- package/esm/parse/v3-1/requestBody/toRequestBodiesV3.js +9 -9
- package/esm/parse/v3-1/tag/toTagsV3.js +7 -2
- package/esm/parse/v3-2/components/toComponentsV3.js +2 -2
- package/esm/parse/v3-2/externalDocs/toExternalDocs.d.ts +3 -1
- package/esm/parse/v3-2/externalDocs/toExternalDocs.js +9 -8
- package/esm/parse/v3-2/header/toHeadersV3.d.ts +12 -0
- package/esm/parse/v3-2/header/toHeadersV3.js +20 -0
- package/esm/parse/v3-2/info/toInfoV3.d.ts +2 -1
- package/esm/parse/v3-2/info/toInfoV3.js +15 -4
- package/esm/parse/v3-2/requestBody/toRequestBodiesV3.js +9 -9
- package/esm/parse/v3-2/tag/toTagsV3.js +14 -7
- package/package.json +1 -1
- package/script/context/CoreContext.d.ts +8 -21
- package/script/context/CoreContext.js +9 -22
- package/script/context/GenerateContext.js +7 -7
- package/script/context/ParseContext.d.ts +1 -1
- package/script/context/ParseContext.js +2 -2
- package/script/context/StackTrail.d.ts +30 -13
- package/script/context/StackTrail.js +36 -14
- package/script/context/generateTypes.d.ts +2 -2
- package/script/context/generateTypes.js +5 -0
- package/script/helpers/ResultsLog.d.ts +19 -181
- package/script/helpers/ResultsLog.js +46 -208
- package/script/parse/descriptiveFields.d.ts +36 -0
- package/script/parse/descriptiveFields.js +95 -0
- package/script/parse/isPlainObject.d.ts +2 -0
- package/script/parse/isPlainObject.js +6 -0
- package/script/parse/toComponentEntries.d.ts +29 -0
- package/script/parse/toComponentEntries.js +35 -0
- package/script/parse/toPresentInfo.d.ts +30 -0
- package/script/parse/toPresentInfo.js +45 -0
- package/script/parse/v3-0/components/toComponentsV3.js +1 -1
- package/script/parse/v3-0/externalDocs/toExternalDocs.d.ts +3 -1
- package/script/parse/v3-0/externalDocs/toExternalDocs.js +9 -41
- package/script/parse/v3-0/header/toHeadersV3.d.ts +12 -0
- package/script/parse/v3-0/header/toHeadersV3.js +22 -1
- package/script/parse/v3-0/info/toInfoV3.d.ts +2 -1
- package/script/parse/v3-0/info/toInfoV3.js +15 -4
- package/script/parse/v3-0/requestBody/toRequestBodiesV3.js +9 -9
- package/script/parse/v3-0/tag/toTagsV3.js +7 -2
- package/script/parse/v3-1/components/toComponentsV3.js +1 -1
- package/script/parse/v3-1/externalDocs/toExternalDocs.d.ts +3 -1
- package/script/parse/v3-1/externalDocs/toExternalDocs.js +9 -41
- package/script/parse/v3-1/header/toHeadersV3.d.ts +12 -0
- package/script/parse/v3-1/header/toHeadersV3.js +22 -1
- package/script/parse/v3-1/info/toInfoV3.d.ts +2 -1
- package/script/parse/v3-1/info/toInfoV3.js +15 -4
- package/script/parse/v3-1/requestBody/toRequestBodiesV3.js +9 -9
- package/script/parse/v3-1/tag/toTagsV3.js +7 -2
- package/script/parse/v3-2/components/toComponentsV3.js +1 -1
- package/script/parse/v3-2/externalDocs/toExternalDocs.d.ts +3 -1
- package/script/parse/v3-2/externalDocs/toExternalDocs.js +9 -41
- package/script/parse/v3-2/header/toHeadersV3.d.ts +12 -0
- package/script/parse/v3-2/header/toHeadersV3.js +22 -1
- package/script/parse/v3-2/info/toInfoV3.d.ts +2 -1
- package/script/parse/v3-2/info/toInfoV3.js +15 -4
- package/script/parse/v3-2/requestBody/toRequestBodiesV3.js +9 -9
- package/script/parse/v3-2/tag/toTagsV3.js +14 -7
|
@@ -2,22 +2,33 @@ import { OasInfo } from '../../../oas/info/Info.js';
|
|
|
2
2
|
import { toContactV3 } from '../contact/toContactV3.js';
|
|
3
3
|
import { toLicenseV3 } from '../license/toLicenseV3.js';
|
|
4
4
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
5
|
+
import { toInfoString, toPresentInfo } from '../../toPresentInfo.js';
|
|
5
6
|
export const toInfoV3 = ({ info, stackTrail, context }) => {
|
|
6
|
-
const
|
|
7
|
+
const presentInfo = toPresentInfo({ info, stackTrail, context });
|
|
8
|
+
if (presentInfo === undefined) {
|
|
9
|
+
return new OasInfo({ title: '', version: '' });
|
|
10
|
+
}
|
|
11
|
+
const { title, description, termsOfService, contact, license, version, ...skipped } = presentInfo;
|
|
7
12
|
const extensionFields = toSpecificationExtensionsV3({
|
|
8
13
|
skipped,
|
|
9
|
-
parent:
|
|
14
|
+
parent: presentInfo,
|
|
10
15
|
context,
|
|
11
16
|
stackTrail,
|
|
12
17
|
parentType: 'info'
|
|
13
18
|
});
|
|
14
19
|
return new OasInfo({
|
|
15
|
-
title,
|
|
20
|
+
title: toInfoString({ value: title, key: 'title', parent: presentInfo, stackTrail, context }),
|
|
16
21
|
description,
|
|
17
22
|
termsOfService,
|
|
18
23
|
contact: contact ? toContactV3(contact, stackTrail, context) : undefined,
|
|
19
24
|
license: license ? toLicenseV3(license, stackTrail, context) : undefined,
|
|
20
|
-
version
|
|
25
|
+
version: toInfoString({
|
|
26
|
+
value: version,
|
|
27
|
+
key: 'version',
|
|
28
|
+
parent: presentInfo,
|
|
29
|
+
stackTrail,
|
|
30
|
+
context
|
|
31
|
+
}),
|
|
21
32
|
extensionFields
|
|
22
33
|
});
|
|
23
34
|
};
|
|
@@ -4,6 +4,7 @@ import { toMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
4
4
|
import { OasRequestBody } from '../../../oas/requestBody/RequestBody.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
6
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
7
|
+
import { toComponentEntries } from '../../toComponentEntries.js';
|
|
7
8
|
export const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
|
|
8
9
|
if (!requestBody) {
|
|
9
10
|
return undefined;
|
|
@@ -35,13 +36,12 @@ export const toRequestBodiesV3 = ({ requestBodies, stackTrail, context }) => {
|
|
|
35
36
|
if (!requestBodies) {
|
|
36
37
|
return undefined;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return Object.fromEntries(entries);
|
|
39
|
+
return toComponentEntries({
|
|
40
|
+
entries: requestBodies,
|
|
41
|
+
stackTrail,
|
|
42
|
+
context,
|
|
43
|
+
type: 'INVALID_REQUEST_BODY',
|
|
44
|
+
label: 'Request body',
|
|
45
|
+
parse: ({ entry, stackTrail: st }) => toRequestBodyV3({ requestBody: entry, stackTrail: st, context })
|
|
46
|
+
});
|
|
47
47
|
};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { OasTag } from '../../../oas/tag/Tag.js';
|
|
2
2
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
3
3
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
4
|
+
import { isValidTag, toTagList } from '../../descriptiveFields.js';
|
|
4
5
|
export const toTagsV3 = ({ tags, stackTrail, context }) => {
|
|
5
|
-
if (
|
|
6
|
+
if (tags === undefined) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
// A malformed entry, or a `tags` that is not an array, is left out with a
|
|
10
|
+
// warning: tags do not change how an operation renders.
|
|
11
|
+
return toTagList({ tags, stackTrail, context })?.flatMap((tag, index) => stackTrail.trace(`${index}`, st => isValidTag({ tag, stackTrail: st, context })
|
|
12
|
+
? [toTagV3({ tag, stackTrail: st, context })]
|
|
13
|
+
: []));
|
|
9
14
|
};
|
|
10
15
|
export const toTagV3 = ({ tag, stackTrail, context }) => {
|
|
11
16
|
const { name, description, externalDocs, ...skipped } = tag;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
|
|
2
|
-
import {
|
|
2
|
+
import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
|
|
3
3
|
import { toLinksV3 } from '../link/toLinksV3.js';
|
|
4
4
|
import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
|
|
5
5
|
import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
|
|
@@ -32,7 +32,7 @@ export const toComponentsV3 = ({ components, stackTrail, context }) => {
|
|
|
32
32
|
context
|
|
33
33
|
}),
|
|
34
34
|
requestBodies: stackTrail.trace('requestBodies', st => toRequestBodiesV3({ requestBodies, stackTrail: st, context })),
|
|
35
|
-
headers: stackTrail.trace('headers', st =>
|
|
35
|
+
headers: stackTrail.trace('headers', st => toComponentHeadersV3({ headers, stackTrail: st, context })),
|
|
36
36
|
securitySchemes: stackTrail.trace('securitySchemes', st => toSecuritySchemesV3({ securitySchemes, stackTrail: st, context })),
|
|
37
37
|
links: stackTrail.trace('links', st => toLinksV3({ links, stackTrail: st, context })),
|
|
38
38
|
extensionFields
|
|
@@ -4,7 +4,9 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
|
4
4
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
5
5
|
export type ToExternalDocsArgs = {
|
|
6
6
|
externalDocs: OpenAPIV3.ExternalDocumentationObject | undefined;
|
|
7
|
+
/** Trail that ends in the `externalDocs` key. */
|
|
7
8
|
stackTrail: StackTrail;
|
|
8
9
|
context: ParseContextType;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
/** An invalid `externalDocs` is left out with a warning; its parent is kept. */
|
|
12
|
+
export declare const toExternalDocs: ({ externalDocs, stackTrail, context }: ToExternalDocsArgs) => OasExternalDocs | undefined;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { OasExternalDocs } from '../../../oas/externalDocs/ExternalDocs.js';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export const toExternalDocs = ({ externalDocs, stackTrail }) => {
|
|
5
|
-
if (
|
|
2
|
+
import { toValidExternalDocs } from '../../descriptiveFields.js';
|
|
3
|
+
/** An invalid `externalDocs` is left out with a warning; its parent is kept. */
|
|
4
|
+
export const toExternalDocs = ({ externalDocs, stackTrail, context }) => {
|
|
5
|
+
if (externalDocs === undefined) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const valid = toValidExternalDocs({ externalDocs, stackTrail, context });
|
|
9
|
+
if (!valid) {
|
|
10
|
+
return undefined;
|
|
10
11
|
}
|
|
11
12
|
return new OasExternalDocs({
|
|
12
|
-
url:
|
|
13
|
-
description:
|
|
13
|
+
url: valid.url,
|
|
14
|
+
description: valid.description
|
|
14
15
|
});
|
|
15
16
|
};
|
|
@@ -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` */
|
|
@@ -5,6 +5,7 @@ import { isRef } from '../../../helpers/refFns.js';
|
|
|
5
5
|
import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
6
6
|
import { OasHeader } from '../../../oas/header/Header.js';
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
|
+
import { toComponentEntries } from '../../toComponentEntries.js';
|
|
8
9
|
export const toHeadersV3 = ({ headers, stackTrail, context }) => {
|
|
9
10
|
if (!headers) {
|
|
10
11
|
return undefined;
|
|
@@ -16,6 +17,25 @@ export const toHeadersV3 = ({ headers, stackTrail, context }) => {
|
|
|
16
17
|
}
|
|
17
18
|
return output;
|
|
18
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Parse `components.headers`. Each entry parses inside its own boundary: a
|
|
22
|
+
* broken one is dropped with an INVALID_HEADER error, and the others are
|
|
23
|
+
* kept. Headers inside a response stay with {@link toHeadersV3}, where a
|
|
24
|
+
* broken header drops the response.
|
|
25
|
+
*/
|
|
26
|
+
export const toComponentHeadersV3 = ({ headers, stackTrail, context }) => {
|
|
27
|
+
if (!headers) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return toComponentEntries({
|
|
31
|
+
entries: headers,
|
|
32
|
+
stackTrail,
|
|
33
|
+
context,
|
|
34
|
+
type: 'INVALID_HEADER',
|
|
35
|
+
label: 'Header',
|
|
36
|
+
parse: ({ key, entry, stackTrail: st }) => toHeaderV3({ header: entry, name: key, stackTrail: st, context })
|
|
37
|
+
});
|
|
38
|
+
};
|
|
19
39
|
const toHeaderV3 = ({ header, name, stackTrail, context }) => {
|
|
20
40
|
if (isRef(header)) {
|
|
21
41
|
return 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
|
-
|
|
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
|
};
|
|
@@ -2,22 +2,33 @@ import { OasInfo } from '../../../oas/info/Info.js';
|
|
|
2
2
|
import { toContactV3 } from '../contact/toContactV3.js';
|
|
3
3
|
import { toLicenseV3 } from '../license/toLicenseV3.js';
|
|
4
4
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
5
|
+
import { toInfoString, toPresentInfo } from '../../toPresentInfo.js';
|
|
5
6
|
export const toInfoV3 = ({ info, stackTrail, context }) => {
|
|
6
|
-
const
|
|
7
|
+
const presentInfo = toPresentInfo({ info, stackTrail, context });
|
|
8
|
+
if (presentInfo === undefined) {
|
|
9
|
+
return new OasInfo({ title: '', version: '' });
|
|
10
|
+
}
|
|
11
|
+
const { title, description, termsOfService, contact, license, version, ...skipped } = presentInfo;
|
|
7
12
|
const extensionFields = toSpecificationExtensionsV3({
|
|
8
13
|
skipped,
|
|
9
|
-
parent:
|
|
14
|
+
parent: presentInfo,
|
|
10
15
|
context,
|
|
11
16
|
stackTrail,
|
|
12
17
|
parentType: 'info'
|
|
13
18
|
});
|
|
14
19
|
return new OasInfo({
|
|
15
|
-
title,
|
|
20
|
+
title: toInfoString({ value: title, key: 'title', parent: presentInfo, stackTrail, context }),
|
|
16
21
|
description,
|
|
17
22
|
termsOfService,
|
|
18
23
|
contact: contact ? toContactV3(contact, stackTrail, context) : undefined,
|
|
19
24
|
license: license ? toLicenseV3(license, stackTrail, context) : undefined,
|
|
20
|
-
version
|
|
25
|
+
version: toInfoString({
|
|
26
|
+
value: version,
|
|
27
|
+
key: 'version',
|
|
28
|
+
parent: presentInfo,
|
|
29
|
+
stackTrail,
|
|
30
|
+
context
|
|
31
|
+
}),
|
|
21
32
|
extensionFields
|
|
22
33
|
});
|
|
23
34
|
};
|
|
@@ -4,6 +4,7 @@ import { toMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
4
4
|
import { OasRequestBody } from '../../../oas/requestBody/RequestBody.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
6
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
7
|
+
import { toComponentEntries } from '../../toComponentEntries.js';
|
|
7
8
|
export const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
|
|
8
9
|
if (!requestBody) {
|
|
9
10
|
return undefined;
|
|
@@ -35,13 +36,12 @@ export const toRequestBodiesV3 = ({ requestBodies, stackTrail, context }) => {
|
|
|
35
36
|
if (!requestBodies) {
|
|
36
37
|
return undefined;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return Object.fromEntries(entries);
|
|
39
|
+
return toComponentEntries({
|
|
40
|
+
entries: requestBodies,
|
|
41
|
+
stackTrail,
|
|
42
|
+
context,
|
|
43
|
+
type: 'INVALID_REQUEST_BODY',
|
|
44
|
+
label: 'Request body',
|
|
45
|
+
parse: ({ entry, stackTrail: st }) => toRequestBodyV3({ requestBody: entry, stackTrail: st, context })
|
|
46
|
+
});
|
|
47
47
|
};
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { OasTag } from '../../../oas/tag/Tag.js';
|
|
2
2
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
3
3
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
4
|
+
import { isValidTag, toTagList } from '../../descriptiveFields.js';
|
|
4
5
|
export const toTagsV3 = ({ tags, stackTrail, context }) => {
|
|
5
|
-
if (
|
|
6
|
+
if (tags === undefined) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
// A malformed entry, or a `tags` that is not an array, is left out with a
|
|
10
|
+
// warning: tags do not change how an operation renders.
|
|
11
|
+
return toTagList({ tags, stackTrail, context })?.flatMap((tag, index) => stackTrail.trace(`${index}`, st => isValidTag({ tag, stackTrail: st, context })
|
|
12
|
+
? [toTagV3({ tag, stackTrail: st, context })]
|
|
13
|
+
: []));
|
|
9
14
|
};
|
|
10
15
|
export const toTagV3 = ({ tag, stackTrail, context }) => {
|
|
11
16
|
const { name, description, externalDocs, ...skipped } = tag;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
|
|
2
|
-
import {
|
|
2
|
+
import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
|
|
3
3
|
import { toLinksV3 } from '../link/toLinksV3.js';
|
|
4
4
|
import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
|
|
5
5
|
import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
|
|
@@ -34,7 +34,7 @@ export const toComponentsV3 = ({ components, stackTrail, context }) => {
|
|
|
34
34
|
context
|
|
35
35
|
}),
|
|
36
36
|
requestBodies: stackTrail.trace('requestBodies', st => toRequestBodiesV3({ requestBodies, stackTrail: st, context })),
|
|
37
|
-
headers: stackTrail.trace('headers', st =>
|
|
37
|
+
headers: stackTrail.trace('headers', st => toComponentHeadersV3({ headers, stackTrail: st, context })),
|
|
38
38
|
securitySchemes: stackTrail.trace('securitySchemes', st => toSecuritySchemesV3({ securitySchemes, stackTrail: st, context })),
|
|
39
39
|
links: stackTrail.trace('links', st => toLinksV3({ links, stackTrail: st, context })),
|
|
40
40
|
extensionFields
|
|
@@ -4,7 +4,9 @@ import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
|
4
4
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
5
5
|
export type ToExternalDocsArgs = {
|
|
6
6
|
externalDocs: OpenAPIV3.ExternalDocumentationObject | undefined;
|
|
7
|
+
/** Trail that ends in the `externalDocs` key. */
|
|
7
8
|
stackTrail: StackTrail;
|
|
8
9
|
context: ParseContextType;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
/** An invalid `externalDocs` is left out with a warning; its parent is kept. */
|
|
12
|
+
export declare const toExternalDocs: ({ externalDocs, stackTrail, context }: ToExternalDocsArgs) => OasExternalDocs | undefined;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { OasExternalDocs } from '../../../oas/externalDocs/ExternalDocs.js';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export const toExternalDocs = ({ externalDocs, stackTrail }) => {
|
|
5
|
-
if (
|
|
2
|
+
import { toValidExternalDocs } from '../../descriptiveFields.js';
|
|
3
|
+
/** An invalid `externalDocs` is left out with a warning; its parent is kept. */
|
|
4
|
+
export const toExternalDocs = ({ externalDocs, stackTrail, context }) => {
|
|
5
|
+
if (externalDocs === undefined) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const valid = toValidExternalDocs({ externalDocs, stackTrail, context });
|
|
9
|
+
if (!valid) {
|
|
10
|
+
return undefined;
|
|
10
11
|
}
|
|
11
12
|
return new OasExternalDocs({
|
|
12
|
-
url:
|
|
13
|
-
description:
|
|
13
|
+
url: valid.url,
|
|
14
|
+
description: valid.description
|
|
14
15
|
});
|
|
15
16
|
};
|
|
@@ -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` */
|
|
@@ -5,6 +5,7 @@ import { isRef } from '../../../helpers/refFns.js';
|
|
|
5
5
|
import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
6
6
|
import { OasHeader } from '../../../oas/header/Header.js';
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
|
+
import { toComponentEntries } from '../../toComponentEntries.js';
|
|
8
9
|
export const toHeadersV3 = ({ headers, stackTrail, context }) => {
|
|
9
10
|
if (!headers) {
|
|
10
11
|
return undefined;
|
|
@@ -16,6 +17,25 @@ export const toHeadersV3 = ({ headers, stackTrail, context }) => {
|
|
|
16
17
|
}
|
|
17
18
|
return output;
|
|
18
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Parse `components.headers`. Each entry parses inside its own boundary: a
|
|
22
|
+
* broken one is dropped with an INVALID_HEADER error, and the others are
|
|
23
|
+
* kept. Headers inside a response stay with {@link toHeadersV3}, where a
|
|
24
|
+
* broken header drops the response.
|
|
25
|
+
*/
|
|
26
|
+
export const toComponentHeadersV3 = ({ headers, stackTrail, context }) => {
|
|
27
|
+
if (!headers) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return toComponentEntries({
|
|
31
|
+
entries: headers,
|
|
32
|
+
stackTrail,
|
|
33
|
+
context,
|
|
34
|
+
type: 'INVALID_HEADER',
|
|
35
|
+
label: 'Header',
|
|
36
|
+
parse: ({ key, entry, stackTrail: st }) => toHeaderV3({ header: entry, name: key, stackTrail: st, context })
|
|
37
|
+
});
|
|
38
|
+
};
|
|
19
39
|
const toHeaderV3 = ({ header, name, stackTrail, context }) => {
|
|
20
40
|
if (isRef(header)) {
|
|
21
41
|
return 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
|
-
|
|
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
|
};
|
|
@@ -2,22 +2,33 @@ import { OasInfo } from '../../../oas/info/Info.js';
|
|
|
2
2
|
import { toContactV3 } from '../contact/toContactV3.js';
|
|
3
3
|
import { toLicenseV3 } from '../license/toLicenseV3.js';
|
|
4
4
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
5
|
+
import { toInfoString, toPresentInfo } from '../../toPresentInfo.js';
|
|
5
6
|
export const toInfoV3 = ({ info, stackTrail, context }) => {
|
|
6
|
-
const
|
|
7
|
+
const presentInfo = toPresentInfo({ info, stackTrail, context });
|
|
8
|
+
if (presentInfo === undefined) {
|
|
9
|
+
return new OasInfo({ title: '', version: '' });
|
|
10
|
+
}
|
|
11
|
+
const { title, description, termsOfService, contact, license, version, ...skipped } = presentInfo;
|
|
7
12
|
const extensionFields = toSpecificationExtensionsV3({
|
|
8
13
|
skipped,
|
|
9
|
-
parent:
|
|
14
|
+
parent: presentInfo,
|
|
10
15
|
context,
|
|
11
16
|
stackTrail,
|
|
12
17
|
parentType: 'info'
|
|
13
18
|
});
|
|
14
19
|
return new OasInfo({
|
|
15
|
-
title,
|
|
20
|
+
title: toInfoString({ value: title, key: 'title', parent: presentInfo, stackTrail, context }),
|
|
16
21
|
description,
|
|
17
22
|
termsOfService,
|
|
18
23
|
contact: contact ? toContactV3(contact, stackTrail, context) : undefined,
|
|
19
24
|
license: license ? toLicenseV3(license, stackTrail, context) : undefined,
|
|
20
|
-
version
|
|
25
|
+
version: toInfoString({
|
|
26
|
+
value: version,
|
|
27
|
+
key: 'version',
|
|
28
|
+
parent: presentInfo,
|
|
29
|
+
stackTrail,
|
|
30
|
+
context
|
|
31
|
+
}),
|
|
21
32
|
extensionFields
|
|
22
33
|
});
|
|
23
34
|
};
|
|
@@ -4,6 +4,7 @@ import { toMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
4
4
|
import { OasRequestBody } from '../../../oas/requestBody/RequestBody.js';
|
|
5
5
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
6
6
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
7
|
+
import { toComponentEntries } from '../../toComponentEntries.js';
|
|
7
8
|
export const toRequestBodyV3 = ({ requestBody, stackTrail, context }) => {
|
|
8
9
|
if (!requestBody) {
|
|
9
10
|
return undefined;
|
|
@@ -35,13 +36,12 @@ export const toRequestBodiesV3 = ({ requestBodies, stackTrail, context }) => {
|
|
|
35
36
|
if (!requestBodies) {
|
|
36
37
|
return undefined;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return Object.fromEntries(entries);
|
|
39
|
+
return toComponentEntries({
|
|
40
|
+
entries: requestBodies,
|
|
41
|
+
stackTrail,
|
|
42
|
+
context,
|
|
43
|
+
type: 'INVALID_REQUEST_BODY',
|
|
44
|
+
label: 'Request body',
|
|
45
|
+
parse: ({ entry, stackTrail: st }) => toRequestBodyV3({ requestBody: entry, stackTrail: st, context })
|
|
46
|
+
});
|
|
47
47
|
};
|
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
import { OasTag } from '../../../oas/tag/Tag.js';
|
|
2
2
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
3
3
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
4
|
+
import { isValidTag, toTagList } from '../../descriptiveFields.js';
|
|
4
5
|
export const toTagsV3 = ({ tags, stackTrail, context }) => {
|
|
5
|
-
if (
|
|
6
|
+
if (tags === undefined) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
// A malformed entry, or a `tags` that is not an array, is left out with a
|
|
10
|
+
// warning: tags do not change how an operation renders.
|
|
11
|
+
const validTags = toTagList({ tags, stackTrail, context })?.flatMap((tag, index) => stackTrail.trace(`${index}`, st => isValidTag({ tag, stackTrail: st, context }) ? [{ tag, index }] : []));
|
|
12
|
+
if (!validTags) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const parents = new Map(validTags.map(({ tag: { name, parent } }) => [name, parent]));
|
|
16
|
+
return validTags.map(({ tag, index }) => stackTrail.trace(`${index}`, st => {
|
|
10
17
|
const parentError = toParentError({ name: tag.name, parent: tag.parent, parents });
|
|
11
18
|
if (!parentError) {
|
|
12
|
-
return toTagV3({ tag, stackTrail, context });
|
|
19
|
+
return toTagV3({ tag, stackTrail: st, context });
|
|
13
20
|
}
|
|
14
21
|
context.logIssue({
|
|
15
22
|
key: 'parent',
|
|
16
23
|
level: 'warning',
|
|
17
24
|
message: `Tag '${tag.name}' ${parentError}; dropping 'parent'`,
|
|
18
25
|
parent: tag,
|
|
19
|
-
stackTrail,
|
|
26
|
+
stackTrail: st,
|
|
20
27
|
type: 'INVALID_TAG_PARENT'
|
|
21
28
|
});
|
|
22
|
-
return toTagV3({ tag: { ...tag, parent: undefined }, stackTrail, context });
|
|
23
|
-
});
|
|
29
|
+
return toTagV3({ tag: { ...tag, parent: undefined }, stackTrail: st, context });
|
|
30
|
+
}));
|
|
24
31
|
};
|
|
25
32
|
/** Describes why the tag's `parent` is invalid, or returns undefined when it is valid. */
|
|
26
33
|
const toParentError = ({ name, parent, parents }) => {
|
package/package.json
CHANGED
|
@@ -305,31 +305,18 @@ export declare class CoreContext {
|
|
|
305
305
|
parseIssues: ParseIssue[];
|
|
306
306
|
};
|
|
307
307
|
/**
|
|
308
|
-
* Captures a result at
|
|
309
|
-
*
|
|
310
|
-
* This method records processing results (success, warning, error, etc.) at the
|
|
311
|
-
* current location in the document traversal stack. Results are associated with
|
|
312
|
-
* the current stack trail position, enabling detailed error reporting and
|
|
313
|
-
* debugging of OpenAPI processing issues.
|
|
308
|
+
* Captures a result at `stackTrail`. Each frame of the trail becomes one
|
|
309
|
+
* level of the `manifest.results` tree.
|
|
314
310
|
*
|
|
315
311
|
* @param result - The type of result to capture (success, warning, error, etc.)
|
|
312
|
+
* @param stackTrail - The trail the result belongs to
|
|
316
313
|
*
|
|
317
|
-
* @example
|
|
318
|
-
* ```typescript
|
|
319
|
-
* context.captureCurrentResult('warning');
|
|
320
|
-
* // Result captured at current stack position like: "components.schemas.User.properties.email"
|
|
321
|
-
* ```
|
|
322
|
-
*
|
|
323
|
-
* @example Usage during schema processing
|
|
314
|
+
* @example
|
|
324
315
|
* ```typescript
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* } catch (error) {
|
|
330
|
-
* context.captureCurrentResult('error');
|
|
331
|
-
* }
|
|
332
|
-
* });
|
|
316
|
+
* stackTrail.trace(['/pets', 'get'], opTrail => {
|
|
317
|
+
* context.captureCurrentResult('success', opTrail)
|
|
318
|
+
* })
|
|
319
|
+
* // manifest.results: { …, '/pets': { get: 'success' } }
|
|
333
320
|
* ```
|
|
334
321
|
*/
|
|
335
322
|
captureCurrentResult(result: ResultType, stackTrail: StackTrail): void;
|
|
@@ -448,35 +448,22 @@ class CoreContext {
|
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
/**
|
|
451
|
-
* Captures a result at
|
|
452
|
-
*
|
|
453
|
-
* This method records processing results (success, warning, error, etc.) at the
|
|
454
|
-
* current location in the document traversal stack. Results are associated with
|
|
455
|
-
* the current stack trail position, enabling detailed error reporting and
|
|
456
|
-
* debugging of OpenAPI processing issues.
|
|
451
|
+
* Captures a result at `stackTrail`. Each frame of the trail becomes one
|
|
452
|
+
* level of the `manifest.results` tree.
|
|
457
453
|
*
|
|
458
454
|
* @param result - The type of result to capture (success, warning, error, etc.)
|
|
455
|
+
* @param stackTrail - The trail the result belongs to
|
|
459
456
|
*
|
|
460
|
-
* @example
|
|
461
|
-
* ```typescript
|
|
462
|
-
* context.captureCurrentResult('warning');
|
|
463
|
-
* // Result captured at current stack position like: "components.schemas.User.properties.email"
|
|
464
|
-
* ```
|
|
465
|
-
*
|
|
466
|
-
* @example Usage during schema processing
|
|
457
|
+
* @example
|
|
467
458
|
* ```typescript
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
* } catch (error) {
|
|
473
|
-
* context.captureCurrentResult('error');
|
|
474
|
-
* }
|
|
475
|
-
* });
|
|
459
|
+
* stackTrail.trace(['/pets', 'get'], opTrail => {
|
|
460
|
+
* context.captureCurrentResult('success', opTrail)
|
|
461
|
+
* })
|
|
462
|
+
* // manifest.results: { …, '/pets': { get: 'success' } }
|
|
476
463
|
* ```
|
|
477
464
|
*/
|
|
478
465
|
captureCurrentResult(result, stackTrail) {
|
|
479
|
-
__classPrivateFieldGet(this, _CoreContext_results, "f").capture(stackTrail
|
|
466
|
+
__classPrivateFieldGet(this, _CoreContext_results, "f").capture(stackTrail, result);
|
|
480
467
|
}
|
|
481
468
|
}
|
|
482
469
|
exports.CoreContext = CoreContext;
|