Skip to content

Commit 119dbd8

Browse files
committed
feat: added authorization token to headers
Co-authored-by: MarcinFilipek <[email protected]>
1 parent b2d876f commit 119dbd8

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

index.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ interface GenerateApiParamsBase {
110110
* fix up small errors in the swagger source definition
111111
*/
112112
patch?: boolean;
113+
/**
114+
* authorization token
115+
*/
116+
authorizationToken?: string;
113117
}
114118

115119
interface GenerateApiParamsFromPath extends GenerateApiParamsBase {
@@ -133,10 +137,7 @@ interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
133137
spec: import("swagger-schema-official").Spec;
134138
}
135139

136-
export type GenerateApiParams =
137-
| GenerateApiParamsFromPath
138-
| GenerateApiParamsFromUrl
139-
| GenerateApiParamsFromSpecLiteral;
140+
export type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral;
140141

141142
export interface Hooks {
142143
/** calls after parse schema component */

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module.exports = {
6262
typePrefix = config.typePrefix,
6363
typeSuffix = config.typeSuffix,
6464
patch = config.patch,
65+
authorizationToken,
6566
}) =>
6667
new Promise((resolve, reject) => {
6768
addToConfig({
@@ -99,7 +100,7 @@ module.exports = {
99100
});
100101
(spec
101102
? convertSwaggerObject(spec, { patch })
102-
: getSwaggerObject(input, url, disableStrictSSL, disableProxy, { patch })
103+
: getSwaggerObject(input, url, disableStrictSSL, disableProxy, authorizationToken, { patch })
103104
)
104105
.then(({ usageSchema, originalSchema }) => {
105106
const templatePaths = getTemplatePaths(config);

src/swagger.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const parseSwaggerFile = (file) => {
1717
}
1818
};
1919

20-
const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy) =>
20+
const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy, authorizationToken) =>
2121
new Promise((resolve, reject) => {
2222
if (pathIsExist(pathToSwagger)) {
2323
logger.log(`try to get swagger by path "${pathToSwagger}"`);
@@ -33,6 +33,12 @@ const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disablePr
3333
});
3434
}
3535
//
36+
if (authorizationToken) {
37+
axiosOptions.headers = {
38+
Authorization: authorizationToken,
39+
};
40+
}
41+
//
3642
if (disableProxy) axiosOptions.proxy = false;
3743
//
3844
axios
@@ -48,8 +54,15 @@ const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disablePr
4854
}
4955
});
5056

51-
const getSwaggerObject = (pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy, converterOptions) =>
52-
getSwaggerFile(pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy).then((file) =>
57+
const getSwaggerObject = (
58+
pathToSwagger,
59+
urlToSwagger,
60+
disableStrictSSL,
61+
disableProxy,
62+
authorizationToken,
63+
converterOptions,
64+
) =>
65+
getSwaggerFile(pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy, authorizationToken).then((file) =>
5366
convertSwaggerObject(parseSwaggerFile(file), converterOptions),
5467
);
5568

0 commit comments

Comments
 (0)