Skip to content

Commit 59fd933

Browse files
committed
Refactor
1 parent b2ddda8 commit 59fd933

File tree

195 files changed

+59102
-887573
lines changed

Some content is hidden

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

195 files changed

+59102
-887573
lines changed

.gitignore

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
.dccache
2-
.cache
31
.DS_Store
4-
.idea/
5-
.nyc_output/
6-
**/generated/
7-
**/__snapshots__/
2+
test/fixtures/*.yaml
83
coverage/
94
dist
105
node_modules
11-
yarn.lock
12-
yarn-error.log

.npmrc

-1
This file was deleted.

README.md

+159-81
Large diffs are not rendered by default.

bin/cli.js

+7-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Options
2424
--content-never (optional) If supplied, an omitted reponse \`content\` property will be generated as \`never\` instead of \`unknown\`
2525
--additional-properties, -ap (optional) Allow arbitrary properties for all schema objects without "additionalProperties: false"
2626
--default-non-nullable (optional) If a schema object has a default value set, don’t mark it as nullable
27-
--prettier-config, -c (optional) specify path to Prettier config file
2827
--raw-schema (optional) Parse as partial schema (raw components)
2928
--paths-enum, -pe (optional) Generate an enum containing all API paths.
3029
--export-type (optional) Export type instead of interface
@@ -38,6 +37,7 @@ const OUTPUT_FILE = "FILE";
3837
const OUTPUT_STDOUT = "STDOUT";
3938
const CWD = new URL(`file://${process.cwd()}/`);
4039
const EXT_RE = /\.[^.]+$/i;
40+
const HTTP_RE = /^https?:\/\//;
4141

4242
const timeStart = process.hrtime();
4343

@@ -47,30 +47,28 @@ function errorAndExit(errorMessage) {
4747
}
4848

4949
const [, , input, ...args] = process.argv;
50+
if (args.includes("-ap")) errorAndExit(`The -ap alias has been deprecated. Use "--additional-properties" instead.`);
51+
if (args.includes("-it")) errorAndExit(`The -it alias has been deprecated. Use "--immutable-types" instead.`);
52+
5053
const flags = parser(args, {
5154
array: ["header"],
5255
boolean: [
5356
"defaultNonNullable",
5457
"immutableTypes",
5558
"contentNever",
56-
"rawSchema",
5759
"exportType",
5860
"supportArrayLength",
59-
"makePathsEnum",
6061
"pathParamsAsTypes",
6162
"alphabetize",
6263
],
6364
number: ["version"],
64-
string: ["auth", "header", "headersObject", "httpMethod", "prettierConfig"],
65+
string: ["auth", "header", "headersObject", "httpMethod"],
6566
alias: {
66-
additionalProperties: ["ap"],
6767
header: ["x"],
68+
exportType: ["t"],
6869
headersObject: ["h"],
6970
httpMethod: ["m"],
70-
immutableTypes: ["it"],
7171
output: ["o"],
72-
prettierConfig: ["c"],
73-
makePathsEnum: ["pe"],
7472
},
7573
default: {
7674
httpMethod: "GET",
@@ -103,9 +101,6 @@ async function generateSchema(pathToSpec) {
103101
auth: flags.auth,
104102
defaultNonNullable: flags.defaultNonNullable,
105103
immutableTypes: flags.immutableTypes,
106-
prettierConfig: flags.prettierConfig,
107-
rawSchema: flags.rawSchema,
108-
makePathsEnum: flags.makePathsEnum,
109104
contentNever: flags.contentNever,
110105
silent: output === OUTPUT_STDOUT,
111106
version: flags.version,
@@ -156,13 +151,8 @@ async function main() {
156151
console.info(`✨ ${BOLD}openapi-typescript ${packageJSON.version}${RESET}`); // only log if we’re NOT writing to stdout
157152
}
158153

159-
// error: --raw-schema
160-
if (flags.rawSchema && !flags.version) {
161-
throw new Error(`--raw-schema requires --version flag`);
162-
}
163-
164154
// handle remote schema, exit
165-
if (/^https?:\/\//.test(pathToSpec)) {
155+
if (HTTP_RE.test(pathToSpec)) {
166156
if (output !== "." && output === OUTPUT_FILE) fs.mkdirSync(outputDir, { recursive: true });
167157
await generateSchema(pathToSpec);
168158
return;

examples/github-api.ts

+34,215-42,223
Large diffs are not rendered by default.

examples/stripe-api.ts

+21,807-35,096
Large diffs are not rendered by default.

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,39 @@
3535
},
3636
"homepage": "https://github.com/drwpow/openapi-typescript#readme",
3737
"scripts": {
38-
"build": "del dist && tsc",
39-
"dev": "tsc --watch",
38+
"build": "del dist && tsc -p tsconfig.build.json",
39+
"dev": "tsc -p tsconfig.build.json --watch",
40+
"download:schemas": "node ./scripts/download-schemas.js",
4041
"format": "npm run prettier -w .",
4142
"lint": "eslint .",
42-
"prepare": "npm run build",
4343
"pregenerate": "npm run build",
44-
"update:examples": "node ./scripts/update-examples.js",
44+
"prepare": "npm run build && npm run download:schemas",
4545
"test": "vitest run",
4646
"test:coverage": "vitest run --coverage",
47+
"update:examples": "node ./scripts/update-examples.js",
4748
"version": "npm run build"
4849
},
4950
"dependencies": {
5051
"fast-glob": "^3.2.12",
5152
"js-yaml": "^4.1.0",
5253
"mime": "^3.0.0",
53-
"prettier": "^2.7.1",
5454
"undici": "^5.12.0",
5555
"yargs-parser": "^21.1.1"
5656
},
5757
"devDependencies": {
5858
"@types/js-yaml": "^4.0.5",
5959
"@types/mime": "^2.0.3",
60-
"@types/node": "^18.11.7",
61-
"@types/prettier": "^2.7.1",
62-
"@typescript-eslint/eslint-plugin": "^5.41.0",
63-
"@typescript-eslint/parser": "^5.41.0",
64-
"@vitest/coverage-c8": "^0.24.3",
60+
"@types/node": "^18.11.9",
61+
"@typescript-eslint/eslint-plugin": "^5.42.0",
62+
"@typescript-eslint/parser": "^5.42.0",
63+
"@vitest/coverage-c8": "^0.24.5",
6564
"del-cli": "^5.0.0",
6665
"eol": "^0.9.1",
6766
"eslint": "^8.26.0",
6867
"eslint-config-prettier": "^8.5.0",
6968
"eslint-plugin-prettier": "^4.2.1",
69+
"prettier": "^2.7.1",
7070
"typescript": "^4.8.4",
71-
"vitest": "^0.24.3"
71+
"vitest": "^0.24.5"
7272
}
7373
}

0 commit comments

Comments
 (0)