swagger-sdk-generator 0.0.0-stage → 3.0.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/README.md +58 -2
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.js +196 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +130 -0
- package/dist/cli/commands/inspect.d.ts +2 -0
- package/dist/cli/commands/inspect.js +164 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +126 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/context.js +85 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.js +82 -0
- package/dist/config/interpolate.d.ts +8 -0
- package/dist/config/interpolate.js +85 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +182 -0
- package/dist/config/migrate-v3.d.ts +5 -0
- package/dist/config/migrate-v3.js +6 -0
- package/dist/config/mode-compatibility.d.ts +9 -0
- package/dist/config/mode-compatibility.js +17 -0
- package/dist/config/modes.d.ts +13 -0
- package/dist/config/modes.js +27 -0
- package/dist/config/preset-definitions.d.ts +2 -0
- package/dist/config/preset-definitions.js +4 -0
- package/dist/config/presets.d.ts +25 -0
- package/dist/config/presets.js +36 -0
- package/dist/config/resolve.d.ts +32 -0
- package/dist/config/resolve.js +288 -0
- package/dist/config/schema.d.ts +93 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/types.d.ts +42 -0
- package/dist/config/types.js +2 -0
- package/dist/config/workspace.d.ts +30 -0
- package/dist/config/workspace.js +95 -0
- package/dist/core/case-align.d.ts +5 -0
- package/dist/core/case-align.js +90 -0
- package/dist/core/deep-merge.d.ts +2 -0
- package/dist/core/deep-merge.js +21 -0
- package/dist/core/file-set.d.ts +10 -0
- package/dist/core/file-set.js +31 -0
- package/dist/core/import-module.d.ts +1 -0
- package/dist/core/import-module.js +61 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +24 -0
- package/dist/core/manifest.d.ts +17 -0
- package/dist/core/manifest.js +195 -0
- package/dist/core/overlaps.d.ts +6 -0
- package/dist/core/overlaps.js +67 -0
- package/dist/core/package-version.d.ts +1 -0
- package/dist/core/package-version.js +44 -0
- package/dist/core/pipeline.d.ts +30 -0
- package/dist/core/pipeline.js +335 -0
- package/dist/core/plugin.d.ts +72 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/targets.d.ts +14 -0
- package/dist/core/targets.js +120 -0
- package/dist/core/unmanaged.d.ts +3 -0
- package/dist/core/unmanaged.js +101 -0
- package/dist/core/writer.d.ts +28 -0
- package/dist/core/writer.js +148 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +37 -0
- package/dist/ir/casing.d.ts +5 -0
- package/dist/ir/casing.js +22 -0
- package/dist/ir/graph.d.ts +8 -0
- package/dist/ir/graph.js +95 -0
- package/dist/ir/operations/grouping.d.ts +17 -0
- package/dist/ir/operations/grouping.js +39 -0
- package/dist/ir/operations/legacy-naming.d.ts +2 -0
- package/dist/ir/operations/legacy-naming.js +8 -0
- package/dist/ir/operations/naming.d.ts +6 -0
- package/dist/ir/operations/naming.js +54 -0
- package/dist/ir/option-errors.d.ts +3 -0
- package/dist/ir/option-errors.js +68 -0
- package/dist/ir/transforms/builtins.d.ts +2 -0
- package/dist/ir/transforms/builtins.js +4 -0
- package/dist/ir/transforms/index.d.ts +10 -0
- package/dist/ir/transforms/index.js +39 -0
- package/dist/ir/transforms/types.d.ts +9 -0
- package/dist/ir/transforms/types.js +2 -0
- package/dist/ir/types.d.ts +140 -0
- package/dist/ir/types.js +2 -0
- package/dist/runtime/axios.d.ts +28 -0
- package/dist/runtime/axios.js +132 -0
- package/dist/runtime/fetch.d.ts +6 -0
- package/dist/runtime/fetch.js +38 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +167 -0
- package/dist/runtime/rtk.d.ts +35 -0
- package/dist/runtime/rtk.js +36 -0
- package/dist/runtime/transport.d.ts +38 -0
- package/dist/runtime/transport.js +30 -0
- package/dist/runtime/wire.d.ts +27 -0
- package/dist/runtime/wire.js +148 -0
- package/dist/spec/html-entities.d.ts +1 -0
- package/dist/spec/html-entities.js +25 -0
- package/dist/spec/load.d.ts +26 -0
- package/dist/spec/load.js +130 -0
- package/dist/spec/openapi/all-of.d.ts +3 -0
- package/dist/spec/openapi/all-of.js +9 -0
- package/dist/spec/openapi/normalize.d.ts +4 -0
- package/dist/spec/openapi/normalize.js +31 -0
- package/dist/spec/openapi/operations.d.ts +4 -0
- package/dist/spec/openapi/operations.js +173 -0
- package/dist/spec/openapi/schema.d.ts +51 -0
- package/dist/spec/openapi/schema.js +307 -0
- package/dist/targets/declarative/config.d.ts +533 -0
- package/dist/targets/declarative/config.js +280 -0
- package/dist/targets/declarative/extensions.d.ts +45 -0
- package/dist/targets/declarative/extensions.js +123 -0
- package/dist/targets/declarative/files.d.ts +13 -0
- package/dist/targets/declarative/files.js +127 -0
- package/dist/targets/declarative/format.d.ts +4 -0
- package/dist/targets/declarative/format.js +104 -0
- package/dist/targets/declarative/index.d.ts +9 -0
- package/dist/targets/declarative/index.js +170 -0
- package/dist/targets/declarative/liquid.d.ts +8 -0
- package/dist/targets/declarative/liquid.js +57 -0
- package/dist/targets/declarative/naming-case.d.ts +3 -0
- package/dist/targets/declarative/naming-case.js +31 -0
- package/dist/targets/declarative/naming.d.ts +42 -0
- package/dist/targets/declarative/naming.js +174 -0
- package/dist/targets/declarative/scaffold.d.ts +5 -0
- package/dist/targets/declarative/scaffold.js +146 -0
- package/dist/targets/declarative/types.d.ts +52 -0
- package/dist/targets/declarative/types.js +287 -0
- package/dist/targets/declarative/views.d.ts +180 -0
- package/dist/targets/declarative/views.js +447 -0
- package/dist/targets/python/extensions.js +152 -0
- package/dist/targets/python/target.json +549 -0
- package/dist/targets/python/templates/client/client.liquid +114 -0
- package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
- package/dist/targets/python/templates/client/init.liquid +20 -0
- package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
- package/dist/targets/python/templates/client/resource.liquid +28 -0
- package/dist/targets/python/templates/client/runtime.liquid +133 -0
- package/dist/targets/python/templates/client/transport.liquid +62 -0
- package/dist/targets/python/templates/models/module.liquid +48 -0
- package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
- package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
- package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
- package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
- package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
- package/dist/targets/typescript/compatibility-naming.js +28 -0
- package/dist/targets/typescript/compatibility-options.d.ts +5 -0
- package/dist/targets/typescript/compatibility-options.js +8 -0
- package/dist/targets/typescript/compatibility-target.d.ts +5 -0
- package/dist/targets/typescript/compatibility-target.js +10 -0
- package/dist/targets/typescript/http-operations.d.ts +34 -0
- package/dist/targets/typescript/http-operations.js +155 -0
- package/dist/targets/typescript/imports.d.ts +43 -0
- package/dist/targets/typescript/imports.js +154 -0
- package/dist/targets/typescript/index.d.ts +7 -0
- package/dist/targets/typescript/index.js +52 -0
- package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
- package/dist/targets/typescript/mock-compatibility.js +6 -0
- package/dist/targets/typescript/mock-hints.d.ts +13 -0
- package/dist/targets/typescript/mock-hints.js +75 -0
- package/dist/targets/typescript/mock-reachability.d.ts +12 -0
- package/dist/targets/typescript/mock-reachability.js +87 -0
- package/dist/targets/typescript/model-compatibility.d.ts +14 -0
- package/dist/targets/typescript/model-compatibility.js +16 -0
- package/dist/targets/typescript/naming.d.ts +13 -0
- package/dist/targets/typescript/naming.js +50 -0
- package/dist/targets/typescript/options.d.ts +124 -0
- package/dist/targets/typescript/options.js +90 -0
- package/dist/targets/typescript/outputs/client.d.ts +67 -0
- package/dist/targets/typescript/outputs/client.js +187 -0
- package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
- package/dist/targets/typescript/outputs/mocks.js +371 -0
- package/dist/targets/typescript/outputs/models.d.ts +85 -0
- package/dist/targets/typescript/outputs/models.js +246 -0
- package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
- package/dist/targets/typescript/outputs/rtk-query.js +266 -0
- package/dist/targets/typescript/prettier.d.ts +7 -0
- package/dist/targets/typescript/prettier.js +44 -0
- package/dist/targets/typescript/templates/client/client.liquid +30 -0
- package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
- package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
- package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
- package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
- package/dist/targets/typescript/templates/client/resource.liquid +34 -0
- package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
- package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
- package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/models/alias.liquid +16 -0
- package/dist/targets/typescript/templates/models/enum.liquid +27 -0
- package/dist/targets/typescript/templates/models/index.liquid +14 -0
- package/dist/targets/typescript/templates/models/model.liquid +25 -0
- package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
- package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
- package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
- package/dist/targets/typescript/ts-type.d.ts +70 -0
- package/dist/targets/typescript/ts-type.js +62 -0
- package/dist/targets/typescript/type-printer.d.ts +21 -0
- package/dist/targets/typescript/type-printer.js +115 -0
- package/dist/templates/engine.d.ts +20 -0
- package/dist/templates/engine.js +161 -0
- package/dist/templates/inspect.d.ts +27 -0
- package/dist/templates/inspect.js +331 -0
- package/package.json +65 -4
- package/schema/sdk-gen.local.schema.json +75 -0
- package/schema/sdk-gen.schema.json +980 -0
- package/schema/sdk-gen.target.schema.json +1384 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'trace';
|
|
2
|
+
export type HttpResponseType = 'json' | 'text' | 'blob' | 'arraybuffer' | 'document' | 'stream';
|
|
3
|
+
export interface TransferProgress {
|
|
4
|
+
onUploadProgress?: (event: ProgressEvent) => void;
|
|
5
|
+
onDownloadProgress?: (event: ProgressEvent) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface HttpRequest extends TransferProgress {
|
|
8
|
+
operation: string;
|
|
9
|
+
method: HttpMethod;
|
|
10
|
+
path: string;
|
|
11
|
+
query?: Record<string, unknown>;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
contentType?: string;
|
|
15
|
+
responseType: HttpResponseType;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
export interface HttpResponse {
|
|
19
|
+
status: number;
|
|
20
|
+
headers: Record<string, string>;
|
|
21
|
+
data: unknown;
|
|
22
|
+
}
|
|
23
|
+
export type Transport = (request: HttpRequest) => Promise<HttpResponse>;
|
|
24
|
+
export declare class ApiError extends Error {
|
|
25
|
+
readonly response: HttpResponse;
|
|
26
|
+
readonly request: HttpRequest;
|
|
27
|
+
readonly status: number;
|
|
28
|
+
readonly data: unknown;
|
|
29
|
+
constructor(response: HttpResponse, request: HttpRequest);
|
|
30
|
+
}
|
|
31
|
+
export declare class NetworkError extends Error {
|
|
32
|
+
readonly cause: unknown;
|
|
33
|
+
constructor(cause: unknown);
|
|
34
|
+
}
|
|
35
|
+
export declare class RequestCancelledError extends Error {
|
|
36
|
+
readonly cause?: unknown;
|
|
37
|
+
constructor(cause?: unknown);
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestCancelledError = exports.NetworkError = exports.ApiError = void 0;
|
|
4
|
+
class ApiError extends Error {
|
|
5
|
+
constructor(response, request) {
|
|
6
|
+
super(`${request.method.toUpperCase()} ${request.path} failed with status ${response.status}`);
|
|
7
|
+
this.response = response;
|
|
8
|
+
this.request = request;
|
|
9
|
+
this.name = 'ApiError';
|
|
10
|
+
this.status = response.status;
|
|
11
|
+
this.data = response.data;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ApiError = ApiError;
|
|
15
|
+
class NetworkError extends Error {
|
|
16
|
+
constructor(cause) {
|
|
17
|
+
super('The SDK could not complete the HTTP request');
|
|
18
|
+
this.cause = cause;
|
|
19
|
+
this.name = 'NetworkError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.NetworkError = NetworkError;
|
|
23
|
+
class RequestCancelledError extends Error {
|
|
24
|
+
constructor(cause) {
|
|
25
|
+
super('The SDK request was cancelled');
|
|
26
|
+
this.cause = cause;
|
|
27
|
+
this.name = 'RequestCancelledError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.RequestCancelledError = RequestCancelledError;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpRequest } from './transport';
|
|
2
|
+
export declare function isSensitiveHeader(name: string): boolean;
|
|
3
|
+
export declare function redactRequest(request: HttpRequest): HttpRequest;
|
|
4
|
+
export declare function serializeQuery(query: Record<string, unknown>): string;
|
|
5
|
+
type EncodedBody = {
|
|
6
|
+
body: BodyInit | undefined;
|
|
7
|
+
contentType: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function encodeBody(body: unknown, contentType: string | undefined): EncodedBody;
|
|
10
|
+
export declare function setHeader(headers: Record<string, string>, name: string, value: string): void;
|
|
11
|
+
export declare function deleteHeader(headers: Record<string, string>, name: string): void;
|
|
12
|
+
export declare function isInstance(value: unknown, globalName: "FormData" | "Blob" | "URLSearchParams" | "ArrayBuffer"): boolean;
|
|
13
|
+
export interface HttpOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
getToken?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
serializeQuery?: (query: Record<string, unknown>) => string;
|
|
18
|
+
}
|
|
19
|
+
export declare function encodeRequest(request: HttpRequest, options: HttpOptions): Promise<{
|
|
20
|
+
url: string;
|
|
21
|
+
headers: {
|
|
22
|
+
[x: string]: string;
|
|
23
|
+
};
|
|
24
|
+
body: BodyInit | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function decodeText(text: string, kind: 'json' | 'text' | 'document', contentType?: string): unknown;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isSensitiveHeader = isSensitiveHeader;
|
|
13
|
+
exports.redactRequest = redactRequest;
|
|
14
|
+
exports.serializeQuery = serializeQuery;
|
|
15
|
+
exports.encodeBody = encodeBody;
|
|
16
|
+
exports.setHeader = setHeader;
|
|
17
|
+
exports.deleteHeader = deleteHeader;
|
|
18
|
+
exports.isInstance = isInstance;
|
|
19
|
+
exports.encodeRequest = encodeRequest;
|
|
20
|
+
exports.decodeText = decodeText;
|
|
21
|
+
const SENSITIVE_HEADERS = ["authorization", "proxy-authorization", "cookie", "set-cookie", "x-api-key", "api-key"];
|
|
22
|
+
function isSensitiveHeader(name) {
|
|
23
|
+
const lower = name.toLowerCase();
|
|
24
|
+
return SENSITIVE_HEADERS.includes(lower) || ["token", "secret", "password"].some((part) => lower.includes(part));
|
|
25
|
+
}
|
|
26
|
+
function redactRequest(request) {
|
|
27
|
+
if (!request.headers)
|
|
28
|
+
return request;
|
|
29
|
+
const headers = {};
|
|
30
|
+
for (const [name, value] of Object.entries(request.headers))
|
|
31
|
+
headers[name] = isSensitiveHeader(name) ? "[REDACTED]" : value;
|
|
32
|
+
return Object.assign(Object.assign({}, request), { headers });
|
|
33
|
+
}
|
|
34
|
+
function serializeQuery(query) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
const append = (key, value) => {
|
|
37
|
+
if (value === undefined || value === null)
|
|
38
|
+
return;
|
|
39
|
+
const text = value instanceof Date ? value.toISOString() : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
40
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(text)}`);
|
|
41
|
+
};
|
|
42
|
+
for (const [key, value] of Object.entries(query)) {
|
|
43
|
+
if (Array.isArray(value))
|
|
44
|
+
value.forEach((item) => append(key, item));
|
|
45
|
+
else
|
|
46
|
+
append(key, value);
|
|
47
|
+
}
|
|
48
|
+
return parts.join("&");
|
|
49
|
+
}
|
|
50
|
+
function encodeBody(body, contentType) {
|
|
51
|
+
if (body === undefined)
|
|
52
|
+
return { body: undefined, contentType: undefined };
|
|
53
|
+
if (isInstance(body, "FormData"))
|
|
54
|
+
return { body: body, contentType: undefined };
|
|
55
|
+
if (typeof body === "string")
|
|
56
|
+
return { body: isJsonMediaType(contentType) ? JSON.stringify(body) : body, contentType };
|
|
57
|
+
if (isInstance(body, "Blob") ||
|
|
58
|
+
isInstance(body, "URLSearchParams") ||
|
|
59
|
+
isInstance(body, "ArrayBuffer") ||
|
|
60
|
+
ArrayBuffer.isView(body)) {
|
|
61
|
+
return { body: body, contentType };
|
|
62
|
+
}
|
|
63
|
+
const type = (contentType !== null && contentType !== void 0 ? contentType : "").toLowerCase();
|
|
64
|
+
if (type.startsWith("multipart/form-data"))
|
|
65
|
+
return { body: toFormData(body), contentType: undefined };
|
|
66
|
+
if (type.startsWith("application/x-www-form-urlencoded")) {
|
|
67
|
+
return { body: serializeQuery(body), contentType };
|
|
68
|
+
}
|
|
69
|
+
if (type.startsWith("text/"))
|
|
70
|
+
return { body: String(body), contentType };
|
|
71
|
+
return { body: JSON.stringify(body), contentType: contentType !== null && contentType !== void 0 ? contentType : "application/json" };
|
|
72
|
+
}
|
|
73
|
+
function isJsonMediaType(contentType) {
|
|
74
|
+
const type = (contentType !== null && contentType !== void 0 ? contentType : "").split(";")[0].trim().toLowerCase();
|
|
75
|
+
return type === "application/json" || /^[a-z]+\/[^/]+\+json$/.test(type);
|
|
76
|
+
}
|
|
77
|
+
function toFormData(body) {
|
|
78
|
+
const form = new FormData();
|
|
79
|
+
const append = (key, value) => {
|
|
80
|
+
if (value === undefined || value === null)
|
|
81
|
+
return;
|
|
82
|
+
if (isInstance(value, "Blob"))
|
|
83
|
+
form.append(key, value);
|
|
84
|
+
else if (value instanceof Date)
|
|
85
|
+
form.append(key, value.toISOString());
|
|
86
|
+
else
|
|
87
|
+
form.append(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
88
|
+
};
|
|
89
|
+
for (const [key, value] of Object.entries(body)) {
|
|
90
|
+
if (Array.isArray(value))
|
|
91
|
+
value.forEach((item) => append(key, item));
|
|
92
|
+
else
|
|
93
|
+
append(key, value);
|
|
94
|
+
}
|
|
95
|
+
return form;
|
|
96
|
+
}
|
|
97
|
+
function setHeader(headers, name, value) {
|
|
98
|
+
deleteHeader(headers, name);
|
|
99
|
+
headers[name] = value;
|
|
100
|
+
}
|
|
101
|
+
function deleteHeader(headers, name) {
|
|
102
|
+
const lower = name.toLowerCase();
|
|
103
|
+
for (const key of Object.keys(headers))
|
|
104
|
+
if (key.toLowerCase() === lower)
|
|
105
|
+
delete headers[key];
|
|
106
|
+
}
|
|
107
|
+
function isInstance(value, globalName) {
|
|
108
|
+
const ctor = globalThis[globalName];
|
|
109
|
+
return typeof ctor === "function" && value instanceof ctor;
|
|
110
|
+
}
|
|
111
|
+
function encodeRequest(request, options) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
var _a;
|
|
114
|
+
var _b, _c;
|
|
115
|
+
const query = request.query ? ((_b = options.serializeQuery) !== null && _b !== void 0 ? _b : serializeQuery)(request.query).replace(/^\?/, '') : '';
|
|
116
|
+
const url = `${options.baseUrl.replace(/\/+$/, '')}${request.path}${query ? `?${query}` : ''}`;
|
|
117
|
+
const { body, contentType } = encodeBody(request.body, request.contentType);
|
|
118
|
+
const headers = Object.assign({}, options.headers);
|
|
119
|
+
if (contentType)
|
|
120
|
+
setHeader(headers, 'Content-Type', contentType);
|
|
121
|
+
const token = yield (_a = options.getToken) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
122
|
+
if (token)
|
|
123
|
+
setHeader(headers, 'Authorization', `Bearer ${token}`);
|
|
124
|
+
for (const [name, value] of Object.entries((_c = request.headers) !== null && _c !== void 0 ? _c : {}))
|
|
125
|
+
setHeader(headers, name, value);
|
|
126
|
+
if (isInstance(body, 'FormData'))
|
|
127
|
+
deleteHeader(headers, 'Content-Type');
|
|
128
|
+
return { url, headers, body };
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function decodeText(text, kind, contentType) {
|
|
132
|
+
var _a;
|
|
133
|
+
if (kind === 'text')
|
|
134
|
+
return text;
|
|
135
|
+
if (kind === 'document') {
|
|
136
|
+
const mediaType = (_a = contentType === null || contentType === void 0 ? void 0 : contentType.split(';', 1)[0]) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
|
|
137
|
+
const syntax = (mediaType === null || mediaType === void 0 ? void 0 : mediaType.includes('xml')) ? 'application/xml' : 'text/html';
|
|
138
|
+
return new DOMParser().parseFromString(text, syntax);
|
|
139
|
+
}
|
|
140
|
+
if (!text)
|
|
141
|
+
return undefined;
|
|
142
|
+
try {
|
|
143
|
+
return JSON.parse(text);
|
|
144
|
+
}
|
|
145
|
+
catch (_b) {
|
|
146
|
+
return text;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function decodeHtmlEntities(input: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeHtmlEntities = decodeHtmlEntities;
|
|
4
|
+
function decodeHtmlEntities(input) {
|
|
5
|
+
if (!input)
|
|
6
|
+
return input;
|
|
7
|
+
let result = input.replace(/&[a-z]+;/g, (match) => {
|
|
8
|
+
const entities = {
|
|
9
|
+
'&': '&',
|
|
10
|
+
'<': '<',
|
|
11
|
+
'>': '>',
|
|
12
|
+
'"': '"',
|
|
13
|
+
''': "'",
|
|
14
|
+
' ': ' '
|
|
15
|
+
};
|
|
16
|
+
return entities[match] || match;
|
|
17
|
+
});
|
|
18
|
+
result = result.replace(/&#x([0-9a-f]+);/gi, (match, hex) => {
|
|
19
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
20
|
+
});
|
|
21
|
+
result = result.replace(/&#(\d+);/g, (match, dec) => {
|
|
22
|
+
return String.fromCharCode(parseInt(dec, 10));
|
|
23
|
+
});
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SpecInput } from '../config/types';
|
|
2
|
+
export interface OpenApiDocument {
|
|
3
|
+
openapi: string;
|
|
4
|
+
info: {
|
|
5
|
+
title?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
[k: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
servers?: Array<{
|
|
11
|
+
url: string;
|
|
12
|
+
[k: string]: unknown;
|
|
13
|
+
}>;
|
|
14
|
+
paths?: Record<string, any>;
|
|
15
|
+
components?: {
|
|
16
|
+
schemas?: Record<string, any>;
|
|
17
|
+
parameters?: Record<string, any>;
|
|
18
|
+
requestBodies?: Record<string, any>;
|
|
19
|
+
responses?: Record<string, any>;
|
|
20
|
+
[k: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
[k: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
export declare function loadSpec(input: SpecInput): Promise<OpenApiDocument>;
|
|
25
|
+
export declare function parseSpec(text: string, where: string): OpenApiDocument;
|
|
26
|
+
export declare function undecodedDocument(document: OpenApiDocument): unknown;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.loadSpec = loadSpec;
|
|
46
|
+
exports.parseSpec = parseSpec;
|
|
47
|
+
exports.undecodedDocument = undecodedDocument;
|
|
48
|
+
const fs = __importStar(require("fs-extra"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const yaml_1 = require("yaml");
|
|
51
|
+
const html_entities_1 = require("./html-entities");
|
|
52
|
+
function loadSpec(input) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const text = input.kind === 'url' ? yield fetchText(input.url, input.headers) : yield readText(input.path);
|
|
55
|
+
const where = input.kind === 'url' ? input.url : input.path;
|
|
56
|
+
return parseSpec(text, where);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function parseSpec(text, where) {
|
|
60
|
+
let data;
|
|
61
|
+
try {
|
|
62
|
+
data = JSON.parse(text);
|
|
63
|
+
}
|
|
64
|
+
catch (_a) {
|
|
65
|
+
try {
|
|
66
|
+
data = (0, yaml_1.parse)(text);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error(`${where}: not valid JSON or YAML (${error instanceof Error ? error.message : error})`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const document = validate(decodeDeep(data), where);
|
|
73
|
+
undecoded.set(document, data);
|
|
74
|
+
return document;
|
|
75
|
+
}
|
|
76
|
+
const undecoded = new WeakMap();
|
|
77
|
+
function undecodedDocument(document) {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = undecoded.get(document)) !== null && _a !== void 0 ? _a : document;
|
|
80
|
+
}
|
|
81
|
+
function fetchText(url, headers) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
let response;
|
|
84
|
+
try {
|
|
85
|
+
response = yield fetch(url, { headers: Object.assign({ Accept: 'application/json, application/yaml;q=0.9, */*;q=0.5' }, headers) });
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new Error(`Failed to fetch ${url}: ${error instanceof Error ? error.message : error}`);
|
|
89
|
+
}
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error(`Failed to fetch ${url}: HTTP ${response.status} ${response.statusText}`);
|
|
92
|
+
}
|
|
93
|
+
return response.text();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function readText(file) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const abs = path.resolve(file);
|
|
99
|
+
if (!(yield fs.pathExists(abs)))
|
|
100
|
+
throw new Error(`Spec file not found: ${abs}`);
|
|
101
|
+
return fs.readFile(abs, 'utf8');
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function validate(doc, where) {
|
|
105
|
+
var _a;
|
|
106
|
+
if (!doc || typeof doc !== 'object')
|
|
107
|
+
throw new Error(`${where}: spec is not an object`);
|
|
108
|
+
if (doc.swagger) {
|
|
109
|
+
throw new Error(`${where}: Swagger ${doc.swagger} is not supported — convert to OpenAPI 3.x first`);
|
|
110
|
+
}
|
|
111
|
+
if (typeof doc.openapi !== 'string' || !doc.openapi.startsWith('3.')) {
|
|
112
|
+
throw new Error(`${where}: unsupported or missing "openapi" version (${(_a = doc.openapi) !== null && _a !== void 0 ? _a : 'none'}); only 3.x is supported`);
|
|
113
|
+
}
|
|
114
|
+
if (!doc.info || typeof doc.info !== 'object')
|
|
115
|
+
doc.info = {};
|
|
116
|
+
return doc;
|
|
117
|
+
}
|
|
118
|
+
function decodeDeep(value) {
|
|
119
|
+
if (typeof value === 'string')
|
|
120
|
+
return (0, html_entities_1.decodeHtmlEntities)(value);
|
|
121
|
+
if (Array.isArray(value))
|
|
122
|
+
return value.map(decodeDeep);
|
|
123
|
+
if (value && typeof value === 'object') {
|
|
124
|
+
const out = {};
|
|
125
|
+
for (const [k, v] of Object.entries(value))
|
|
126
|
+
out[k] = decodeDeep(v);
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ALLOF_MODE = exports.ALLOF_MODES = void 0;
|
|
4
|
+
exports.flattenModelSchema = flattenModelSchema;
|
|
5
|
+
exports.ALLOF_MODES = ['intersection'];
|
|
6
|
+
exports.DEFAULT_ALLOF_MODE = 'intersection';
|
|
7
|
+
function flattenModelSchema(_schema, _context, _hasEnum) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOpenApi = normalizeOpenApi;
|
|
4
|
+
const all_of_1 = require("./all-of");
|
|
5
|
+
const operations_1 = require("./operations");
|
|
6
|
+
const schema_1 = require("./schema");
|
|
7
|
+
function normalizeOpenApi(doc, options = {}) {
|
|
8
|
+
var _a;
|
|
9
|
+
var _b, _c;
|
|
10
|
+
const schemas = (_b = (0, schema_1.asRecord)((_a = (0, schema_1.asRecord)(doc.components)) === null || _a === void 0 ? void 0 : _a.schemas)) !== null && _b !== void 0 ? _b : {};
|
|
11
|
+
const ctx = { schemas, allOf: (_c = options.allOf) !== null && _c !== void 0 ? _c : all_of_1.DEFAULT_ALLOF_MODE, diagnostics: new schema_1.DiagnosticSink() };
|
|
12
|
+
const models = Object.entries(schemas).map(([id, schema]) => (0, schema_1.convertModel)(id, schema, ctx));
|
|
13
|
+
const operations = (0, operations_1.convertOperations)(doc, ctx);
|
|
14
|
+
return { info: convertInfo(doc), models, operations, diagnostics: ctx.diagnostics.items };
|
|
15
|
+
}
|
|
16
|
+
function convertInfo(doc) {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
|
+
const info = (_a = (0, schema_1.asRecord)(doc.info)) !== null && _a !== void 0 ? _a : {};
|
|
19
|
+
const result = {
|
|
20
|
+
title: (_b = (0, schema_1.asString)(info.title)) !== null && _b !== void 0 ? _b : '',
|
|
21
|
+
version: (_c = (0, schema_1.asString)(info.version)) !== null && _c !== void 0 ? _c : '',
|
|
22
|
+
servers: ((_d = (0, schema_1.asArray)(doc.servers)) !== null && _d !== void 0 ? _d : [])
|
|
23
|
+
.map((server) => { var _a; return (0, schema_1.asString)((_a = (0, schema_1.asRecord)(server)) === null || _a === void 0 ? void 0 : _a.url); })
|
|
24
|
+
.filter((url) => url !== undefined),
|
|
25
|
+
openapi: doc.openapi,
|
|
26
|
+
};
|
|
27
|
+
const description = (0, schema_1.asString)(info.description);
|
|
28
|
+
if (description !== undefined)
|
|
29
|
+
result.description = description;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertOperations = convertOperations;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'];
|
|
6
|
+
const LOCATIONS = ['path', 'query', 'header', 'cookie'];
|
|
7
|
+
function isHttpMethod(value) {
|
|
8
|
+
return HTTP_METHODS.includes(value);
|
|
9
|
+
}
|
|
10
|
+
function isLocation(value) {
|
|
11
|
+
return typeof value === 'string' && LOCATIONS.includes(value);
|
|
12
|
+
}
|
|
13
|
+
function resolveComponent(value, section, prefix) {
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
let current = value;
|
|
16
|
+
while ((0, schema_1.isRecord)(current) && typeof current.$ref === 'string') {
|
|
17
|
+
const ref = current.$ref;
|
|
18
|
+
if (seen.has(ref) || !ref.startsWith(prefix))
|
|
19
|
+
return undefined;
|
|
20
|
+
seen.add(ref);
|
|
21
|
+
current = section === null || section === void 0 ? void 0 : section[ref.slice(prefix.length)];
|
|
22
|
+
}
|
|
23
|
+
return (0, schema_1.asRecord)(current);
|
|
24
|
+
}
|
|
25
|
+
function reportUnresolved(value, what, ctx) {
|
|
26
|
+
var _a;
|
|
27
|
+
const ref = (_a = (0, schema_1.asRecord)(value)) === null || _a === void 0 ? void 0 : _a.$ref;
|
|
28
|
+
ctx.diagnostics.report('warn', 'unresolved-ref', typeof ref === 'string' ? `${what} $ref "${ref}" does not resolve` : `${what} is not an object`);
|
|
29
|
+
}
|
|
30
|
+
function firstMediaSchema(content) {
|
|
31
|
+
var _a;
|
|
32
|
+
var _b;
|
|
33
|
+
const first = Object.values((_b = (0, schema_1.asRecord)(content)) !== null && _b !== void 0 ? _b : {})[0];
|
|
34
|
+
return (_a = (0, schema_1.asRecord)(first)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
35
|
+
}
|
|
36
|
+
function convertParameter(value, ctx) {
|
|
37
|
+
const param = resolveComponent(value, ctx.components.parameters, '#/components/parameters/');
|
|
38
|
+
if (!param) {
|
|
39
|
+
reportUnresolved(value, 'parameter', ctx);
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const name = (0, schema_1.asString)(param.name);
|
|
43
|
+
if (name === undefined || !isLocation(param.in)) {
|
|
44
|
+
ctx.diagnostics.report('warn', 'invalid-parameter', `parameter ${JSON.stringify(param.name)} in ${JSON.stringify(param.in)} skipped (needs a name and in: path|query|header|cookie)`);
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const schema = param.schema !== undefined ? param.schema : firstMediaSchema(param.content);
|
|
48
|
+
const parameter = {
|
|
49
|
+
name,
|
|
50
|
+
in: param.in,
|
|
51
|
+
required: param.in === 'path' ? param.required !== false : !!param.required,
|
|
52
|
+
type: ctx.diagnostics.within(`parameters/${name}`, () => (0, schema_1.convertSchema)(schema, ctx)),
|
|
53
|
+
raw: param,
|
|
54
|
+
};
|
|
55
|
+
const description = (0, schema_1.asString)(param.description);
|
|
56
|
+
if (description !== undefined)
|
|
57
|
+
parameter.description = description;
|
|
58
|
+
const deprecated = (0, schema_1.asBoolean)(param.deprecated);
|
|
59
|
+
if (deprecated !== undefined)
|
|
60
|
+
parameter.deprecated = deprecated;
|
|
61
|
+
const style = (0, schema_1.asString)(param.style);
|
|
62
|
+
if (style !== undefined)
|
|
63
|
+
parameter.style = style;
|
|
64
|
+
const explode = (0, schema_1.asBoolean)(param.explode);
|
|
65
|
+
if (explode !== undefined)
|
|
66
|
+
parameter.explode = explode;
|
|
67
|
+
return parameter;
|
|
68
|
+
}
|
|
69
|
+
function convertParameterList(value, ctx) {
|
|
70
|
+
var _a;
|
|
71
|
+
return ((_a = (0, schema_1.asArray)(value)) !== null && _a !== void 0 ? _a : [])
|
|
72
|
+
.map((p) => convertParameter(p, ctx))
|
|
73
|
+
.filter((p) => p !== undefined);
|
|
74
|
+
}
|
|
75
|
+
function mergeParameters(pathLevel, operationLevel) {
|
|
76
|
+
const merged = [...pathLevel];
|
|
77
|
+
for (const param of operationLevel) {
|
|
78
|
+
const index = merged.findIndex((p) => p.name === param.name && p.in === param.in);
|
|
79
|
+
if (index >= 0)
|
|
80
|
+
merged[index] = param;
|
|
81
|
+
else
|
|
82
|
+
merged.push(param);
|
|
83
|
+
}
|
|
84
|
+
return merged;
|
|
85
|
+
}
|
|
86
|
+
function convertContents(content, ctx) {
|
|
87
|
+
var _a;
|
|
88
|
+
return Object.entries((_a = (0, schema_1.asRecord)(content)) !== null && _a !== void 0 ? _a : {}).map(([mediaType, media]) => { var _a; return ({
|
|
89
|
+
mediaType,
|
|
90
|
+
type: (0, schema_1.convertSchema)((_a = (0, schema_1.asRecord)(media)) === null || _a === void 0 ? void 0 : _a.schema, ctx),
|
|
91
|
+
}); });
|
|
92
|
+
}
|
|
93
|
+
function convertRequestBody(value, ctx) {
|
|
94
|
+
const body = resolveComponent(value, ctx.components.requestBodies, '#/components/requestBodies/');
|
|
95
|
+
if (!body) {
|
|
96
|
+
reportUnresolved(value, 'requestBody', ctx);
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const requestBody = {
|
|
100
|
+
required: !!body.required,
|
|
101
|
+
contents: ctx.diagnostics.within('requestBody', () => convertContents(body.content, ctx)),
|
|
102
|
+
};
|
|
103
|
+
const description = (0, schema_1.asString)(body.description);
|
|
104
|
+
if (description !== undefined)
|
|
105
|
+
requestBody.description = description;
|
|
106
|
+
return requestBody;
|
|
107
|
+
}
|
|
108
|
+
function convertResponse(status, value, ctx) {
|
|
109
|
+
const resolved = resolveComponent(value, ctx.components.responses, '#/components/responses/');
|
|
110
|
+
if (!resolved)
|
|
111
|
+
reportUnresolved(value, `responses/${status}`, ctx);
|
|
112
|
+
const response = {
|
|
113
|
+
status,
|
|
114
|
+
contents: ctx.diagnostics.within(`responses/${status}`, () => convertContents(resolved === null || resolved === void 0 ? void 0 : resolved.content, ctx)),
|
|
115
|
+
};
|
|
116
|
+
const description = (0, schema_1.asString)(resolved === null || resolved === void 0 ? void 0 : resolved.description);
|
|
117
|
+
if (description !== undefined)
|
|
118
|
+
response.description = description;
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
function convertResponses(value, ctx) {
|
|
122
|
+
var _a;
|
|
123
|
+
return Object.entries((_a = (0, schema_1.asRecord)(value)) !== null && _a !== void 0 ? _a : {}).map(([status, response]) => convertResponse(status, response, ctx));
|
|
124
|
+
}
|
|
125
|
+
function convertOperation(method, path, operation, pathParameters, ctx) {
|
|
126
|
+
const result = {
|
|
127
|
+
id: `${method} ${path}`,
|
|
128
|
+
method,
|
|
129
|
+
path,
|
|
130
|
+
tags: (0, schema_1.stringList)(operation.tags),
|
|
131
|
+
parameters: mergeParameters(convertParameterList(pathParameters, ctx), convertParameterList(operation.parameters, ctx)),
|
|
132
|
+
responses: convertResponses(operation.responses, ctx),
|
|
133
|
+
raw: operation,
|
|
134
|
+
};
|
|
135
|
+
const operationId = (0, schema_1.asString)(operation.operationId);
|
|
136
|
+
if (operationId !== undefined)
|
|
137
|
+
result.operationId = operationId;
|
|
138
|
+
const summary = (0, schema_1.asString)(operation.summary);
|
|
139
|
+
if (summary !== undefined)
|
|
140
|
+
result.summary = summary;
|
|
141
|
+
const description = (0, schema_1.asString)(operation.description);
|
|
142
|
+
if (description !== undefined)
|
|
143
|
+
result.description = description;
|
|
144
|
+
const deprecated = (0, schema_1.asBoolean)(operation.deprecated);
|
|
145
|
+
if (deprecated !== undefined)
|
|
146
|
+
result.deprecated = deprecated;
|
|
147
|
+
const requestBody = operation.requestBody !== undefined ? convertRequestBody(operation.requestBody, ctx) : undefined;
|
|
148
|
+
if (requestBody)
|
|
149
|
+
result.requestBody = requestBody;
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function convertOperations(doc, schemaCtx) {
|
|
153
|
+
var _a, _b;
|
|
154
|
+
const components = (_a = (0, schema_1.asRecord)(doc.components)) !== null && _a !== void 0 ? _a : {};
|
|
155
|
+
const ctx = Object.assign(Object.assign({}, schemaCtx), { components: {
|
|
156
|
+
parameters: (0, schema_1.asRecord)(components.parameters),
|
|
157
|
+
requestBodies: (0, schema_1.asRecord)(components.requestBodies),
|
|
158
|
+
responses: (0, schema_1.asRecord)(components.responses),
|
|
159
|
+
} });
|
|
160
|
+
const operations = [];
|
|
161
|
+
for (const [path, pathItemValue] of Object.entries((_b = (0, schema_1.asRecord)(doc.paths)) !== null && _b !== void 0 ? _b : {})) {
|
|
162
|
+
const pathItem = (0, schema_1.asRecord)(pathItemValue);
|
|
163
|
+
if (!pathItem)
|
|
164
|
+
continue;
|
|
165
|
+
for (const [key, operation] of Object.entries(pathItem)) {
|
|
166
|
+
const method = key.toLowerCase();
|
|
167
|
+
if (!isHttpMethod(method) || !(0, schema_1.isRecord)(operation))
|
|
168
|
+
continue;
|
|
169
|
+
operations.push(ctx.diagnostics.atLocation(`#/paths/${path.replace(/~/g, '~0').replace(/\//g, '~1')}/${key}`, () => convertOperation(method, path, operation, pathItem.parameters, ctx)));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return operations;
|
|
173
|
+
}
|