@skmtc/core 0.32.3 → 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/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-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-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/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/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-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-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
|
@@ -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
|
+
};
|
|
@@ -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)) {
|
|
@@ -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)) {
|
|
@@ -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)) {
|
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;
|
|
@@ -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 }) => {
|
|
@@ -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 }) => {
|
|
@@ -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 }) => {
|