@mintlify/validation 0.1.98 → 0.1.100

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.
@@ -1,74 +0,0 @@
1
- import { InvalidSchemaError } from './convertOpenApi.js';
2
- import { copyKeyIfDefined } from './convertSchema.js';
3
- export const convertSecurity = ({ securityRequirements, securitySchemes, }) => {
4
- if (securityRequirements === undefined || securityRequirements.length === 0) {
5
- return [];
6
- }
7
- if (securitySchemes === undefined) {
8
- throw new InvalidSchemaError(['#', 'components'], 'securitySchemes not defined');
9
- }
10
- // TODO(ronan): make this work for camel-case as well
11
- return securityRequirements.map((security) => {
12
- const title = Object.keys(security)
13
- .map((securityName) => securityName.replace(/[_-]/g, ' '))
14
- .join(' & ');
15
- const parameterSections = {
16
- query: {},
17
- header: {},
18
- cookie: {},
19
- };
20
- Object.keys(security).forEach((securityName) => {
21
- const securityScheme = securitySchemes === null || securitySchemes === void 0 ? void 0 : securitySchemes[securityName];
22
- if (securityScheme === undefined) {
23
- throw new InvalidSchemaError(['#', 'components', 'securitySchemes'], `security scheme not defined: '${securityName}'`);
24
- }
25
- addSecurityParameters({
26
- securityName,
27
- securityScheme,
28
- parameterSections,
29
- });
30
- });
31
- return {
32
- title,
33
- parameters: parameterSections,
34
- };
35
- });
36
- };
37
- export const addSecurityParameters = ({ securityName, securityScheme, parameterSections, }) => {
38
- switch (securityScheme.type) {
39
- case 'apiKey': {
40
- if (!['header', 'query', 'cookie'].includes(securityScheme.in)) {
41
- throw new InvalidSchemaError(['#', 'components', 'securitySchemes', securityName], `invalid security scheme location provided: '${securityScheme.in}'`);
42
- }
43
- const paramGroup = securityScheme.in;
44
- const schema = { type: 'apiKey' };
45
- copyKeyIfDefined('description', securityScheme, schema);
46
- parameterSections[paramGroup][securityScheme.name] = schema;
47
- return;
48
- }
49
- case 'http': {
50
- const scheme = securityScheme.scheme;
51
- if (scheme === 'basic' || scheme === 'bearer') {
52
- const schema = {
53
- type: 'http',
54
- scheme,
55
- };
56
- copyKeyIfDefined('description', securityScheme, schema);
57
- parameterSections.header['Authorization'] = schema;
58
- }
59
- else {
60
- throw new InvalidSchemaError(['#', 'components', 'securitySchemes', securityName], `encountered unknown HTTP security scheme: '${securityScheme.scheme}'`);
61
- }
62
- return;
63
- }
64
- case 'oauth2': {
65
- const schema = { type: 'oauth2' };
66
- copyKeyIfDefined('description', securityScheme, schema);
67
- parameterSections.header['Authorization'] = schema;
68
- return;
69
- }
70
- case 'openIdConnect': {
71
- return;
72
- }
73
- }
74
- };
@@ -1,8 +0,0 @@
1
- import { OpenAPIV3_1 } from 'openapi-types';
2
- import { Server } from './types/endpoint.js';
3
- type ConvertServersParams = {
4
- servers?: OpenAPIV3_1.ServerObject[];
5
- };
6
- type ConvertServersType = Server[] | undefined;
7
- export declare const convertServers: ({ servers }: ConvertServersParams) => ConvertServersType;
8
- export {};
@@ -1,39 +0,0 @@
1
- export const convertServers = ({ servers }) => {
2
- if (servers === undefined || servers.length === 0) {
3
- return undefined;
4
- }
5
- return servers.map(({ url, description, variables }) => {
6
- return {
7
- url,
8
- description,
9
- variables: convertVariables({ variables }),
10
- };
11
- });
12
- };
13
- const convertVariables = ({ variables }) => {
14
- if (variables === undefined || Object.keys(variables).length === 0) {
15
- return undefined;
16
- }
17
- const newEntries = Object.entries(variables).map(([name, variable]) => {
18
- if (variable.enum) {
19
- return [
20
- name,
21
- {
22
- type: 'enum<string>',
23
- enum: variable.enum,
24
- description: variable.description,
25
- default: variable.default,
26
- },
27
- ];
28
- }
29
- return [
30
- name,
31
- {
32
- type: 'string',
33
- description: variable.description,
34
- default: variable.default,
35
- },
36
- ];
37
- });
38
- return Object.fromEntries(newEntries);
39
- };