Skip to content

Commit 8443a58

Browse files
committed
Refactor
1 parent b2ddda8 commit 8443a58

File tree

195 files changed

+59208
-887577
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

+59208
-887577
lines changed

.gitignore

Lines changed: 1 addition & 8 deletions
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

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 159 additions & 81 deletions
Large diffs are not rendered by default.

bin/cli.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +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
28-
--raw-schema (optional) Parse as partial schema (raw components)
2927
--paths-enum, -pe (optional) Generate an enum containing all API paths.
3028
--export-type (optional) Export type instead of interface
3129
--support-array-length (optional) Generate tuples using array minItems / maxItems
@@ -38,6 +36,7 @@ const OUTPUT_FILE = "FILE";
3836
const OUTPUT_STDOUT = "STDOUT";
3937
const CWD = new URL(`file://${process.cwd()}/`);
4038
const EXT_RE = /\.[^.]+$/i;
39+
const HTTP_RE = /^https?:\/\//;
4140

4241
const timeStart = process.hrtime();
4342

@@ -47,30 +46,28 @@ function errorAndExit(errorMessage) {
4746
}
4847

4948
const [, , input, ...args] = process.argv;
49+
if (args.includes("-ap")) errorAndExit(`The -ap alias has been deprecated. Use "--additional-properties" instead.`);
50+
if (args.includes("-it")) errorAndExit(`The -it alias has been deprecated. Use "--immutable-types" instead.`);
51+
5052
const flags = parser(args, {
5153
array: ["header"],
5254
boolean: [
5355
"defaultNonNullable",
5456
"immutableTypes",
5557
"contentNever",
56-
"rawSchema",
5758
"exportType",
5859
"supportArrayLength",
59-
"makePathsEnum",
6060
"pathParamsAsTypes",
6161
"alphabetize",
6262
],
6363
number: ["version"],
64-
string: ["auth", "header", "headersObject", "httpMethod", "prettierConfig"],
64+
string: ["auth", "header", "headersObject", "httpMethod"],
6565
alias: {
66-
additionalProperties: ["ap"],
6766
header: ["x"],
67+
exportType: ["t"],
6868
headersObject: ["h"],
6969
httpMethod: ["m"],
70-
immutableTypes: ["it"],
7170
output: ["o"],
72-
prettierConfig: ["c"],
73-
makePathsEnum: ["pe"],
7471
},
7572
default: {
7673
httpMethod: "GET",
@@ -103,9 +100,6 @@ async function generateSchema(pathToSpec) {
103100
auth: flags.auth,
104101
defaultNonNullable: flags.defaultNonNullable,
105102
immutableTypes: flags.immutableTypes,
106-
prettierConfig: flags.prettierConfig,
107-
rawSchema: flags.rawSchema,
108-
makePathsEnum: flags.makePathsEnum,
109103
contentNever: flags.contentNever,
110104
silent: output === OUTPUT_STDOUT,
111105
version: flags.version,
@@ -156,13 +150,8 @@ async function main() {
156150
console.info(`✨ ${BOLD}openapi-typescript ${packageJSON.version}${RESET}`); // only log if we’re NOT writing to stdout
157151
}
158152

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

examples/github-api.ts

Lines changed: 34215 additions & 42223 deletions
Large diffs are not rendered by default.

examples/stripe-api.ts

Lines changed: 21807 additions & 35096 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 11 additions & 11 deletions
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)