Skip to content

Commit ee62e72

Browse files
committed
changes
1 parent fefc18c commit ee62e72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1856
-6771
lines changed

.eslintrc.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
module.exports = {
2-
env: {
3-
browser: true,
4-
commonjs: true,
5-
es6: true,
6-
node: true
7-
},
8-
extends: [
9-
'eslint:recommended'
10-
],
11-
globals: {
12-
Atomics: 'readonly',
13-
SharedArrayBuffer: 'readonly'
14-
},
15-
parserOptions: {
16-
ecmaVersion: 2018
17-
},
18-
rules: {
19-
indent: [
20-
'error',
21-
'tab',
22-
{
23-
SwitchCase: 1
24-
}
25-
],
26-
'linebreak-style': [
27-
'error',
28-
'unix'
29-
],
30-
quotes: [
31-
'error',
32-
'single'
33-
],
34-
semi: [
35-
'error',
36-
'always'
37-
]
38-
}
39-
}
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
node: true,
7+
},
8+
extends: [
9+
'prettier',
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
parser: '@typescript-eslint/parser',
14+
globals: {
15+
Atomics: 'readonly',
16+
SharedArrayBuffer: 'readonly',
17+
},
18+
parserOptions: {
19+
ecmaVersion: 2018,
20+
},
21+
plugins: ['prettier', 'unused-imports', '@typescript-eslint'],
22+
rules: {
23+
indent: [
24+
'error',
25+
'tab',
26+
{
27+
SwitchCase: 1,
28+
},
29+
],
30+
'linebreak-style': ['error', 'unix'],
31+
quotes: ['error', 'single'],
32+
semi: ['error', 'always'],
33+
'@typescript-eslint/ban-ts-comment': 'off',
34+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
35+
'@typescript-eslint/consistent-type-imports': [
36+
'error',
37+
{
38+
prefer: 'type-imports',
39+
},
40+
],
41+
},
42+
};

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
dist
39+
.idea

bin/json-schema-to-openapi-schema.js

Lines changed: 73 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,108 @@
11
#!/usr/bin/env node
2-
"use strict";
2+
'use strict';
33

4-
const yargs = require("yargs");
5-
const chalk = require("chalk");
6-
const converter = require("..");
7-
const helpText = require("./help-text.json");
4+
const yargs = require('yargs');
5+
const chalk = require('chalk');
6+
const converter = require('../dist/cjs/index.js').default;
7+
const helpText = require('./help-text.json');
88
const fs = require('fs');
99
const readFileAsync = require('util').promisify(fs.readFile);
1010

11-
(function main () {
12-
let args = parseArgs();
13-
let command = args.command;
14-
let file = args.file;
15-
let options = args.options;
16-
17-
if (options.help) {
18-
// Show help text and exit
19-
console.log(getHelpText(command));
20-
process.exit(0);
21-
}
22-
else if (command === "convert" && file) {
23-
// Convert the JSON Schema file
24-
convert(file, options);
25-
}
26-
else {
27-
// Invalid args. Show help text and exit with non-zero
28-
console.error("Error: Invalid arguments\n");
29-
console.error(getHelpText(command));
30-
process.exit(1);
31-
}
32-
}());
33-
11+
(async function main() {
12+
let args = parseArgs();
13+
let command = args.command;
14+
let file = args.file;
15+
let options = args.options;
16+
17+
if (options.help) {
18+
// Show help text and exit
19+
console.log(getHelpText(command));
20+
process.exit(0);
21+
} else if (command === 'convert' && file) {
22+
// Convert the JSON Schema file
23+
await convert(file, options);
24+
} else {
25+
// Invalid args. Show help text and exit with non-zero
26+
console.error('Error: Invalid arguments\n');
27+
console.error(getHelpText(command));
28+
process.exit(1);
29+
}
30+
})();
3431

3532
/**
3633
* Parses the command-line arguments
3734
*
3835
* @returns {object} - The parsed arguments
3936
*/
40-
function parseArgs () {
41-
// Configure the argument parser
42-
yargs
43-
.option("d", {
44-
alias: "dereference",
45-
type: "boolean",
46-
default: false,
47-
})
48-
.option("h", {
49-
alias: "help",
50-
type: "boolean",
51-
});
52-
53-
// Show the version number on "--version" or "-v"
54-
yargs
55-
.version()
56-
.alias("v", "version");
57-
58-
// Disable the default "--help" behavior
59-
yargs.help(false);
60-
61-
// Parse the command-line arguments
62-
let args = yargs.argv;
63-
64-
// Normalize the parsed arguments
65-
let parsed = {
66-
command: args._[0],
67-
file: args._[1],
68-
options: {
69-
dereference: args.dereference,
70-
help: args.help,
71-
}
72-
};
73-
74-
return parsed;
37+
function parseArgs() {
38+
// Configure the argument parser
39+
yargs
40+
.option('d', {
41+
alias: 'dereference',
42+
type: 'boolean',
43+
default: false,
44+
})
45+
.option('h', {
46+
alias: 'help',
47+
type: 'boolean',
48+
});
49+
50+
// Show the version number on "--version" or "-v"
51+
yargs.version().alias('v', 'version');
52+
53+
// Disable the default "--help" behavior
54+
yargs.help(false);
55+
56+
// Parse the command-line arguments
57+
let args = yargs.argv;
58+
59+
// Normalize the parsed arguments
60+
let parsed = {
61+
command: args._[0],
62+
file: args._[1],
63+
options: {
64+
dereference: args.dereference,
65+
help: args.help,
66+
},
67+
};
68+
69+
return parsed;
7570
}
7671

77-
7872
/**
7973
* Convert an JSON Schema to OpenAPI schema
8074
*
8175
* @param {string} file - The path of the file to convert
8276
* @param {object} options - Conversion options
8377
*/
84-
async function convert (file, options) {
85-
try {
86-
const schema = await readFileAsync(file, 'utf8');
87-
const converted = await converter(JSON.parse(schema), options)
88-
console.log(JSON.stringify(converted));
89-
}
90-
catch (error) {
91-
errorHandler(error);
92-
}
78+
async function convert(file, options) {
79+
try {
80+
const schema = await readFileAsync(file, 'utf8');
81+
const converted = await converter(JSON.parse(schema), options);
82+
console.log(JSON.stringify(converted));
83+
} catch (error) {
84+
errorHandler(error);
85+
}
9386
}
9487

95-
9688
/**
9789
* Returns the help text for the specified command
9890
*
9991
* @param {string} [commandName] - The command to show help text for
10092
* @returns {string} - the help text
10193
*/
102-
function getHelpText (commandName) {
103-
let lines = helpText[commandName] || helpText.default;
104-
return lines.join("\n");
94+
function getHelpText(commandName) {
95+
let lines = helpText[commandName] || helpText.default;
96+
return lines.join('\n');
10597
}
10698

107-
10899
/**
109100
* Writes error information to stderr and exits with a non-zero code
110101
*
111102
* @param {Error} err
112103
*/
113-
function errorHandler (err) {
114-
let errorMessage = process.env.DEBUG ? err.stack : err.message;
115-
console.error(chalk.red(errorMessage));
116-
process.exit(1);
104+
function errorHandler(err) {
105+
let errorMessage = process.env.DEBUG ? err.stack : err.message;
106+
console.error(chalk.red(errorMessage));
107+
process.exit(1);
117108
}

index.d.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)