@skmtc/core 0.32.2 → 0.33.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/generateTypes.d.ts +2 -2
- package/esm/context/generateTypes.js +2 -0
- package/esm/parse/emptyParameter.d.ts +16 -0
- package/esm/parse/emptyParameter.js +19 -0
- package/esm/parse/toPresentResponses.d.ts +19 -0
- package/esm/parse/toPresentResponses.js +27 -0
- package/esm/parse/v3-0/operation/toOperationsV3.js +1 -2
- package/esm/parse/v3-0/parameter/toParameterV3.js +12 -3
- package/esm/parse/v3-0/response/toResponseV3.d.ts +5 -1
- package/esm/parse/v3-0/response/toResponseV3.js +12 -1
- package/esm/parse/v3-0/server/toServerV3.js +16 -2
- package/esm/parse/v3-0/webhook/toWebhooksV3.js +1 -2
- package/esm/parse/v3-1/operation/toOperationsV3.js +1 -2
- package/esm/parse/v3-1/parameter/toParameterV3.js +12 -3
- package/esm/parse/v3-1/response/toResponseV3.d.ts +5 -1
- package/esm/parse/v3-1/response/toResponseV3.js +12 -1
- package/esm/parse/v3-1/server/toServerV3.js +16 -2
- package/esm/parse/v3-1/webhook/toWebhooksV3.js +1 -2
- package/esm/parse/v3-2/operation/toOperationsV3.js +1 -2
- package/esm/parse/v3-2/parameter/toParameterV3.js +9 -0
- package/esm/parse/v3-2/response/toResponseV3.d.ts +5 -1
- package/esm/parse/v3-2/response/toResponseV3.js +12 -1
- package/esm/parse/v3-2/server/toServerV3.js +16 -2
- package/esm/parse/v3-2/webhook/toWebhooksV3.js +1 -2
- package/package.json +1 -1
- package/script/context/generateTypes.d.ts +2 -2
- package/script/context/generateTypes.js +2 -0
- package/script/parse/emptyParameter.d.ts +16 -0
- package/script/parse/emptyParameter.js +24 -0
- package/script/parse/toPresentResponses.d.ts +19 -0
- package/script/parse/toPresentResponses.js +31 -0
- package/script/parse/v3-0/operation/toOperationsV3.js +1 -2
- package/script/parse/v3-0/parameter/toParameterV3.js +12 -3
- package/script/parse/v3-0/response/toResponseV3.d.ts +5 -1
- package/script/parse/v3-0/response/toResponseV3.js +13 -2
- package/script/parse/v3-0/server/toServerV3.js +16 -2
- package/script/parse/v3-0/webhook/toWebhooksV3.js +1 -2
- package/script/parse/v3-1/operation/toOperationsV3.js +1 -2
- package/script/parse/v3-1/parameter/toParameterV3.js +12 -3
- package/script/parse/v3-1/response/toResponseV3.d.ts +5 -1
- package/script/parse/v3-1/response/toResponseV3.js +13 -2
- package/script/parse/v3-1/server/toServerV3.js +16 -2
- package/script/parse/v3-1/webhook/toWebhooksV3.js +1 -2
- package/script/parse/v3-2/operation/toOperationsV3.js +1 -2
- package/script/parse/v3-2/parameter/toParameterV3.js +9 -0
- package/script/parse/v3-2/response/toResponseV3.d.ts +5 -1
- package/script/parse/v3-2/response/toResponseV3.js +13 -2
- package/script/parse/v3-2/server/toServerV3.js +16 -2
- package/script/parse/v3-2/webhook/toWebhooksV3.js +1 -2
|
@@ -167,7 +167,7 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
167
167
|
* scalar schema (a text body or a file). A body with only specific
|
|
168
168
|
* non-JSON types (`multipart/form-data`, `text/plain`) logs nothing.
|
|
169
169
|
*/
|
|
170
|
-
export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE';
|
|
170
|
+
export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE';
|
|
171
171
|
/**
|
|
172
172
|
* Valibot schema for {@link OasIssueType}. Annotation deliberately omitted
|
|
173
173
|
* so the precise literal-union output type flows through to consumers
|
|
@@ -175,7 +175,7 @@ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISS
|
|
|
175
175
|
* this list and {@link OasIssueType} is caught by `assertSchemaMatchesType`
|
|
176
176
|
* below.
|
|
177
177
|
*/
|
|
178
|
-
export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>], undefined>;
|
|
178
|
+
export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>], undefined>;
|
|
179
179
|
export type GenerateResult = {
|
|
180
180
|
files: Map<string, FileBase>;
|
|
181
181
|
previews: Record<string, Preview>;
|
|
@@ -12,6 +12,8 @@ export const oasIssueType = v.union([
|
|
|
12
12
|
v.literal('MISSING_STRING_TYPE'),
|
|
13
13
|
v.literal('MISSING_ARRAY_TYPE'),
|
|
14
14
|
v.literal('MISSING_BOOLEAN_TYPE'),
|
|
15
|
+
v.literal('MISSING_RESPONSES'),
|
|
16
|
+
v.literal('EMPTY_PARAMETER'),
|
|
15
17
|
v.literal('INVALID_EXAMPLE'),
|
|
16
18
|
v.literal('INVALID_ENUM'),
|
|
17
19
|
v.literal('INVALID_DEFAULT'),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
/**
|
|
4
|
+
* A parameter entry that carries no information: `null`, or a plain object
|
|
5
|
+
* with no own keys. Leaving it out cannot change how any operation renders.
|
|
6
|
+
* A `$ref` entry, or an entry with at least one key, is not empty.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isEmptyParameter: (parameter: unknown) => boolean;
|
|
9
|
+
export type LogEmptyParameterArgs = {
|
|
10
|
+
parameter: unknown;
|
|
11
|
+
/** Trail that ends in the entry's index or name. */
|
|
12
|
+
stackTrail: StackTrail;
|
|
13
|
+
context: ParseContextType;
|
|
14
|
+
};
|
|
15
|
+
/** Log the `EMPTY_PARAMETER` warning for an entry the parser leaves out. */
|
|
16
|
+
export declare const logEmptyParameter: ({ parameter, stackTrail, context }: LogEmptyParameterArgs) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A parameter entry that carries no information: `null`, or a plain object
|
|
3
|
+
* with no own keys. Leaving it out cannot change how any operation renders.
|
|
4
|
+
* A `$ref` entry, or an entry with at least one key, is not empty.
|
|
5
|
+
*/
|
|
6
|
+
export const isEmptyParameter = (parameter) => parameter === null ||
|
|
7
|
+
(typeof parameter === 'object' &&
|
|
8
|
+
!Array.isArray(parameter) &&
|
|
9
|
+
Object.keys(parameter).length === 0);
|
|
10
|
+
/** Log the `EMPTY_PARAMETER` warning for an entry the parser leaves out. */
|
|
11
|
+
export const logEmptyParameter = ({ parameter, stackTrail, context }) => {
|
|
12
|
+
context.logIssueNoKey({
|
|
13
|
+
stackTrail,
|
|
14
|
+
parent: parameter,
|
|
15
|
+
level: 'warning',
|
|
16
|
+
type: 'EMPTY_PARAMETER',
|
|
17
|
+
message: 'Empty parameter object; skipped'
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
export type ToPresentResponsesArgs<Responses extends object> = {
|
|
4
|
+
responses: Responses | null | undefined;
|
|
5
|
+
/** Trail that ends in the `responses` key. */
|
|
6
|
+
stackTrail: StackTrail;
|
|
7
|
+
context: ParseContextType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Check the `responses` field of an operation or webhook before its entries
|
|
11
|
+
* are parsed. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
12
|
+
*
|
|
13
|
+
* - Missing or `null`: logs one `MISSING_RESPONSES` warning and returns
|
|
14
|
+
* `undefined`. The caller reads it as no documented responses.
|
|
15
|
+
* - Not an object (an array, a string, a number): throws, so the operation
|
|
16
|
+
* is dropped as `INVALID_OPERATION` with a message that names `responses`.
|
|
17
|
+
* - Otherwise: returns `responses`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toPresentResponses: <Responses extends object>({ responses, stackTrail, context }: ToPresentResponsesArgs<Responses>) => Responses | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check the `responses` field of an operation or webhook before its entries
|
|
3
|
+
* are parsed. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
4
|
+
*
|
|
5
|
+
* - Missing or `null`: logs one `MISSING_RESPONSES` warning and returns
|
|
6
|
+
* `undefined`. The caller reads it as no documented responses.
|
|
7
|
+
* - Not an object (an array, a string, a number): throws, so the operation
|
|
8
|
+
* is dropped as `INVALID_OPERATION` with a message that names `responses`.
|
|
9
|
+
* - Otherwise: returns `responses`.
|
|
10
|
+
*/
|
|
11
|
+
export const toPresentResponses = ({ responses, stackTrail, context }) => {
|
|
12
|
+
if (responses === undefined || responses === null) {
|
|
13
|
+
context.logIssueNoKey({
|
|
14
|
+
stackTrail,
|
|
15
|
+
parent: undefined,
|
|
16
|
+
level: 'warning',
|
|
17
|
+
type: 'MISSING_RESPONSES',
|
|
18
|
+
message: 'Operation has no responses; read as no documented responses'
|
|
19
|
+
});
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (typeof responses !== 'object' || Array.isArray(responses)) {
|
|
23
|
+
const actual = Array.isArray(responses) ? 'an array' : typeof responses;
|
|
24
|
+
throw new Error(`"responses" must be an object of status codes, got ${actual}`);
|
|
25
|
+
}
|
|
26
|
+
return responses;
|
|
27
|
+
};
|
|
@@ -98,8 +98,7 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
98
98
|
}
|
|
99
99
|
catch (error) {
|
|
100
100
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
101
|
-
context.
|
|
102
|
-
key: method,
|
|
101
|
+
context.logIssueNoKey({
|
|
103
102
|
parent: operation,
|
|
104
103
|
level: 'error',
|
|
105
104
|
message: normalized.message,
|
|
@@ -7,6 +7,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
7
7
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
8
8
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
9
9
|
import * as v from 'valibot';
|
|
10
|
+
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
10
11
|
const parameterLocation = v.enum({
|
|
11
12
|
query: 'query',
|
|
12
13
|
header: 'header',
|
|
@@ -26,14 +27,22 @@ export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
|
26
27
|
if (!parameters) {
|
|
27
28
|
return undefined;
|
|
28
29
|
}
|
|
29
|
-
return parameters.
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
|
|
31
|
+
if (isEmptyParameter(parameter)) {
|
|
32
|
+
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
36
|
+
}));
|
|
32
37
|
};
|
|
33
38
|
export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
34
39
|
const output = {};
|
|
35
40
|
const entries = Object.entries(parameters);
|
|
36
41
|
for (const [key, parameter] of entries) {
|
|
42
|
+
if (isEmptyParameter(parameter)) {
|
|
43
|
+
stackTrail.trace(key, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
37
46
|
const parsed = tryParseAt({
|
|
38
47
|
stackTrail,
|
|
39
48
|
key,
|
|
@@ -4,10 +4,14 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
4
4
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
5
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
6
6
|
export type ToResponsesV3Args = {
|
|
7
|
-
responses
|
|
7
|
+
responses?: OpenAPIV3.ResponsesObject | null;
|
|
8
8
|
stackTrail: StackTrail;
|
|
9
9
|
context: ParseContextType;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
11
15
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
12
16
|
export type ToOptionalResponsesV3Args = {
|
|
13
17
|
responses: OpenAPIV3.ResponsesObject | undefined;
|
|
@@ -7,7 +7,18 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
8
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
9
9
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
10
|
+
import { toPresentResponses } from '../../toPresentResponses.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
10
15
|
export const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
16
|
+
const present = toPresentResponses({ responses, stackTrail, context });
|
|
17
|
+
return present === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
20
|
+
};
|
|
21
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
11
22
|
const output = {};
|
|
12
23
|
const entries = Object.entries(responses);
|
|
13
24
|
for (const [key, value] of entries) {
|
|
@@ -29,7 +40,7 @@ export const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
29
40
|
if (!responses) {
|
|
30
41
|
return undefined;
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
33
44
|
};
|
|
34
45
|
export const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
35
46
|
if (isRef(response)) {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { OasServer } from '../../../oas/server/Server.js';
|
|
2
2
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
3
3
|
import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
|
|
4
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
4
5
|
export const toServersV3 = ({ servers, stackTrail, context }) => {
|
|
5
|
-
return servers.
|
|
6
|
-
|
|
6
|
+
return servers.flatMap((server, index) => {
|
|
7
|
+
const parsed = tryParseAt({
|
|
8
|
+
stackTrail,
|
|
9
|
+
key: `${index}`,
|
|
10
|
+
context,
|
|
11
|
+
type: 'INVALID_OPERATION',
|
|
12
|
+
parent: servers,
|
|
13
|
+
fn: st => {
|
|
14
|
+
if (typeof server?.url !== 'string') {
|
|
15
|
+
throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
|
|
16
|
+
}
|
|
17
|
+
return toServerV3({ server, stackTrail: st, context });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return parsed ? [parsed] : [];
|
|
7
21
|
});
|
|
8
22
|
};
|
|
9
23
|
export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
|
|
@@ -111,8 +111,7 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
111
111
|
}
|
|
112
112
|
catch (error) {
|
|
113
113
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
114
|
-
context.
|
|
115
|
-
key: method,
|
|
114
|
+
context.logIssueNoKey({
|
|
116
115
|
parent: operation,
|
|
117
116
|
level: 'error',
|
|
118
117
|
message: normalized.message,
|
|
@@ -101,8 +101,7 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
101
101
|
}
|
|
102
102
|
catch (error) {
|
|
103
103
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
104
|
-
context.
|
|
105
|
-
key: method,
|
|
104
|
+
context.logIssueNoKey({
|
|
106
105
|
parent: operation,
|
|
107
106
|
level: 'error',
|
|
108
107
|
message: normalized.message,
|
|
@@ -7,6 +7,7 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
7
7
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
8
8
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
9
9
|
import * as v from 'valibot';
|
|
10
|
+
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
10
11
|
const parameterLocation = v.enum({
|
|
11
12
|
query: 'query',
|
|
12
13
|
header: 'header',
|
|
@@ -26,14 +27,22 @@ export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
|
26
27
|
if (!parameters) {
|
|
27
28
|
return undefined;
|
|
28
29
|
}
|
|
29
|
-
return parameters.
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
|
|
31
|
+
if (isEmptyParameter(parameter)) {
|
|
32
|
+
logEmptyParameter({ parameter, stackTrail: st, context });
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return [toParameterV3({ parameter, stackTrail: st, context })];
|
|
36
|
+
}));
|
|
32
37
|
};
|
|
33
38
|
export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
34
39
|
const output = {};
|
|
35
40
|
const entries = Object.entries(parameters);
|
|
36
41
|
for (const [key, parameter] of entries) {
|
|
42
|
+
if (isEmptyParameter(parameter)) {
|
|
43
|
+
stackTrail.trace(key, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
37
46
|
const parsed = tryParseAt({
|
|
38
47
|
stackTrail,
|
|
39
48
|
key,
|
|
@@ -4,10 +4,14 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
4
4
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
5
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
6
6
|
export type ToResponsesV3Args = {
|
|
7
|
-
responses
|
|
7
|
+
responses?: OpenAPIV3.ResponsesObject | null;
|
|
8
8
|
stackTrail: StackTrail;
|
|
9
9
|
context: ParseContextType;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
11
15
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
12
16
|
export type ToOptionalResponsesV3Args = {
|
|
13
17
|
responses: OpenAPIV3.ResponsesObject | undefined;
|
|
@@ -7,7 +7,18 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
8
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
9
9
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
10
|
+
import { toPresentResponses } from '../../toPresentResponses.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
10
15
|
export const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
16
|
+
const present = toPresentResponses({ responses, stackTrail, context });
|
|
17
|
+
return present === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
20
|
+
};
|
|
21
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
11
22
|
const output = {};
|
|
12
23
|
const entries = Object.entries(responses);
|
|
13
24
|
for (const [key, value] of entries) {
|
|
@@ -29,7 +40,7 @@ export const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
29
40
|
if (!responses) {
|
|
30
41
|
return undefined;
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
33
44
|
};
|
|
34
45
|
export const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
35
46
|
if (isRef(response)) {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { OasServer } from '../../../oas/server/Server.js';
|
|
2
2
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
3
3
|
import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
|
|
4
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
4
5
|
export const toServersV3 = ({ servers, stackTrail, context }) => {
|
|
5
|
-
return servers.
|
|
6
|
-
|
|
6
|
+
return servers.flatMap((server, index) => {
|
|
7
|
+
const parsed = tryParseAt({
|
|
8
|
+
stackTrail,
|
|
9
|
+
key: `${index}`,
|
|
10
|
+
context,
|
|
11
|
+
type: 'INVALID_OPERATION',
|
|
12
|
+
parent: servers,
|
|
13
|
+
fn: st => {
|
|
14
|
+
if (typeof server?.url !== 'string') {
|
|
15
|
+
throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
|
|
16
|
+
}
|
|
17
|
+
return toServerV3({ server, stackTrail: st, context });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return parsed ? [parsed] : [];
|
|
7
21
|
});
|
|
8
22
|
};
|
|
9
23
|
export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
|
|
@@ -111,8 +111,7 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
111
111
|
}
|
|
112
112
|
catch (error) {
|
|
113
113
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
114
|
-
context.
|
|
115
|
-
key: method,
|
|
114
|
+
context.logIssueNoKey({
|
|
116
115
|
parent: operation,
|
|
117
116
|
level: 'error',
|
|
118
117
|
message: normalized.message,
|
|
@@ -110,8 +110,7 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
110
110
|
}
|
|
111
111
|
catch (error) {
|
|
112
112
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
113
|
-
context.
|
|
114
|
-
key: method,
|
|
113
|
+
context.logIssueNoKey({
|
|
115
114
|
parent: operation,
|
|
116
115
|
level: 'error',
|
|
117
116
|
message: normalized.message,
|
|
@@ -8,11 +8,16 @@ import { toOptionalMediaTypeItemsV3 } from '../mediaType/toMediaTypeItemV3.js';
|
|
|
8
8
|
import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
9
9
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
10
10
|
import * as v from 'valibot';
|
|
11
|
+
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
11
12
|
export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
12
13
|
if (!parameters) {
|
|
13
14
|
return undefined;
|
|
14
15
|
}
|
|
15
16
|
return parameters.flatMap((parameter, index) => {
|
|
17
|
+
if (isEmptyParameter(parameter)) {
|
|
18
|
+
stackTrail.trace(`${index}`, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
16
21
|
const querystringIssue = toQuerystringIssue(parameter);
|
|
17
22
|
if (querystringIssue) {
|
|
18
23
|
context.logIssue({
|
|
@@ -49,6 +54,10 @@ export const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
|
49
54
|
const output = {};
|
|
50
55
|
const entries = Object.entries(parameters);
|
|
51
56
|
for (const [key, parameter] of entries) {
|
|
57
|
+
if (isEmptyParameter(parameter)) {
|
|
58
|
+
stackTrail.trace(key, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
52
61
|
const parsed = tryParseAt({
|
|
53
62
|
stackTrail,
|
|
54
63
|
key,
|
|
@@ -10,10 +10,14 @@ export type ResponseObjectV32 = OpenAPIV3.ResponseObject & {
|
|
|
10
10
|
/** A 3.2 Responses Object: status code to a 3.2 Response Object or a reference. */
|
|
11
11
|
export type ResponsesObjectV32 = Record<string, OpenAPIV3.ReferenceObject | ResponseObjectV32>;
|
|
12
12
|
export type ToResponsesV3Args = {
|
|
13
|
-
responses
|
|
13
|
+
responses?: ResponsesObjectV32 | null;
|
|
14
14
|
stackTrail: StackTrail;
|
|
15
15
|
context: ParseContextType;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
19
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
20
|
+
*/
|
|
17
21
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
18
22
|
export type ToOptionalResponsesV3Args = {
|
|
19
23
|
responses: ResponsesObjectV32 | undefined;
|
|
@@ -7,7 +7,18 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
7
7
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
8
8
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
9
9
|
import { logBodyMediaTypes } from '../../logBodyMediaTypes.js';
|
|
10
|
+
import { toPresentResponses } from '../../toPresentResponses.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
10
15
|
export const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
16
|
+
const present = toPresentResponses({ responses, stackTrail, context });
|
|
17
|
+
return present === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
20
|
+
};
|
|
21
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
11
22
|
const output = {};
|
|
12
23
|
const entries = Object.entries(responses);
|
|
13
24
|
for (const [key, value] of entries) {
|
|
@@ -29,7 +40,7 @@ export const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
29
40
|
if (!responses) {
|
|
30
41
|
return undefined;
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
33
44
|
};
|
|
34
45
|
export const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
35
46
|
if (isRef(response)) {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { OasServer } from '../../../oas/server/Server.js';
|
|
2
2
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
3
3
|
import { toOptionalServerVariablesV3 } from '../serverVariable/toServerVariableV3.js';
|
|
4
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
4
5
|
export const toServersV3 = ({ servers, stackTrail, context }) => {
|
|
5
|
-
return servers.
|
|
6
|
-
|
|
6
|
+
return servers.flatMap((server, index) => {
|
|
7
|
+
const parsed = tryParseAt({
|
|
8
|
+
stackTrail,
|
|
9
|
+
key: `${index}`,
|
|
10
|
+
context,
|
|
11
|
+
type: 'INVALID_OPERATION',
|
|
12
|
+
parent: servers,
|
|
13
|
+
fn: st => {
|
|
14
|
+
if (typeof server?.url !== 'string') {
|
|
15
|
+
throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
|
|
16
|
+
}
|
|
17
|
+
return toServerV3({ server, stackTrail: st, context });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return parsed ? [parsed] : [];
|
|
7
21
|
});
|
|
8
22
|
};
|
|
9
23
|
export const toOptionalServersV3 = ({ servers, stackTrail, context }) => {
|
|
@@ -120,8 +120,7 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
120
120
|
}
|
|
121
121
|
catch (error) {
|
|
122
122
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
123
|
-
context.
|
|
124
|
-
key: method,
|
|
123
|
+
context.logIssueNoKey({
|
|
125
124
|
parent: operation,
|
|
126
125
|
level: 'error',
|
|
127
126
|
message: normalized.message,
|
package/package.json
CHANGED
|
@@ -167,7 +167,7 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
167
167
|
* scalar schema (a text body or a file). A body with only specific
|
|
168
168
|
* non-JSON types (`multipart/form-data`, `text/plain`) logs nothing.
|
|
169
169
|
*/
|
|
170
|
-
export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE';
|
|
170
|
+
export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE';
|
|
171
171
|
/**
|
|
172
172
|
* Valibot schema for {@link OasIssueType}. Annotation deliberately omitted
|
|
173
173
|
* so the precise literal-union output type flows through to consumers
|
|
@@ -175,7 +175,7 @@ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISS
|
|
|
175
175
|
* this list and {@link OasIssueType} is caught by `assertSchemaMatchesType`
|
|
176
176
|
* below.
|
|
177
177
|
*/
|
|
178
|
-
export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>], undefined>;
|
|
178
|
+
export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>], undefined>;
|
|
179
179
|
export type GenerateResult = {
|
|
180
180
|
files: Map<string, FileBase>;
|
|
181
181
|
previews: Record<string, Preview>;
|
|
@@ -48,6 +48,8 @@ exports.oasIssueType = v.union([
|
|
|
48
48
|
v.literal('MISSING_STRING_TYPE'),
|
|
49
49
|
v.literal('MISSING_ARRAY_TYPE'),
|
|
50
50
|
v.literal('MISSING_BOOLEAN_TYPE'),
|
|
51
|
+
v.literal('MISSING_RESPONSES'),
|
|
52
|
+
v.literal('EMPTY_PARAMETER'),
|
|
51
53
|
v.literal('INVALID_EXAMPLE'),
|
|
52
54
|
v.literal('INVALID_ENUM'),
|
|
53
55
|
v.literal('INVALID_DEFAULT'),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
/**
|
|
4
|
+
* A parameter entry that carries no information: `null`, or a plain object
|
|
5
|
+
* with no own keys. Leaving it out cannot change how any operation renders.
|
|
6
|
+
* A `$ref` entry, or an entry with at least one key, is not empty.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isEmptyParameter: (parameter: unknown) => boolean;
|
|
9
|
+
export type LogEmptyParameterArgs = {
|
|
10
|
+
parameter: unknown;
|
|
11
|
+
/** Trail that ends in the entry's index or name. */
|
|
12
|
+
stackTrail: StackTrail;
|
|
13
|
+
context: ParseContextType;
|
|
14
|
+
};
|
|
15
|
+
/** Log the `EMPTY_PARAMETER` warning for an entry the parser leaves out. */
|
|
16
|
+
export declare const logEmptyParameter: ({ parameter, stackTrail, context }: LogEmptyParameterArgs) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logEmptyParameter = exports.isEmptyParameter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A parameter entry that carries no information: `null`, or a plain object
|
|
6
|
+
* with no own keys. Leaving it out cannot change how any operation renders.
|
|
7
|
+
* A `$ref` entry, or an entry with at least one key, is not empty.
|
|
8
|
+
*/
|
|
9
|
+
const isEmptyParameter = (parameter) => parameter === null ||
|
|
10
|
+
(typeof parameter === 'object' &&
|
|
11
|
+
!Array.isArray(parameter) &&
|
|
12
|
+
Object.keys(parameter).length === 0);
|
|
13
|
+
exports.isEmptyParameter = isEmptyParameter;
|
|
14
|
+
/** Log the `EMPTY_PARAMETER` warning for an entry the parser leaves out. */
|
|
15
|
+
const logEmptyParameter = ({ parameter, stackTrail, context }) => {
|
|
16
|
+
context.logIssueNoKey({
|
|
17
|
+
stackTrail,
|
|
18
|
+
parent: parameter,
|
|
19
|
+
level: 'warning',
|
|
20
|
+
type: 'EMPTY_PARAMETER',
|
|
21
|
+
message: 'Empty parameter object; skipped'
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.logEmptyParameter = logEmptyParameter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
|
+
export type ToPresentResponsesArgs<Responses extends object> = {
|
|
4
|
+
responses: Responses | null | undefined;
|
|
5
|
+
/** Trail that ends in the `responses` key. */
|
|
6
|
+
stackTrail: StackTrail;
|
|
7
|
+
context: ParseContextType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Check the `responses` field of an operation or webhook before its entries
|
|
11
|
+
* are parsed. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
12
|
+
*
|
|
13
|
+
* - Missing or `null`: logs one `MISSING_RESPONSES` warning and returns
|
|
14
|
+
* `undefined`. The caller reads it as no documented responses.
|
|
15
|
+
* - Not an object (an array, a string, a number): throws, so the operation
|
|
16
|
+
* is dropped as `INVALID_OPERATION` with a message that names `responses`.
|
|
17
|
+
* - Otherwise: returns `responses`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toPresentResponses: <Responses extends object>({ responses, stackTrail, context }: ToPresentResponsesArgs<Responses>) => Responses | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toPresentResponses = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check the `responses` field of an operation or webhook before its entries
|
|
6
|
+
* are parsed. Shared by the 3.0, 3.1 and 3.2 parsers.
|
|
7
|
+
*
|
|
8
|
+
* - Missing or `null`: logs one `MISSING_RESPONSES` warning and returns
|
|
9
|
+
* `undefined`. The caller reads it as no documented responses.
|
|
10
|
+
* - Not an object (an array, a string, a number): throws, so the operation
|
|
11
|
+
* is dropped as `INVALID_OPERATION` with a message that names `responses`.
|
|
12
|
+
* - Otherwise: returns `responses`.
|
|
13
|
+
*/
|
|
14
|
+
const toPresentResponses = ({ responses, stackTrail, context }) => {
|
|
15
|
+
if (responses === undefined || responses === null) {
|
|
16
|
+
context.logIssueNoKey({
|
|
17
|
+
stackTrail,
|
|
18
|
+
parent: undefined,
|
|
19
|
+
level: 'warning',
|
|
20
|
+
type: 'MISSING_RESPONSES',
|
|
21
|
+
message: 'Operation has no responses; read as no documented responses'
|
|
22
|
+
});
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
if (typeof responses !== 'object' || Array.isArray(responses)) {
|
|
26
|
+
const actual = Array.isArray(responses) ? 'an array' : typeof responses;
|
|
27
|
+
throw new Error(`"responses" must be an object of status codes, got ${actual}`);
|
|
28
|
+
}
|
|
29
|
+
return responses;
|
|
30
|
+
};
|
|
31
|
+
exports.toPresentResponses = toPresentResponses;
|
|
@@ -102,8 +102,7 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
104
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
105
|
-
context.
|
|
106
|
-
key: method,
|
|
105
|
+
context.logIssueNoKey({
|
|
107
106
|
parent: operation,
|
|
108
107
|
level: 'error',
|
|
109
108
|
message: normalized.message,
|
|
@@ -43,6 +43,7 @@ const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
|
|
|
43
43
|
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
|
+
const emptyParameter_js_1 = require("../../emptyParameter.js");
|
|
46
47
|
const parameterLocation = v.enum({
|
|
47
48
|
query: 'query',
|
|
48
49
|
header: 'header',
|
|
@@ -62,15 +63,23 @@ const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
|
62
63
|
if (!parameters) {
|
|
63
64
|
return undefined;
|
|
64
65
|
}
|
|
65
|
-
return parameters.
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
}));
|
|
68
73
|
};
|
|
69
74
|
exports.toParameterListV3 = toParameterListV3;
|
|
70
75
|
const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
71
76
|
const output = {};
|
|
72
77
|
const entries = Object.entries(parameters);
|
|
73
78
|
for (const [key, parameter] of entries) {
|
|
79
|
+
if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
|
|
80
|
+
stackTrail.trace(key, st => (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context }));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
74
83
|
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
75
84
|
stackTrail,
|
|
76
85
|
key,
|
|
@@ -4,10 +4,14 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
4
4
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
5
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
6
6
|
export type ToResponsesV3Args = {
|
|
7
|
-
responses
|
|
7
|
+
responses?: OpenAPIV3.ResponsesObject | null;
|
|
8
8
|
stackTrail: StackTrail;
|
|
9
9
|
context: ParseContextType;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
11
15
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
12
16
|
export type ToOptionalResponsesV3Args = {
|
|
13
17
|
responses: OpenAPIV3.ResponsesObject | undefined;
|
|
@@ -10,7 +10,19 @@ const Response_js_1 = require("../../../oas/response/Response.js");
|
|
|
10
10
|
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
11
11
|
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
12
12
|
const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
|
|
13
|
+
const toPresentResponses_js_1 = require("../../toPresentResponses.js");
|
|
14
|
+
/**
|
|
15
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
16
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
17
|
+
*/
|
|
13
18
|
const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
19
|
+
const present = (0, toPresentResponses_js_1.toPresentResponses)({ responses, stackTrail, context });
|
|
20
|
+
return present === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
23
|
+
};
|
|
24
|
+
exports.toResponsesV3 = toResponsesV3;
|
|
25
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
14
26
|
const output = {};
|
|
15
27
|
const entries = Object.entries(responses);
|
|
16
28
|
for (const [key, value] of entries) {
|
|
@@ -28,12 +40,11 @@ const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
28
40
|
}
|
|
29
41
|
return output;
|
|
30
42
|
};
|
|
31
|
-
exports.toResponsesV3 = toResponsesV3;
|
|
32
43
|
const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
33
44
|
if (!responses) {
|
|
34
45
|
return undefined;
|
|
35
46
|
}
|
|
36
|
-
return (
|
|
47
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
37
48
|
};
|
|
38
49
|
exports.toOptionalResponsesV3 = toOptionalResponsesV3;
|
|
39
50
|
const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
@@ -4,9 +4,23 @@ exports.toServerV3 = exports.toOptionalServersV3 = exports.toServersV3 = void 0;
|
|
|
4
4
|
const Server_js_1 = require("../../../oas/server/Server.js");
|
|
5
5
|
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
6
6
|
const toServerVariableV3_js_1 = require("../serverVariable/toServerVariableV3.js");
|
|
7
|
+
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
7
8
|
const toServersV3 = ({ servers, stackTrail, context }) => {
|
|
8
|
-
return servers.
|
|
9
|
-
|
|
9
|
+
return servers.flatMap((server, index) => {
|
|
10
|
+
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
11
|
+
stackTrail,
|
|
12
|
+
key: `${index}`,
|
|
13
|
+
context,
|
|
14
|
+
type: 'INVALID_OPERATION',
|
|
15
|
+
parent: servers,
|
|
16
|
+
fn: st => {
|
|
17
|
+
if (typeof server?.url !== 'string') {
|
|
18
|
+
throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
|
|
19
|
+
}
|
|
20
|
+
return (0, exports.toServerV3)({ server, stackTrail: st, context });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return parsed ? [parsed] : [];
|
|
10
24
|
});
|
|
11
25
|
};
|
|
12
26
|
exports.toServersV3 = toServersV3;
|
|
@@ -115,8 +115,7 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
117
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
118
|
-
context.
|
|
119
|
-
key: method,
|
|
118
|
+
context.logIssueNoKey({
|
|
120
119
|
parent: operation,
|
|
121
120
|
level: 'error',
|
|
122
121
|
message: normalized.message,
|
|
@@ -105,8 +105,7 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
105
105
|
}
|
|
106
106
|
catch (error) {
|
|
107
107
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
108
|
-
context.
|
|
109
|
-
key: method,
|
|
108
|
+
context.logIssueNoKey({
|
|
110
109
|
parent: operation,
|
|
111
110
|
level: 'error',
|
|
112
111
|
message: normalized.message,
|
|
@@ -43,6 +43,7 @@ const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
|
|
|
43
43
|
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
|
+
const emptyParameter_js_1 = require("../../emptyParameter.js");
|
|
46
47
|
const parameterLocation = v.enum({
|
|
47
48
|
query: 'query',
|
|
48
49
|
header: 'header',
|
|
@@ -62,15 +63,23 @@ const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
|
62
63
|
if (!parameters) {
|
|
63
64
|
return undefined;
|
|
64
65
|
}
|
|
65
|
-
return parameters.
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
}));
|
|
68
73
|
};
|
|
69
74
|
exports.toParameterListV3 = toParameterListV3;
|
|
70
75
|
const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
71
76
|
const output = {};
|
|
72
77
|
const entries = Object.entries(parameters);
|
|
73
78
|
for (const [key, parameter] of entries) {
|
|
79
|
+
if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
|
|
80
|
+
stackTrail.trace(key, st => (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context }));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
74
83
|
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
75
84
|
stackTrail,
|
|
76
85
|
key,
|
|
@@ -4,10 +4,14 @@ import { OasResponse } from '../../../oas/response/Response.js';
|
|
|
4
4
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
5
5
|
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
6
6
|
export type ToResponsesV3Args = {
|
|
7
|
-
responses
|
|
7
|
+
responses?: OpenAPIV3.ResponsesObject | null;
|
|
8
8
|
stackTrail: StackTrail;
|
|
9
9
|
context: ParseContextType;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
13
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
14
|
+
*/
|
|
11
15
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
12
16
|
export type ToOptionalResponsesV3Args = {
|
|
13
17
|
responses: OpenAPIV3.ResponsesObject | undefined;
|
|
@@ -10,7 +10,19 @@ const Response_js_1 = require("../../../oas/response/Response.js");
|
|
|
10
10
|
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
11
11
|
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
12
12
|
const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
|
|
13
|
+
const toPresentResponses_js_1 = require("../../toPresentResponses.js");
|
|
14
|
+
/**
|
|
15
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
16
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
17
|
+
*/
|
|
13
18
|
const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
19
|
+
const present = (0, toPresentResponses_js_1.toPresentResponses)({ responses, stackTrail, context });
|
|
20
|
+
return present === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
23
|
+
};
|
|
24
|
+
exports.toResponsesV3 = toResponsesV3;
|
|
25
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
14
26
|
const output = {};
|
|
15
27
|
const entries = Object.entries(responses);
|
|
16
28
|
for (const [key, value] of entries) {
|
|
@@ -28,12 +40,11 @@ const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
28
40
|
}
|
|
29
41
|
return output;
|
|
30
42
|
};
|
|
31
|
-
exports.toResponsesV3 = toResponsesV3;
|
|
32
43
|
const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
33
44
|
if (!responses) {
|
|
34
45
|
return undefined;
|
|
35
46
|
}
|
|
36
|
-
return (
|
|
47
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
37
48
|
};
|
|
38
49
|
exports.toOptionalResponsesV3 = toOptionalResponsesV3;
|
|
39
50
|
const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
@@ -4,9 +4,23 @@ exports.toServerV3 = exports.toOptionalServersV3 = exports.toServersV3 = void 0;
|
|
|
4
4
|
const Server_js_1 = require("../../../oas/server/Server.js");
|
|
5
5
|
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
6
6
|
const toServerVariableV3_js_1 = require("../serverVariable/toServerVariableV3.js");
|
|
7
|
+
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
7
8
|
const toServersV3 = ({ servers, stackTrail, context }) => {
|
|
8
|
-
return servers.
|
|
9
|
-
|
|
9
|
+
return servers.flatMap((server, index) => {
|
|
10
|
+
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
11
|
+
stackTrail,
|
|
12
|
+
key: `${index}`,
|
|
13
|
+
context,
|
|
14
|
+
type: 'INVALID_OPERATION',
|
|
15
|
+
parent: servers,
|
|
16
|
+
fn: st => {
|
|
17
|
+
if (typeof server?.url !== 'string') {
|
|
18
|
+
throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
|
|
19
|
+
}
|
|
20
|
+
return (0, exports.toServerV3)({ server, stackTrail: st, context });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return parsed ? [parsed] : [];
|
|
10
24
|
});
|
|
11
25
|
};
|
|
12
26
|
exports.toServersV3 = toServersV3;
|
|
@@ -115,8 +115,7 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
117
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
118
|
-
context.
|
|
119
|
-
key: method,
|
|
118
|
+
context.logIssueNoKey({
|
|
120
119
|
parent: operation,
|
|
121
120
|
level: 'error',
|
|
122
121
|
message: normalized.message,
|
|
@@ -114,8 +114,7 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
114
114
|
}
|
|
115
115
|
catch (error) {
|
|
116
116
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
117
|
-
context.
|
|
118
|
-
key: method,
|
|
117
|
+
context.logIssueNoKey({
|
|
119
118
|
parent: operation,
|
|
120
119
|
level: 'error',
|
|
121
120
|
message: normalized.message,
|
|
@@ -44,11 +44,16 @@ const toMediaTypeItemV3_js_1 = require("../mediaType/toMediaTypeItemV3.js");
|
|
|
44
44
|
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
|
+
const emptyParameter_js_1 = require("../../emptyParameter.js");
|
|
47
48
|
const toParameterListV3 = ({ parameters, stackTrail, context }) => {
|
|
48
49
|
if (!parameters) {
|
|
49
50
|
return undefined;
|
|
50
51
|
}
|
|
51
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
|
+
}
|
|
52
57
|
const querystringIssue = toQuerystringIssue(parameter);
|
|
53
58
|
if (querystringIssue) {
|
|
54
59
|
context.logIssue({
|
|
@@ -86,6 +91,10 @@ const toParametersV3 = ({ parameters, stackTrail, context }) => {
|
|
|
86
91
|
const output = {};
|
|
87
92
|
const entries = Object.entries(parameters);
|
|
88
93
|
for (const [key, parameter] of entries) {
|
|
94
|
+
if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
|
|
95
|
+
stackTrail.trace(key, st => (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context }));
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
89
98
|
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
90
99
|
stackTrail,
|
|
91
100
|
key,
|
|
@@ -10,10 +10,14 @@ export type ResponseObjectV32 = OpenAPIV3.ResponseObject & {
|
|
|
10
10
|
/** A 3.2 Responses Object: status code to a 3.2 Response Object or a reference. */
|
|
11
11
|
export type ResponsesObjectV32 = Record<string, OpenAPIV3.ReferenceObject | ResponseObjectV32>;
|
|
12
12
|
export type ToResponsesV3Args = {
|
|
13
|
-
responses
|
|
13
|
+
responses?: ResponsesObjectV32 | null;
|
|
14
14
|
stackTrail: StackTrail;
|
|
15
15
|
context: ParseContextType;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
19
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
20
|
+
*/
|
|
17
21
|
export declare const toResponsesV3: ({ responses, stackTrail, context }: ToResponsesV3Args) => Record<string, OasResponse | OasRef<"response">>;
|
|
18
22
|
export type ToOptionalResponsesV3Args = {
|
|
19
23
|
responses: ResponsesObjectV32 | undefined;
|
|
@@ -10,7 +10,19 @@ const Response_js_1 = require("../../../oas/response/Response.js");
|
|
|
10
10
|
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
11
11
|
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
12
12
|
const logBodyMediaTypes_js_1 = require("../../logBodyMediaTypes.js");
|
|
13
|
+
const toPresentResponses_js_1 = require("../../toPresentResponses.js");
|
|
14
|
+
/**
|
|
15
|
+
* Parses the `responses` of an operation or webhook. A missing or `null`
|
|
16
|
+
* `responses` reads as no documented responses; see {@link toPresentResponses}.
|
|
17
|
+
*/
|
|
13
18
|
const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
19
|
+
const present = (0, toPresentResponses_js_1.toPresentResponses)({ responses, stackTrail, context });
|
|
20
|
+
return present === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: toResponseEntriesV3({ responses: present, stackTrail, context });
|
|
23
|
+
};
|
|
24
|
+
exports.toResponsesV3 = toResponsesV3;
|
|
25
|
+
const toResponseEntriesV3 = ({ responses, stackTrail, context }) => {
|
|
14
26
|
const output = {};
|
|
15
27
|
const entries = Object.entries(responses);
|
|
16
28
|
for (const [key, value] of entries) {
|
|
@@ -28,12 +40,11 @@ const toResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
|
28
40
|
}
|
|
29
41
|
return output;
|
|
30
42
|
};
|
|
31
|
-
exports.toResponsesV3 = toResponsesV3;
|
|
32
43
|
const toOptionalResponsesV3 = ({ responses, stackTrail, context }) => {
|
|
33
44
|
if (!responses) {
|
|
34
45
|
return undefined;
|
|
35
46
|
}
|
|
36
|
-
return (
|
|
47
|
+
return toResponseEntriesV3({ responses, stackTrail, context });
|
|
37
48
|
};
|
|
38
49
|
exports.toOptionalResponsesV3 = toOptionalResponsesV3;
|
|
39
50
|
const toResponseV3 = ({ response, stackTrail, context }) => {
|
|
@@ -4,9 +4,23 @@ exports.toServerV3 = exports.toOptionalServersV3 = exports.toServersV3 = void 0;
|
|
|
4
4
|
const Server_js_1 = require("../../../oas/server/Server.js");
|
|
5
5
|
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
6
6
|
const toServerVariableV3_js_1 = require("../serverVariable/toServerVariableV3.js");
|
|
7
|
+
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
7
8
|
const toServersV3 = ({ servers, stackTrail, context }) => {
|
|
8
|
-
return servers.
|
|
9
|
-
|
|
9
|
+
return servers.flatMap((server, index) => {
|
|
10
|
+
const parsed = (0, tryParseAt_js_1.tryParseAt)({
|
|
11
|
+
stackTrail,
|
|
12
|
+
key: `${index}`,
|
|
13
|
+
context,
|
|
14
|
+
type: 'INVALID_OPERATION',
|
|
15
|
+
parent: servers,
|
|
16
|
+
fn: st => {
|
|
17
|
+
if (typeof server?.url !== 'string') {
|
|
18
|
+
throw new Error(`Expected a Server Object with a string url, got: ${JSON.stringify(server)}`);
|
|
19
|
+
}
|
|
20
|
+
return (0, exports.toServerV3)({ server, stackTrail: st, context });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return parsed ? [parsed] : [];
|
|
10
24
|
});
|
|
11
25
|
};
|
|
12
26
|
exports.toServersV3 = toServersV3;
|
|
@@ -124,8 +124,7 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
124
124
|
}
|
|
125
125
|
catch (error) {
|
|
126
126
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
127
|
-
context.
|
|
128
|
-
key: method,
|
|
127
|
+
context.logIssueNoKey({
|
|
129
128
|
parent: operation,
|
|
130
129
|
level: 'error',
|
|
131
130
|
message: normalized.message,
|