Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# next release

# 4.0.3

Features:
- `--disableStrictSSL` option for disable strict SSL statement with fetching swagger schema. (Thanks @kel666 for PR with feature request)
This option fix problem #114

# 4.0.2

Fixes:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Options:
--module-name-index <number> determines which path index should be used for routes separation (default: 0)
(example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)
--modular generate separated files for http client, data contracts, and routes (default: false)
--disableStrictSSL disabled strict SSL (default: false)
-h, --help display help for command
```

Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ interface GenerateApiParams {
* determines which path index should be used for routes separation
*/
moduleNameIndex?: number;
/**
* disabled SSL check
*/
disableStrictSSL?: boolean;
/**
* generate separated files for http client, data contracts, and routes (default: false)
*/
Expand Down Expand Up @@ -207,6 +211,7 @@ export interface GenerateApiConfiguration {
componentsMap: Record<string, SchemaComponent>;
convertedFromSwagger2: boolean;
moduleNameIndex: number;
disableStrictSSSL: boolean;
extractRequestParams: boolean;
fileNames: {
dataContracts: string;
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ program
"--module-name-index <number>",
"determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)",
0,
);
)
.option("--disableStrictSSL", "disabled strict SSL", false);

program.parse(process.argv);

Expand All @@ -78,6 +79,7 @@ const {
moduleNameIndex,
extractRequestParams,
enumNamesAsValues,
disableStrictSSL,
} = program;

generateApi({
Expand All @@ -96,4 +98,5 @@ generateApi({
toJS: !!js,
enumNamesAsValues: enumNamesAsValues,
moduleNameIndex: +(moduleNameIndex || 0),
disableStrictSSL: !!disableStrictSSL,
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-typescript-api",
"version": "4.0.2",
"version": "4.0.3",
"description": "Create typescript api module from swagger schema",
"scripts": {
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts --extract-request-params --enum-names-as-values",
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const config = {

/** url index from paths used for merging into modules */
moduleNameIndex: 0,
disableStrictSSL: false,
extractRequestParams: false,
fileNames: {
dataContracts: "data-contracts",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
hooks: rawHooks,
extraTemplates,
enumNamesAsValues,
disableStrictSSL = config.disableStrictSSL,
}) =>
new Promise((resolve, reject) => {
addToConfig({
Expand All @@ -55,8 +56,9 @@ module.exports = {
extractRequestParams,
hooks: _.merge(config.hooks, rawHooks || {}),
enumNamesAsValues,
disableStrictSSL,
});
(spec ? convertSwaggerObject(spec) : getSwaggerObject(input, url))
(spec ? convertSwaggerObject(spec) : getSwaggerObject(input, url, disableStrictSSL))
.then(({ usageSchema, originalSchema }) => {
const templatesToRender = getTemplates(config);

Expand Down
15 changes: 11 additions & 4 deletions src/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const _ = require("lodash");
const yaml = require("js-yaml");
const axios = require("axios");
const converter = require("swagger2openapi");
const https = require("https");
const { addToConfig } = require("./config");
const { pathIsExist, getFileContent } = require("./files");

Expand All @@ -15,19 +16,25 @@ const parseSwaggerFile = (file) => {
}
};

const getSwaggerFile = (pathToSwagger, urlToSwagger) =>
const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL) =>
new Promise((resolve) => {
if (pathIsExist(pathToSwagger)) {
console.log(`✨ try to get swagger by path "${pathToSwagger}"`);
resolve(getFileContent(pathToSwagger));
} else {
console.log(`✨ try to get swagger by url "${urlToSwagger}"`);
axios.get(urlToSwagger).then((res) => resolve(res.data));
let agent = undefined;
if (disableStrictSSL) {
agent = new https.Agent({
rejectUnauthorized: false,
});
}
axios.get(urlToSwagger, { httpsAgent: agent }).then((res) => resolve(res.data));
}
});

const getSwaggerObject = (pathToSwagger, urlToSwagger) =>
getSwaggerFile(pathToSwagger, urlToSwagger).then((file) =>
const getSwaggerObject = (pathToSwagger, urlToSwagger, disableStrictSSL) =>
getSwaggerFile(pathToSwagger, urlToSwagger, disableStrictSSL).then((file) =>
convertSwaggerObject(parseSwaggerFile(file)),
);

Expand Down