@mintlify/validation 0.1.57 → 0.1.59

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.
Files changed (32) hide show
  1. package/dist/index.js +86 -2
  2. package/dist/mint-config/common.js +12 -0
  3. package/dist/mint-config/flattenUnionErrorMessages.js +23 -0
  4. package/dist/mint-config/hexadecimalPattern.js +4 -0
  5. package/dist/mint-config/schemas/analytics.js +132 -0
  6. package/dist/mint-config/schemas/anchorColors.js +31 -0
  7. package/dist/mint-config/schemas/anchors.d.ts +6 -6
  8. package/dist/mint-config/schemas/anchors.js +72 -0
  9. package/dist/mint-config/schemas/apiReference.js +68 -0
  10. package/dist/mint-config/schemas/basics.js +135 -0
  11. package/dist/mint-config/schemas/colors.js +45 -0
  12. package/dist/mint-config/schemas/config.d.ts +13 -13
  13. package/dist/mint-config/schemas/config.js +42 -0
  14. package/dist/mint-config/schemas/favicon.js +12 -0
  15. package/dist/mint-config/schemas/integrations.js +14 -0
  16. package/dist/mint-config/schemas/navigation.js +27 -0
  17. package/dist/mint-config/schemas/tabs.js +31 -0
  18. package/dist/mint-config/schemas/versions.js +16 -0
  19. package/dist/mint-config/types/enums.js +4 -0
  20. package/dist/mint-config/types/index.js +2 -0
  21. package/dist/mint-config/types/navigation.js +2 -0
  22. package/dist/mint-config/validateAnchorsWarnings.js +39 -0
  23. package/dist/mint-config/validateVersionsInNavigation.js +60 -0
  24. package/dist/openapi/convertOpenApi.js +174 -0
  25. package/dist/openapi/convertParameters.js +64 -0
  26. package/dist/openapi/convertSchema.js +486 -0
  27. package/dist/openapi/convertSecurity.js +87 -0
  28. package/dist/openapi/convertServers.js +47 -0
  29. package/dist/openapi/types/endpoint.js +16 -0
  30. package/dist/tsconfig.build.tsbuildinfo +1 -0
  31. package/package.json +7 -4
  32. package/dist/index.js.LICENSE.txt +0 -8
@@ -231,11 +231,11 @@ export declare const configSchema: z.ZodObject<{
231
231
  }, "strict", z.ZodTypeAny, {
232
232
  name: string;
233
233
  icon?: string | undefined;
234
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
234
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
235
235
  }, {
236
236
  name: string;
237
237
  icon?: string | undefined;
238
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
238
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
239
239
  }>>;
240
240
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
241
241
  name: z.ZodString;
