@scalar/postman-to-openapi 0.1.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/CHANGELOG.md +12 -0
- package/README.md +33 -0
- package/dist/convert.d.ts +9 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +156 -0
- package/dist/helpers/authHelpers.d.ts +12 -0
- package/dist/helpers/authHelpers.d.ts.map +1 -0
- package/dist/helpers/authHelpers.js +99 -0
- package/dist/helpers/externalDocsHelper.d.ts +10 -0
- package/dist/helpers/externalDocsHelper.d.ts.map +1 -0
- package/dist/helpers/externalDocsHelper.js +40 -0
- package/dist/helpers/formDataHelpers.d.ts +8 -0
- package/dist/helpers/formDataHelpers.d.ts.map +1 -0
- package/dist/helpers/formDataHelpers.js +42 -0
- package/dist/helpers/itemHelpers.d.ts +13 -0
- package/dist/helpers/itemHelpers.d.ts.map +1 -0
- package/dist/helpers/itemHelpers.js +236 -0
- package/dist/helpers/licenseContactHelper.d.ts +14 -0
- package/dist/helpers/licenseContactHelper.d.ts.map +1 -0
- package/dist/helpers/licenseContactHelper.js +73 -0
- package/dist/helpers/logoHelper.d.ts +13 -0
- package/dist/helpers/logoHelper.d.ts.map +1 -0
- package/dist/helpers/logoHelper.js +24 -0
- package/dist/helpers/md-utils.d.ts +6 -0
- package/dist/helpers/md-utils.d.ts.map +1 -0
- package/dist/helpers/md-utils.js +40 -0
- package/dist/helpers/parameterHelpers.d.ts +12 -0
- package/dist/helpers/parameterHelpers.d.ts.map +1 -0
- package/dist/helpers/parameterHelpers.js +109 -0
- package/dist/helpers/requestBodyHelpers.d.ts +8 -0
- package/dist/helpers/requestBodyHelpers.d.ts.map +1 -0
- package/dist/helpers/requestBodyHelpers.js +79 -0
- package/dist/helpers/responseHelpers.d.ts +9 -0
- package/dist/helpers/responseHelpers.d.ts.map +1 -0
- package/dist/helpers/responseHelpers.js +52 -0
- package/dist/helpers/schemaHelpers.d.ts +15 -0
- package/dist/helpers/schemaHelpers.d.ts.map +1 -0
- package/dist/helpers/schemaHelpers.js +52 -0
- package/dist/helpers/serverHelpers.d.ts +9 -0
- package/dist/helpers/serverHelpers.d.ts.map +1 -0
- package/dist/helpers/serverHelpers.js +29 -0
- package/dist/helpers/statusCodeHelpers.d.ts +10 -0
- package/dist/helpers/statusCodeHelpers.d.ts.map +1 -0
- package/dist/helpers/statusCodeHelpers.js +47 -0
- package/dist/helpers/urlHelpers.d.ts +19 -0
- package/dist/helpers/urlHelpers.d.ts.map +1 -0
- package/dist/helpers/urlHelpers.js +52 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +229 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Postman to OpenAPI Converter
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@scalar/postman-to-openapi)
|
|
4
|
+
[](https://www.npmjs.com/package/@scalar/postman-to-openapi)
|
|
5
|
+
[](https://www.npmjs.com/package/@scalar/postman-to-openapi)
|
|
6
|
+
[](https://discord.gg/scalar)
|
|
7
|
+
|
|
8
|
+
Convert Postman collections to [the open standard OpenAPI](https://github.com/OAI/OpenAPI-Specification). Free the postman!
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @scalar/postman-to-openapi
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { convert } from '@scalar/postman-to-openapi'
|
|
20
|
+
|
|
21
|
+
// Free the postman!
|
|
22
|
+
const result = await convert(myPostmanCollection)
|
|
23
|
+
|
|
24
|
+
console.log(result)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Community
|
|
28
|
+
|
|
29
|
+
We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
|
|
30
|
+
|
|
31
|
+
## Thank you!
|
|
32
|
+
|
|
33
|
+
This package is based on the existing [`postman-to-openapi`](https://github.com/joolfe/postman-to-openapi) by [@joolfe](https://github.com/joolfe). We update the code and adapted it to our use case. You might consider our package the modern successor.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
2
|
+
import type { PostmanCollection } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a Postman Collection to an OpenAPI 3.1.0 document.
|
|
5
|
+
* This function processes the collection's information, servers, authentication,
|
|
6
|
+
* and items to create a corresponding OpenAPI structure.
|
|
7
|
+
*/
|
|
8
|
+
export declare function convert(postmanCollection: PostmanCollection | string): OpenAPIV3_1.Document;
|
|
9
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AASxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,iBAAiB,EAAE,iBAAiB,GAAG,MAAM,GAC5C,WAAW,CAAC,QAAQ,CAuKtB"}
|
package/dist/convert.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { processAuth } from './helpers/authHelpers.js';
|
|
2
|
+
import { processExternalDocs } from './helpers/externalDocsHelper.js';
|
|
3
|
+
import { processItem } from './helpers/itemHelpers.js';
|
|
4
|
+
import { processLicenseAndContact } from './helpers/licenseContactHelper.js';
|
|
5
|
+
import { processLogo } from './helpers/logoHelper.js';
|
|
6
|
+
import { parseServers } from './helpers/serverHelpers.js';
|
|
7
|
+
import { normalizePath } from './helpers/urlHelpers.js';
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Postman Collection to an OpenAPI 3.1.0 document.
|
|
10
|
+
* This function processes the collection's information, servers, authentication,
|
|
11
|
+
* and items to create a corresponding OpenAPI structure.
|
|
12
|
+
*/
|
|
13
|
+
export function convert(postmanCollection) {
|
|
14
|
+
// Parse string input if provided
|
|
15
|
+
const collection = typeof postmanCollection === 'string'
|
|
16
|
+
? JSON.parse(postmanCollection)
|
|
17
|
+
: postmanCollection;
|
|
18
|
+
// Extract title from collection info, fallback to 'API' if not provided
|
|
19
|
+
const title = collection.info.name || 'API';
|
|
20
|
+
// Look for version in collection variables, default to '1.0.0'
|
|
21
|
+
const version = collection.variable?.find((v) => v.key === 'version')?.value ||
|
|
22
|
+
'1.0.0';
|
|
23
|
+
// Handle different description formats in Postman
|
|
24
|
+
const description = typeof collection.info.description === 'string'
|
|
25
|
+
? collection.info.description
|
|
26
|
+
: collection.info.description?.content || '';
|
|
27
|
+
// Process license and contact information
|
|
28
|
+
const { license, contact } = processLicenseAndContact(collection);
|
|
29
|
+
// Process logo information
|
|
30
|
+
const logo = processLogo(collection);
|
|
31
|
+
// Initialize the OpenAPI document with required fields
|
|
32
|
+
const openapi = {
|
|
33
|
+
openapi: '3.1.0',
|
|
34
|
+
info: {
|
|
35
|
+
title,
|
|
36
|
+
version,
|
|
37
|
+
...(description && { description }),
|
|
38
|
+
...(license && { license }),
|
|
39
|
+
...(contact && { contact }),
|
|
40
|
+
...(logo && { 'x-logo': logo }),
|
|
41
|
+
},
|
|
42
|
+
servers: parseServers(collection),
|
|
43
|
+
paths: {},
|
|
44
|
+
};
|
|
45
|
+
// Process external docs
|
|
46
|
+
const externalDocs = processExternalDocs(collection);
|
|
47
|
+
if (externalDocs) {
|
|
48
|
+
openapi.externalDocs = externalDocs;
|
|
49
|
+
}
|
|
50
|
+
// Process authentication if present in the collection
|
|
51
|
+
if (collection.auth) {
|
|
52
|
+
const { securitySchemes, security } = processAuth(collection.auth);
|
|
53
|
+
openapi.components = openapi.components || {};
|
|
54
|
+
openapi.components.securitySchemes = {
|
|
55
|
+
...openapi.components.securitySchemes,
|
|
56
|
+
...securitySchemes,
|
|
57
|
+
};
|
|
58
|
+
openapi.security = security;
|
|
59
|
+
}
|
|
60
|
+
// Process each item in the collection and merge into OpenAPI spec
|
|
61
|
+
if (collection.item) {
|
|
62
|
+
collection.item.forEach((item) => {
|
|
63
|
+
const { paths: itemPaths, components: itemComponents } = processItem(item);
|
|
64
|
+
// Merge paths from the current item
|
|
65
|
+
openapi.paths = openapi.paths || {};
|
|
66
|
+
for (const [pathKey, pathItem] of Object.entries(itemPaths)) {
|
|
67
|
+
// Convert colon-style params to curly brace style
|
|
68
|
+
const normalizedPathKey = normalizePath(pathKey);
|
|
69
|
+
/**
|
|
70
|
+
* this is a bit of a hack to skip empty paths only if they have no parameters
|
|
71
|
+
* because there is a test where if I remove the empty path it breaks the test
|
|
72
|
+
* but there is another test where if I leave the empty path it breaks the test
|
|
73
|
+
* so I added this check to only remove the empty path if all the methods on it have no parameters
|
|
74
|
+
*/
|
|
75
|
+
if (normalizedPathKey === '/') {
|
|
76
|
+
const allMethodsHaveEmptyParams = Object.values(pathItem || {}).every((method) => !method.parameters || method.parameters.length === 0);
|
|
77
|
+
if (allMethodsHaveEmptyParams) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!openapi.paths[normalizedPathKey]) {
|
|
82
|
+
openapi.paths[normalizedPathKey] = pathItem;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
openapi.paths[normalizedPathKey] = {
|
|
86
|
+
...openapi.paths[normalizedPathKey],
|
|
87
|
+
...pathItem,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Handle the /raw endpoint specifically
|
|
91
|
+
if (normalizedPathKey === '/raw' && pathItem?.post) {
|
|
92
|
+
if (pathItem.post.requestBody?.content['text/plain']) {
|
|
93
|
+
pathItem.post.requestBody.content['application/json'] = {
|
|
94
|
+
schema: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
examples: [],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
delete pathItem.post.requestBody.content['text/plain'];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Merge security schemes from the current item
|
|
104
|
+
if (itemComponents?.securitySchemes) {
|
|
105
|
+
openapi.components = openapi.components || {};
|
|
106
|
+
openapi.components.securitySchemes = {
|
|
107
|
+
...openapi.components.securitySchemes,
|
|
108
|
+
...itemComponents.securitySchemes,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Clean up the generated paths
|
|
114
|
+
if (openapi.paths) {
|
|
115
|
+
Object.values(openapi.paths).forEach((path) => {
|
|
116
|
+
if (path) {
|
|
117
|
+
Object.values(path).forEach((method) => {
|
|
118
|
+
if (method && 'parameters' in method) {
|
|
119
|
+
// Remove empty parameters array to keep spec clean
|
|
120
|
+
if (method.parameters?.length === 0) {
|
|
121
|
+
delete method.parameters;
|
|
122
|
+
}
|
|
123
|
+
// Handle request bodies
|
|
124
|
+
if (method.requestBody?.content) {
|
|
125
|
+
const content = method.requestBody.content;
|
|
126
|
+
if (Object.keys(content).length === 0) {
|
|
127
|
+
// Keep an empty requestBody with text/plain content
|
|
128
|
+
method.requestBody = {
|
|
129
|
+
content: {
|
|
130
|
+
'text/plain': {},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
else if ('text/plain' in content) {
|
|
135
|
+
// Preserve schema if it exists, otherwise keep an empty object
|
|
136
|
+
if (!content['text/plain'].schema ||
|
|
137
|
+
Object.keys(content['text/plain'].schema).length === 0) {
|
|
138
|
+
content['text/plain'] = {};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Ensure all methods have a description, but don't add an empty one if it doesn't exist
|
|
143
|
+
if (!method.description) {
|
|
144
|
+
delete method.description;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Remove empty components object
|
|
152
|
+
if (Object.keys(openapi.components || {}).length === 0) {
|
|
153
|
+
delete openapi.components;
|
|
154
|
+
}
|
|
155
|
+
return openapi;
|
|
156
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
2
|
+
import type { Auth } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Processes authentication information from a Postman collection and updates
|
|
5
|
+
* the OpenAPI document with the corresponding security schemes and requirements.
|
|
6
|
+
* Supports API key, basic auth, bearer token, and OAuth2 authentication types.
|
|
7
|
+
*/
|
|
8
|
+
export declare function processAuth(auth: Auth): {
|
|
9
|
+
securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>;
|
|
10
|
+
security: OpenAPIV3_1.SecurityRequirementObject[];
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=authHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/authHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAyFpC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG;IACvC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAA;IACjE,QAAQ,EAAE,WAAW,CAAC,yBAAyB,EAAE,CAAA;CAClD,CAoBA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Constants for security scheme names and URLs
|
|
2
|
+
const AUTH_SCHEMES = {
|
|
3
|
+
API_KEY: 'apikeyAuth',
|
|
4
|
+
BASIC: 'basicAuth',
|
|
5
|
+
BEARER: 'bearerAuth',
|
|
6
|
+
OAUTH2: 'oauth2Auth',
|
|
7
|
+
};
|
|
8
|
+
const OAUTH2_DEFAULTS = {
|
|
9
|
+
AUTHORIZE_URL: 'https://example.com/oauth/authorize',
|
|
10
|
+
TOKEN_URL: 'https://example.com/oauth/token',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates security configuration for API key authentication
|
|
14
|
+
*/
|
|
15
|
+
function createApiKeyConfig() {
|
|
16
|
+
return {
|
|
17
|
+
scheme: {
|
|
18
|
+
type: 'apiKey',
|
|
19
|
+
name: 'api_key',
|
|
20
|
+
in: 'header',
|
|
21
|
+
},
|
|
22
|
+
requirement: { [AUTH_SCHEMES.API_KEY]: [] },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates security configuration for Basic authentication
|
|
27
|
+
*/
|
|
28
|
+
function createBasicConfig() {
|
|
29
|
+
return {
|
|
30
|
+
scheme: {
|
|
31
|
+
type: 'http',
|
|
32
|
+
scheme: 'basic',
|
|
33
|
+
},
|
|
34
|
+
requirement: { [AUTH_SCHEMES.BASIC]: [] },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates security configuration for Bearer token authentication
|
|
39
|
+
*/
|
|
40
|
+
function createBearerConfig() {
|
|
41
|
+
return {
|
|
42
|
+
scheme: {
|
|
43
|
+
type: 'http',
|
|
44
|
+
scheme: 'bearer',
|
|
45
|
+
},
|
|
46
|
+
requirement: { [AUTH_SCHEMES.BEARER]: [] },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates security configuration for OAuth2 authentication
|
|
51
|
+
*/
|
|
52
|
+
function createOAuth2Config() {
|
|
53
|
+
return {
|
|
54
|
+
scheme: {
|
|
55
|
+
type: 'oauth2',
|
|
56
|
+
flows: {
|
|
57
|
+
authorizationCode: {
|
|
58
|
+
authorizationUrl: OAUTH2_DEFAULTS.AUTHORIZE_URL,
|
|
59
|
+
tokenUrl: OAUTH2_DEFAULTS.TOKEN_URL,
|
|
60
|
+
scopes: {},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
requirement: { [AUTH_SCHEMES.OAUTH2]: [] },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Maps authentication types to their configuration creators
|
|
69
|
+
*/
|
|
70
|
+
const AUTH_TYPE_HANDLERS = {
|
|
71
|
+
apikey: createApiKeyConfig,
|
|
72
|
+
basic: createBasicConfig,
|
|
73
|
+
bearer: createBearerConfig,
|
|
74
|
+
oauth2: createOAuth2Config,
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Processes authentication information from a Postman collection and updates
|
|
78
|
+
* the OpenAPI document with the corresponding security schemes and requirements.
|
|
79
|
+
* Supports API key, basic auth, bearer token, and OAuth2 authentication types.
|
|
80
|
+
*/
|
|
81
|
+
export function processAuth(auth) {
|
|
82
|
+
const securitySchemes = {};
|
|
83
|
+
const security = [];
|
|
84
|
+
try {
|
|
85
|
+
const handler = AUTH_TYPE_HANDLERS[auth.type];
|
|
86
|
+
if (!handler) {
|
|
87
|
+
throw new Error(`Unsupported authentication type: ${auth.type}`);
|
|
88
|
+
}
|
|
89
|
+
const { scheme, requirement } = handler();
|
|
90
|
+
const schemeKey = `${auth.type}Auth`;
|
|
91
|
+
securitySchemes[schemeKey] = scheme;
|
|
92
|
+
security.push(requirement);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Error processing authentication:', error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return { securitySchemes, security };
|
|
99
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
2
|
+
import type { PostmanCollection } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Processes the external documentation information from a Postman Collection.
|
|
5
|
+
* This function checks for 'externalDocs.url' and 'externalDocs.description'
|
|
6
|
+
* in the collection variables and creates an OpenAPI External Documentation Object
|
|
7
|
+
* if the URL is present.
|
|
8
|
+
*/
|
|
9
|
+
export declare function processExternalDocs(collection: PostmanCollection): OpenAPIV3_1.ExternalDocumentationObject | undefined;
|
|
10
|
+
//# sourceMappingURL=externalDocsHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"externalDocsHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/externalDocsHelper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,UAAU,CAAA;AAkB3D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,iBAAiB,GAC5B,WAAW,CAAC,2BAA2B,GAAG,SAAS,CA2BrD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Constants for variable keys
|
|
2
|
+
const VARIABLE_KEYS = {
|
|
3
|
+
URL: 'externalDocs.url',
|
|
4
|
+
DESCRIPTION: 'externalDocs.description',
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Finds a specific variable in the collection by its key
|
|
8
|
+
*/
|
|
9
|
+
function findVariable(collection, key) {
|
|
10
|
+
return collection.variable?.find((v) => v.key === key);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Processes the external documentation information from a Postman Collection.
|
|
14
|
+
* This function checks for 'externalDocs.url' and 'externalDocs.description'
|
|
15
|
+
* in the collection variables and creates an OpenAPI External Documentation Object
|
|
16
|
+
* if the URL is present.
|
|
17
|
+
*/
|
|
18
|
+
export function processExternalDocs(collection) {
|
|
19
|
+
try {
|
|
20
|
+
const urlVariable = findVariable(collection, VARIABLE_KEYS.URL);
|
|
21
|
+
const descriptionVariable = findVariable(collection, VARIABLE_KEYS.DESCRIPTION);
|
|
22
|
+
if (!urlVariable?.value) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
if (typeof urlVariable.value !== 'string') {
|
|
26
|
+
throw new Error('External docs URL must be a string');
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
url: urlVariable.value,
|
|
30
|
+
...(descriptionVariable?.value &&
|
|
31
|
+
typeof descriptionVariable.value === 'string' && {
|
|
32
|
+
description: descriptionVariable.value,
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('Error processing external docs:', error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
2
|
+
import type { FormParameter } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Processes form data parameters from a Postman request and converts them into an OpenAPI schema.
|
|
5
|
+
* Handles file uploads, required fields, and descriptions.
|
|
6
|
+
*/
|
|
7
|
+
export declare function processFormDataSchema(formdata: FormParameter[]): OpenAPIV3_1.SchemaObject;
|
|
8
|
+
//# sourceMappingURL=formDataHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formDataHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/formDataHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,aAAa,EAAE,GACxB,WAAW,CAAC,YAAY,CA6C1B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes form data parameters from a Postman request and converts them into an OpenAPI schema.
|
|
3
|
+
* Handles file uploads, required fields, and descriptions.
|
|
4
|
+
*/
|
|
5
|
+
export function processFormDataSchema(formdata) {
|
|
6
|
+
const schema = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
properties: {},
|
|
9
|
+
required: [],
|
|
10
|
+
};
|
|
11
|
+
formdata.forEach((item) => {
|
|
12
|
+
if (!schema.properties)
|
|
13
|
+
return;
|
|
14
|
+
const property = {
|
|
15
|
+
type: 'string',
|
|
16
|
+
};
|
|
17
|
+
// Add description if present, handling both string and object descriptions
|
|
18
|
+
if (item.description) {
|
|
19
|
+
const descriptionText = typeof item.description === 'string'
|
|
20
|
+
? item.description
|
|
21
|
+
: item.description.content || '';
|
|
22
|
+
property.description = descriptionText.replace(' [required]', '');
|
|
23
|
+
// If [required] was present, add to required array
|
|
24
|
+
if (descriptionText.includes('[required]')) {
|
|
25
|
+
schema.required?.push(item.key);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Handle file type fields
|
|
29
|
+
if (item.type === 'file') {
|
|
30
|
+
property.format = 'binary';
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
property.example = item.value;
|
|
34
|
+
}
|
|
35
|
+
schema.properties[item.key] = property;
|
|
36
|
+
});
|
|
37
|
+
// Only keep required array if it has items
|
|
38
|
+
if (schema.required?.length === 0) {
|
|
39
|
+
delete schema.required;
|
|
40
|
+
}
|
|
41
|
+
return schema;
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
2
|
+
import type { Item, ItemGroup } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Processes a Postman collection item or item group and returns
|
|
5
|
+
* the corresponding OpenAPI paths and components.
|
|
6
|
+
* Handles nested item groups, extracts request details, and generates corresponding
|
|
7
|
+
* OpenAPI path items and operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare function processItem(item: Item | ItemGroup, parentTags?: string[], parentPath?: string): {
|
|
10
|
+
paths: OpenAPIV3_1.PathsObject;
|
|
11
|
+
components: OpenAPIV3_1.ComponentsObject;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=itemHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/itemHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAuB/C;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,GAAG,SAAS,EACtB,UAAU,GAAE,MAAM,EAAO,EACzB,UAAU,GAAE,MAAW,GACtB;IACD,KAAK,EAAE,WAAW,CAAC,WAAW,CAAA;IAC9B,UAAU,EAAE,WAAW,CAAC,gBAAgB,CAAA;CACzC,CA6LA"}
|