Skip to content

Performance improvements, improve remote $refs #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2022
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
5 changes: 1 addition & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
bin
coverage
dist
example/*.ts
examples
**/generated/*
**/expected/*
**/specs/*
test/fixtures
11 changes: 10 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ module.exports = {
parserOptions: {
project: ["./tsconfig.json"],
},
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
extends: ["plugin:prettier/recommended", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
plugins: ["@typescript-eslint"],
overrides: [
{
files: ["**/*.test.*"],
rules: {
"@typescript-eslint/ban-ts-comment": "off", // allow @ts-ignore only in tests
"@typescript-eslint/no-empty-function": "off", // don’t enforce this in tests
},
},
],
};
38 changes: 30 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- main
pull_request:

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-22.04
Expand All @@ -18,11 +22,22 @@ jobs:
- run: pnpm i
- run: npm run lint
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 18
- run: pnpm i
- run: npm run test:coverage
test-node-versions:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [16.x, 18.x]
os: [macos-12, ubuntu-22.04, windows-2022]
runs-on: ${{ matrix.os }}
node-version: [16.x, 19.x]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
Expand All @@ -33,8 +48,15 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: pnpm i
- run: npm test
if: matrix.os != 'macos-12' || matrix.node-version != '18.x'
- run: npm run test:coverage
if: matrix.os == 'macos-12' && matrix.node-version == '18.x'
- uses: codecov/codecov-action@v3
if: matrix.os == 'macos-12' && matrix.node-version == '18.x'
test-macos:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
version: 18
- run: pnpm i
- run: npm test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
test/fixtures/*.yaml
coverage/
dist
node_modules
test/fixtures/**/*
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
examples/**/*.ts
test/fixtures/**/*
*.md
*.yaml
*.yml
22 changes: 7 additions & 15 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { URL } from "node:url";
import glob from "fast-glob";
import parser from "yargs-parser";
import openapiTS from "../dist/index.js";

const GREEN = "\u001b[32m";
const BOLD = "\u001b[1m";
const RESET = "\u001b[0m";
import { c, error } from "../dist/utils.js";

const HELP = `Usage
$ openapi-typescript [input] [options]
Expand Down Expand Up @@ -38,11 +35,6 @@ const HTTP_RE = /^https?:\/\//;

const timeStart = process.hrtime();

function errorAndExit(errorMessage) {
process.exitCode = 1; // needed for async functions
throw new Error(errorMessage);
}

const [, , ...args] = process.argv;
if (args.includes("-ap")) errorAndExit(`The -ap alias has been deprecated. Use "--additional-properties" instead.`);
if (args.includes("-it")) errorAndExit(`The -it alias has been deprecated. Use "--immutable-types" instead.`);
Expand Down Expand Up @@ -123,7 +115,7 @@ async function generateSchema(pathToSpec) {

const timeEnd = process.hrtime(timeStart);
const time = timeEnd[0] + Math.round(timeEnd[1] / 1e6);
console.log(`🚀 ${GREEN}${pathToSpec} -> ${BOLD}${outputFilePath}${RESET}${GREEN} [${time}ms]${RESET}`);
console.log(`🚀 ${c.green(`${pathToSpec} ${c.bold(outputFilePath)}`)} ${c.dim(`[${time}ms]`)}`);
} else {
process.stdout.write(result);
// if stdout, (still) don’t log anything to console!
Expand All @@ -147,9 +139,7 @@ async function main() {
let outputFile = new URL(flags.output, CWD);
let outputDir = new URL(".", outputFile);

if (output === OUTPUT_FILE) {
console.info(`✨ ${BOLD}openapi-typescript ${packageJSON.version}${RESET}`); // only log if we’re NOT writing to stdout
}
if (output === OUTPUT_FILE) console.info(`✨ ${c.bold(`openapi-typescript ${packageJSON.version}`)}`); // only log if we’re NOT writing to stdout

const pathToSpec = flags._[0];

Expand All @@ -173,12 +163,14 @@ async function main() {

// error: no matches for glob
if (inputSpecPaths.length === 0) {
errorAndExit(`✘ Could not find any specs matching "${pathToSpec}". Please check that the path is correct.`);
error(`Could not find any specs matching "${pathToSpec}". Please check that the path is correct.`);
process.exit(1);
}

// error: tried to glob output to single file
if (isGlob && output === OUTPUT_FILE && fs.existsSync(outputDir) && fs.lstatSync(outputDir).isFile()) {
errorAndExit(`✘ Expected directory for --output if using glob patterns. Received "${flags.output}".`);
error(`Expected directory for --output if using glob patterns. Received "${flags.output}".`);
process.exit(1);
}

// generate schema(s) in parallel
Expand Down
Loading