@@ -261,7 +261,7 @@ export declare const configSchema: z.ZodObject<{
261
261
  name: string;
262
262
  url: string;
263
263
  icon?: string | undefined;
264
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
264
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
265
265
  color?: string | {
266
266
  from: string;
267
267
  to: string;
@@ -273,7 +273,7 @@ export declare const configSchema: z.ZodObject<{
273
273
  name: string;
274
274
  url: string;
275
275
  icon?: string | undefined;
276
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
276
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
277
277
  color?: string | {
278
278
  from: string;
279
279
  to: string;
@@ -521,8 +521,8 @@ export declare const configSchema: z.ZodObject<{
521
521
  destination: string;
522
522
  }[]>>;
523
523
  }, "strip", z.ZodTypeAny, {
524
- $schema: string;
525
524
  name: string;
525
+ $schema: string;
526
526
  favicon: string;
527
527
  colors: {
528
528
  primary: string;
@@ -596,13 +596,13 @@ export declare const configSchema: z.ZodObject<{
596
596
  topAnchor?: {
597
597
  name: string;
598
598
  icon?: string | undefined;
599
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
599
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
600
600
  } | undefined;
601
601
  anchors?: {
602
602
  name: string;
603
603
  url: string;
604
604
  icon?: string | undefined;
605
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
605
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
606
606
  color?: string | {
607
607
  from: string;
608
608
  to: string;
@@ -615,10 +615,10 @@ export declare const configSchema: z.ZodObject<{
615
615
  name: string;
616
616
  url: string;
617
617
  }[] | undefined;
618
- footerSocials?: Record<string, string> | {
618
+ footerSocials?: {
619
619
  type: string;
620
620
  url: string;
621
- }[] | undefined;
621
+ }[] | Record<string, string> | undefined;
622
622
  backgroundImage?: string | undefined;
623
623
  feedback?: {
624
624
  thumbsRating?: boolean | undefined;
@@ -753,13 +753,13 @@ export declare const configSchema: z.ZodObject<{
753
753
  topAnchor?: {
754
754
  name: string;
755
755
  icon?: string | undefined;
756
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
756
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
757
757
  } | undefined;
758
758
  anchors?: {
759
759
  name: string;
760
760
  url: string;
761
761
  icon?: string | undefined;
762
- iconType?: "light" | "brands" | "duotone" | "sharp-solid" | "solid" | "thin" | undefined;
762
+ iconType?: "brands" | "duotone" | "light" | "sharp-solid" | "solid" | "thin" | undefined;
763
763
  color?: string | {
764
764
  from: string;
765
765
  to: string;
@@ -772,10 +772,10 @@ export declare const configSchema: z.ZodObject<{
772
772
  name: string;
773
773
  url: string;
774
774
  }[] | undefined;
775
- footerSocials?: Record<string, string> | {
775
+ footerSocials?: {
776
776
  type: string;
777
777
  url: string;
778
- }[] | undefined;
778
+ }[] | Record<string, string> | undefined;
779
779
  backgroundImage?: string | undefined;
780
780
  feedback?: {
781
781
  thumbsRating?: boolean | undefined;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var analytics_1 = require("./analytics");
6
+ var anchors_1 = require("./anchors");
7
+ var apiReference_1 = require("./apiReference");
8
+ var basics_1 = require("./basics");
9
+ var colors_1 = require("./colors");
10
+ var favicon_1 = require("./favicon");
11
+ var integrations_1 = require("./integrations");
12
+ var navigation_1 = require("./navigation");
13
+ var tabs_1 = require("./tabs");
14
+ var versions_1 = require("./versions");
15
+ exports.configSchema = zod_1.z.object({
16
+ $schema: zod_1.z.string().url().optional().default('https://mintlify.com/schema.json'),
17
+ mintlify: zod_1.z.string().optional(),
18
+ name: basics_1.nameSchema,
19
+ logo: basics_1.logoSchema.optional(),
20
+ favicon: favicon_1.faviconSchema,
21
+ openapi: apiReference_1.openApiSchema.optional(),
22
+ api: apiReference_1.apiSchema.optional(),
23
+ modeToggle: basics_1.modeToggleSchema.optional(),
24
+ versions: versions_1.versionsSchema.optional(),
25
+ metadata: basics_1.metadataSchema.optional(),
26
+ colors: colors_1.colorsSchema,
27
+ topbarCtaButton: (0, basics_1.createCtaButtonSchema)('topbarCtaButton').optional(),
28
+ topbarLinks: zod_1.z.array((0, basics_1.createCtaButtonSchema)('topbarLinks')).optional(),
29
+ navigation: navigation_1.navigationConfigSchema,
30
+ primaryTab: tabs_1.primaryTabSchema.optional(),
31
+ topAnchor: anchors_1.topAnchorSchema.optional(),
32
+ anchors: anchors_1.anchorsSchema.optional(),
33
+ tabs: tabs_1.tabsSchema.optional(),
34
+ footerSocials: basics_1.footerSocialsSchema.optional(),
35
+ backgroundImage: zod_1.z.string().optional(),
36
+ feedback: basics_1.feedbackSchema.optional(),
37
+ analytics: analytics_1.analyticsSchema.optional(),
38
+ integrations: integrations_1.integrationsSchema.optional(),
39
+ isWhiteLabeled: basics_1.isWhiteLabeledSchema.optional(),
40
+ search: basics_1.searchSchema.optional(),
41
+ redirects: basics_1.redirectsSchema.optional(),
42
+ });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.faviconSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ exports.faviconSchema = zod_1.z
6
+ .string({
7
+ required_error: 'Favicon is missing. Please set favicon to the path of your favicon file. We recommend using a .svg or .png file. Mintlify automatically resizes your favicon to the sizes needed.',
8
+ invalid_type_error: 'Favicon must be a string path pointing to the favicon file in your Mintlify folder.',
9
+ })
10
+ .refine(function (val) { return val.split('.').pop() !== 'ico'; }, {
11
+ message: 'Favicon cannot be an .ico file.',
12
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.integrationsSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var intercomSchema = zod_1.z
6
+ .string({ invalid_type_error: 'integrations.intercom must be a string' })
7
+ .min(6, 'integrations.intercom must be a valid Intercom app ID');
8
+ var frontchatSchema = zod_1.z
9
+ .string({ invalid_type_error: 'integrations.frontchat must be a string' })
10
+ .min(6, 'integrations.frontchat must be a valid Front chat snippet id');
11
+ exports.integrationsSchema = zod_1.z.object({
12
+ intercom: intercomSchema.optional(),
13
+ frontchat: frontchatSchema.optional(),
14
+ }, { invalid_type_error: 'integrations must be an object' });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.navigationConfigSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var navigationSchema = zod_1.z.lazy(function () {
6
+ return zod_1.z
7
+ .object({
8
+ // We allow top-level groups to be an empty string if the user wants to hide the title.
9
+ // Future work should refactor this so nested groups are non-empty strings.
10
+ group: zod_1.z.string({
11
+ required_error: 'Missing navigation group name.',
12
+ invalid_type_error: 'Group must be a string. We use the group name to create the navigation sidebar.',
13
+ }),
14
+ pages: zod_1.z
15
+ .array(zod_1.z.union([navigationSchema, zod_1.z.string().min(1, 'Page cannot be an empty string.')]))
16
+ .min(1, "Pages array can't be empty."),
17
+ icon: zod_1.z.string({ invalid_type_error: 'Icon must be a string.' }).optional(),
18
+ version: zod_1.z.string({ invalid_type_error: 'Version must be a string.' }).optional(),
19
+ }, { invalid_type_error: 'Navigation entry must be an object.' })
20
+ .strict('Navigation entry can only contain group, pages, icon, and version.');
21
+ });
22
+ exports.navigationConfigSchema = zod_1.z
23
+ .array(navigationSchema, {
24
+ required_error: 'Navigation is missing.',
25
+ invalid_type_error: 'Navigation must be an array.',
26
+ })
27
+ .min(1, 'Navigation cannot be an empty array. Please add at least one group.');
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.primaryTabSchema = exports.tabsSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var tabSchema = zod_1.z.object({
6
+ name: zod_1.z
7
+ .string({
8
+ required_error: 'Every tab must have a name.',
9
+ invalid_type_error: 'Tab name must be a string.',
10
+ })
11
+ .trim()
12
+ .min(1, 'Tab name is empty.'),
13
+ url: zod_1.z
14
+ .string({
15
+ required_error: 'Every tab must have a url',
16
+ invalid_type_error: 'Tab url must be a string.',
17
+ })
18
+ .trim()
19
+ .min(1, 'Tab URL is missing.'),
20
+ });
21
+ exports.tabsSchema = tabSchema.array();
22
+ exports.primaryTabSchema = zod_1.z
23
+ .object({
24
+ name: zod_1.z.string({
25
+ required_error: 'primaryTab.name is missing, set it or delete the entire primaryTab property.',
26
+ invalid_type_error: 'primaryTab.name must be a string',
27
+ }),
28
+ }, {
29
+ invalid_type_error: 'primaryTab must be an object with a name property.',
30
+ })
31
+ .strict('primaryTab can only have name properties.');
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.versionsSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var versionSchema = zod_1.z.union([
6
+ zod_1.z.string({ invalid_type_error: 'Versions must be an array of strings.' }),
7
+ zod_1.z
8
+ .object({
9
+ name: zod_1.z.string().min(1, 'Name cannot be an empty string.'),
10
+ url: zod_1.z.string().min(1, 'URL cannot be an empty string.'),
11
+ })
12
+ .strict('Object must contain name and url properties'),
13
+ ]);
14
+ exports.versionsSchema = zod_1.z
15
+ .array(versionSchema)
16
+ .min(1, 'Versions array cannot be empty. Either delete the property or add strings to the array.');
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/ban-types */
3
+ // explanation for (string & {}): https://twitter.com/mattpocockuk/status/1671908303918473217?s=20
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAnchorsWarnings = void 0;
4
+ var common_1 = require("./common");
5
+ var navigation_1 = require("./schemas/navigation");
6
+ function validateAnchorsWarnings(anchors, navigation) {
7
+ var results = new common_1.MintValidationResults();
8
+ if (anchors &&
9
+ Array.isArray(anchors) &&
10
+ navigation &&
11
+ navigation_1.navigationConfigSchema.safeParse(navigation).success === true) {
12
+ anchors.forEach(function (anchor) {
13
+ if (!anchor.url.startsWith('mailto:') &&
14
+ !anchor.url.startsWith('http') &&
15
+ !anchor.url.startsWith('https') &&
16
+ !navigation.some(function (nav) { return pageStartsWith(nav, anchor.url); })) {
17
+ results.warnings.push('No pages in the navigation match anchor ' +
18
+ anchor.url +
19
+ ' you should have at least one page that starts with ' +
20
+ anchor.url);
21
+ }
22
+ });
23
+ }
24
+ return results;
25
+ }
26
+ exports.validateAnchorsWarnings = validateAnchorsWarnings;
27
+ function pageStartsWith(navEntry, prefix) {
28
+ if (typeof navEntry === 'string') {
29
+ return navEntry.startsWith(prefix);
30
+ }
31
+ else if (navEntry.pages == undefined) {
32
+ return false;
33
+ }
34
+ else {
35
+ return navEntry.pages.some(function (entry) {
36
+ return pageStartsWith(entry, prefix);
37
+ });
38
+ }
39
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateVersionsInNavigation = exports.flattenNavigationVersions = void 0;
4
+ var common_1 = require("./common");
5
+ var navigation_1 = require("./schemas/navigation");
6
+ function flattenNavigationVersions(nav, versions) {
7
+ if (versions === void 0) { versions = []; }
8
+ nav.forEach(function (val) {
9
+ if (val == null || typeof val === 'string') {
10
+ return versions;
11
+ }
12
+ if (val.version) {
13
+ versions.push(val.version);
14
+ }
15
+ if (!Array.isArray(val.pages)) {
16
+ return versions;
17
+ }
18
+ return flattenNavigationVersions(val.pages, versions);
19
+ });
20
+ return versions;
21
+ }
22
+ exports.flattenNavigationVersions = flattenNavigationVersions;
23
+ function validateVersionsInNavigation(navigation, versions) {
24
+ if (versions === void 0) { versions = []; }
25
+ var results = new common_1.MintValidationResults();
26
+ if (navigation == null || navigation_1.navigationConfigSchema.safeParse(navigation).success === false) {
27
+ return results;
28
+ }
29
+ var versionsFromNavigation = flattenNavigationVersions(navigation);
30
+ versionsFromNavigation.forEach(function (v) {
31
+ if (versions && !versions.includes(v)) {
32
+ results.errors.push("Version ".concat(v, " is not included in the versions array, but is used in the navigation. Please add ").concat(v, " to the versions array."));
33
+ }
34
+ });
35
+ if (versionsFromNavigation.length === 0 && versions.length > 0) {
36
+ results.warnings.push('You have versions defined in the config, but no versions are used in the navigation.');
37
+ }
38
+ navigation.forEach(function (nav) {
39
+ var _a;
40
+ (_a = results.warnings).push.apply(_a, warnVersionNesting(nav, null));
41
+ });
42
+ return results;
43
+ }
44
+ exports.validateVersionsInNavigation = validateVersionsInNavigation;
45
+ function warnVersionNesting(navigation, currentVersion) {
46
+ if (typeof navigation === 'string') {
47
+ return [];
48
+ }
49
+ var warnings = [];
50
+ if (navigation.version && currentVersion != null && navigation.version !== currentVersion) {
51
+ warnings.push("Please do not set versions on groups nested inside a group that already has a version. The group \"".concat(navigation.group, "\" has version \"").concat(navigation.version, "\" set and it is nested in a group that has the version \"").concat(currentVersion, "\" set."));
52
+ }
53
+ if (navigation.pages) {
54
+ return warnings.concat(navigation.pages
55
+ .map(function (entry) { return warnVersionNesting(entry, currentVersion || navigation.version); })
56
+ .flat()
57
+ .filter(Boolean));
58
+ }
59
+ return [];
60
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.convertOpenAPIV3_1ToEndpoint = exports.convertResponse = exports.convertResponses = exports.convertBody = exports.ConversionError = exports.ImpossibleSchemaError = exports.InvalidSchemaError = exports.generateMessage = void 0;
28
+ var convertParameters_1 = require("./convertParameters");
29
+ var convertSchema_1 = require("./convertSchema");
30
+ var convertSecurity_1 = require("./convertSecurity");
31
+ var convertServers_1 = require("./convertServers");
32
+ var generateMessage = function (path, messages) {
33
+ if (messages === void 0) { messages = []; }
34
+ var pathString = path
35
+ .map(function (component) { return component.replace('\\', '\\\\').replace('/', '\\/'); })
36
+ .join('/');
37
+ return __spreadArray([pathString], messages, true).join('\n');
38
+ };
39
+ exports.generateMessage = generateMessage;
40
+ var InvalidSchemaError = /** @class */ (function (_super) {
41
+ __extends(InvalidSchemaError, _super);
42
+ function InvalidSchemaError(path) {
43
+ var messages = [];
44
+ for (var _i = 1; _i < arguments.length; _i++) {
45
+ messages[_i - 1] = arguments[_i];
46
+ }
47
+ var _this = _super.call(this, (0, exports.generateMessage)(path, messages)) || this;
48
+ _this.name = 'InvalidSchemaError';
49
+ Object.setPrototypeOf(_this, InvalidSchemaError.prototype);
50
+ return _this;
51
+ }
52
+ return InvalidSchemaError;
53
+ }(Error));
54
+ exports.InvalidSchemaError = InvalidSchemaError;
55
+ var ImpossibleSchemaError = /** @class */ (function (_super) {
56
+ __extends(ImpossibleSchemaError, _super);
57
+ function ImpossibleSchemaError(path) {
58
+ var messages = [];
59
+ for (var _i = 1; _i < arguments.length; _i++) {
60
+ messages[_i - 1] = arguments[_i];
61
+ }
62
+ var _this = _super.call(this, (0, exports.generateMessage)(path, messages)) || this;
63
+ _this.name = 'ImpossibleSchemaError';
64
+ Object.setPrototypeOf(_this, ImpossibleSchemaError.prototype);
65
+ return _this;
66
+ }
67
+ return ImpossibleSchemaError;
68
+ }(Error));
69
+ exports.ImpossibleSchemaError = ImpossibleSchemaError;
70
+ var ConversionError = /** @class */ (function (_super) {
71
+ __extends(ConversionError, _super);
72
+ function ConversionError(path) {
73
+ var messages = [];
74
+ for (var _i = 1; _i < arguments.length; _i++) {
75
+ messages[_i - 1] = arguments[_i];
76
+ }
77
+ var _this = _super.call(this, (0, exports.generateMessage)(path, messages)) || this;
78
+ _this.name = 'ConversionError';
79
+ Object.setPrototypeOf(_this, ConversionError.prototype);
80
+ return _this;
81
+ }
82
+ return ConversionError;
83
+ }(Error));
84
+ exports.ConversionError = ConversionError;
85
+ var convertBody = function (path, body) {
86
+ if (body === undefined) {
87
+ return {};
88
+ }
89
+ var newEntries = Object.entries(body.content).map(function (_a) {
90
+ var contentType = _a[0], mediaObject = _a[1];
91
+ return [
92
+ contentType,
93
+ (0, convertSchema_1.convertSchema)(__spreadArray(__spreadArray([], path, true), [contentType, 'schema'], false), mediaObject.schema, body.required),
94
+ ];
95
+ });
96
+ return Object.fromEntries(newEntries);
97
+ };
98
+ exports.convertBody = convertBody;
99
+ var convertResponses = function (path, responses) {
100
+ var newEntries = Object.entries(responses).map(function (_a) {
101
+ var statusCode = _a[0], response = _a[1];
102
+ return [
103
+ statusCode,
104
+ (0, exports.convertResponse)(__spreadArray(__spreadArray([], path, true), [statusCode], false), response),
105
+ ];
106
+ });
107
+ return Object.fromEntries(newEntries);
108
+ };
109
+ exports.convertResponses = convertResponses;
110
+ var convertResponse = function (path, response) {
111
+ if (response.content === undefined) {
112
+ return {};
113
+ }
114
+ var newEntries = Object.entries(response.content).map(function (_a) {
115
+ var contentType = _a[0], mediaType = _a[1];
116
+ return [
117
+ contentType,
118
+ (0, convertSchema_1.convertSchema)(__spreadArray(__spreadArray([], path, true), ['content', contentType, 'schema'], false), mediaType.schema),
119
+ ];
120
+ });
121
+ return Object.fromEntries(newEntries);
122
+ };
123
+ exports.convertResponse = convertResponse;
124
+ var convertOpenAPIV3_1ToEndpoint = function (spec, path, method) {
125
+ var _a, _b, _c, _d, _e;
126
+ var paths = spec.paths;
127
+ if (paths === undefined) {
128
+ throw new InvalidSchemaError(['#'], 'paths not defined');
129
+ }
130
+ var pathObject = paths[path];
131
+ if (pathObject === undefined) {
132
+ throw new InvalidSchemaError(['#', 'paths'], "path not defined: ".concat(path));
133
+ }
134
+ var operationObject = pathObject[method];
135
+ if (operationObject === undefined) {
136
+ throw new InvalidSchemaError(['#', 'paths', path], "operation does not exist: ".concat(method));
137
+ }
138
+ var securityRequirements = (_a = operationObject.security) !== null && _a !== void 0 ? _a : spec.security;
139
+ var securitySchemes = (_b = spec.components) === null || _b === void 0 ? void 0 : _b.securitySchemes;
140
+ var security = (0, convertSecurity_1.convertSecurity)({
141
+ securityRequirements: securityRequirements,
142
+ securitySchemes: securitySchemes,
143
+ });
144
+ var pathParameters = pathObject.parameters;
145
+ var operationParameters = operationObject.parameters;
146
+ var parameters = (0, convertParameters_1.convertParameters)({
147
+ path: ['#', 'paths', path],
148
+ method: method,
149
+ pathParameters: pathParameters,
150
+ operationParameters: operationParameters,
151
+ });
152
+ var servers = (0, convertServers_1.convertServers)({
153
+ servers: (_d = (_c = operationObject.servers) !== null && _c !== void 0 ? _c : pathObject.servers) !== null && _d !== void 0 ? _d : spec.servers,
154
+ });
155
+ var description = (_e = operationObject.description) !== null && _e !== void 0 ? _e : pathObject === null || pathObject === void 0 ? void 0 : pathObject.description;
156
+ var requestBody = operationObject.requestBody;
157
+ var body = (0, exports.convertBody)(['#', 'paths', path, method, 'requestBody'], requestBody);
158
+ var deprecated = !!operationObject.deprecated;
159
+ var response = (0, exports.convertResponses)(['#', 'paths', path, method, 'responses'], operationObject.responses);
160
+ return {
161
+ description: description,
162
+ path: path,
163
+ method: method,
164
+ servers: servers,
165
+ request: {
166
+ security: security,
167
+ parameters: parameters,
168
+ body: body,
169
+ },
170
+ response: response,
171
+ deprecated: deprecated,
172
+ };
173
+ };
174
+ exports.convertOpenAPIV3_1ToEndpoint = convertOpenAPIV3_1ToEndpoint;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.convertParameters = void 0;
13
+ var convertOpenApi_1 = require("./convertOpenApi");
14
+ var convertSchema_1 = require("./convertSchema");
15
+ var convertParameters = function (_a) {
16
+ var path = _a.path, method = _a.method, pathParameters = _a.pathParameters, operationParameters = _a.operationParameters;
17
+ var parameterSections = {
18
+ path: {},
19
+ query: {},
20
+ header: {},
21
+ cookie: {},
22
+ };
23
+ pathParameters === null || pathParameters === void 0 ? void 0 : pathParameters.forEach(function (parameterObject, i) {
24
+ addParameter({
25
+ path: __spreadArray(__spreadArray([], path, true), ['parameters', i.toString()], false),
26
+ parameter: parameterObject,
27
+ parameterSections: parameterSections,
28
+ });
29
+ });
30
+ operationParameters === null || operationParameters === void 0 ? void 0 : operationParameters.forEach(function (parameterObject, i) {
31
+ addParameter({
32
+ path: __spreadArray(__spreadArray([], path, true), [method, 'parameters', i.toString()], false),
33
+ parameter: parameterObject,
34
+ parameterSections: parameterSections,
35
+ });
36
+ });
37
+ return parameterSections;
38
+ };
39
+ exports.convertParameters = convertParameters;
40
+ var addParameter = function (_a) {
41
+ var path = _a.path, parameter = _a.parameter, parameterSections = _a.parameterSections;
42
+ if (!['path', 'header', 'query', 'cookie'].includes(parameter.in)) {
43
+ throw new convertOpenApi_1.InvalidSchemaError(path, "invalid parameter location: '".concat(parameter.in, "'"));
44
+ }
45
+ var location = parameter.in;
46
+ if (location === 'path') {
47
+ var newParameter = {
48
+ required: true,
49
+ schema: (0, convertSchema_1.convertSchema)(__spreadArray(__spreadArray([], path, true), ['schema'], false), parameter.schema, true),
50
+ };
51
+ (0, convertSchema_1.copyKeyIfDefined)('description', parameter, newParameter);
52
+ (0, convertSchema_1.copyKeyIfDefined)('deprecated', parameter, newParameter);
53
+ parameterSections.path[parameter.name] = newParameter;
54
+ }
55
+ else {
56
+ var newParameter = {
57
+ schema: (0, convertSchema_1.convertSchema)(__spreadArray(__spreadArray([], path, true), ['schema'], false), parameter.schema, true),
58
+ };
59
+ (0, convertSchema_1.copyKeyIfDefined)('description', parameter, newParameter);
60
+ (0, convertSchema_1.copyKeyIfDefined)('deprecated', parameter, newParameter);
61
+ (0, convertSchema_1.copyKeyIfDefined)('required', parameter, newParameter);
62
+ parameterSections[location][parameter.name] = newParameter;
63
+ }
64
+ };