|
1 | 1 | # Contributing
|
2 | 2 |
|
3 |
| -Thanks for being willing to contribute! |
| 3 | +Thanks for being willing to contribute! 🙏 |
4 | 4 |
|
5 |
| -**Working on your first Pull Request?** You can learn how from this _free_ series [How to Contribute to an Open Source |
6 |
| -Project on GitHub][egghead] |
| 5 | +**Working on your first Pull Request (PR)?** You can learn how from this _free_ series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github) |
7 | 6 |
|
8 |
| -## Project setup |
| 7 | +## Open issues |
| 8 | + |
| 9 | +Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Help Wanted**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are especially good to help with. |
| 10 | + |
| 11 | +Contributing doesn’t have to be in code! Simply answering questions in open issues, or providing workarounds, is just as important a contribution as making pull requests. |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +### Dependencies |
9 | 16 |
|
10 | 17 | 1. Install [pnpm](https://pnpm.io/)
|
11 | 18 | 2. Fork and clone the repo
|
12 | 19 | 3. Run `pnpm i` to install dependencies
|
13 | 20 | 4. Create a branch for your PR with `git checkout -b pr/your-branch-name`
|
14 | 21 |
|
15 |
| -It’s also recommended you have [ESLint][eslint] installed and set up correctly. You may also run the command |
16 |
| -`npm run lint` to see lint errors. |
| 22 | +### VS Code setup |
17 | 23 |
|
18 |
| -> Tip: Keep your `main` branch pointing at the original repository and make pull requests from branches on your fork. To |
19 |
| -> do this, run: |
20 |
| -> |
21 |
| -> ``` |
22 |
| -> git remote add upstream https://github.com/drwpow/openapi-typescript.git |
23 |
| -> git fetch upstream |
24 |
| -> git branch --set-upstream-to=upstream/main main |
25 |
| -> ``` |
26 |
| -> |
27 |
| -> This will add the original repository as a "remote" called "upstream," Then fetch the git information from that |
28 |
| -> remote, then set your local `main` branch to use the upstream main branch whenever you run `git pull`. Then you can |
29 |
| -> make all of your pull request branches based on this `main` branch. Whenever you want to update your version of |
30 |
| -> `main`, do a regular `git pull`. |
| 24 | +If using VS Code, the following extensions are recommended (or their equivalent extensions if using another editor) |
31 | 25 |
|
32 |
| -## Committing and pushing changes |
| 26 | +- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) |
33 | 27 |
|
34 |
| -Please make sure to run the tests (`npm test`) before you commit your changes. |
| 28 | +## Workflow |
35 | 29 |
|
36 |
| -### Local schemas |
| 30 | +When working locally, run: |
37 | 31 |
|
38 |
| -This repo supports OpenAPI 2.0 and 3.0. There are some real-world examples located in `tests/v2/specs/*.yaml` and |
39 |
| -`tests/v3/specs/*.yaml`, respectively. Testing large, real schemas was a major goal of this project. Many libraries only |
40 |
| -test the “Petstore” example from Swagger, which is contrived and is missing much complexity from companies’ production |
41 |
| -schemas. |
| 32 | +```bash |
| 33 | +npm run dev |
| 34 | +``` |
42 | 35 |
|
43 |
| -_Note: don’t update the `yaml` schemas with your own custom additions (but if the official versions have updated, then |
44 |
| -it’s fine to update them here). If you’d like to add your schema for testing, then please add them as a new schema, and |
45 |
| -add them to `./expected/*.ts`._ |
| 36 | +This will compile the code as you change automatically. |
46 | 37 |
|
47 |
| -#### Regenerating schemas |
| 38 | +### TDD |
48 | 39 |
|
49 |
| -If you’ve added a feature or fixed a bug and need to update the generated schemas, run the following: |
| 40 | +This library is a great usecase for [test-driven development (TDD)](https://en.wikipedia.org/wiki/Test-driven_development). If you’re new to this, the basic workflow is: |
50 | 41 |
|
51 |
| -``` |
52 |
| -# 1. re-build the package |
53 |
| -npm run build |
54 |
| -# 2. run the local CLI (not the npm one!) |
55 |
| -./bin/cli.js tests/v3/specs/github.yaml -o tests/v3/expected/github.ts |
56 |
| -# NOTE: on Windows, try running the script on WSL if getting errors |
57 |
| -``` |
| 42 | +1. First, write a [test](#testing) that fully outlines what you’d _like_ the output to be. |
| 43 | +2. Make sure this test **fails** when you run `npm test` (yes, _fails!_) |
| 44 | +3. Then, make changes to `src/` until the tests pass. |
| 45 | + |
| 46 | +_Code generation is hard!_ And for that reason, starting with a very clear expectation of your end-goal can make working easier. |
| 47 | + |
| 48 | +### Unit tests or snapshot tests? |
| 49 | + |
| 50 | +This library has both unit tests (tests that test a tiny part of a schema) and snapshot tests (tests that run over an entire, complete schema). When opening a PR, the former are more valuable than the latter, and are always required. However, updating snapshot tests can help with the following: |
| 51 | + |
| 52 | +- Fixing bugs that deal with multiple schemas with remote `$ref`s |
| 53 | +- Fixing Node.js or OS-related bugs |
| 54 | +- Adding a CLI option that changes the entire output |
| 55 | + |
| 56 | +For most PRs, **snapshot tests can be avoided.** But for scenarios similar to the ones mentioned, they can ensure everything is working as expected. |
58 | 57 |
|
59 |
| -This should update the expected TypeScript definiton. |
| 58 | +### Opening a PR |
60 | 59 |
|
61 |
| -_Also if this appears in `examples/` feel free to update that, too!_ |
| 60 | +When opening a pull request, make sure all of the following is done: |
| 61 | + |
| 62 | +- [x] Tests are added |
| 63 | +- [x] Build passes (`npm run build`) |
| 64 | +- [x] Tests pass (`npm test`) |
| 65 | +- [x] Linting passes (`npm run lint`) |
62 | 66 |
|
63 | 67 | ## Testing
|
64 | 68 |
|
65 |
| -Tests use [Vitest](https://vitest.dev), a modern test-runner based on Jest. To run the tests locally, run: |
| 69 | +This library uses [Vitest](https://vitest.dev/) for testing. There’s a great [VS Code extension](https://marketplace.visualstudio.com/items?itemName=ZixuanChen.vitest-explorer) you can optionally use if you’d like in-editor debugging tools. |
66 | 70 |
|
67 |
| -``` |
| 71 | +### Running tests |
| 72 | + |
| 73 | +💡 The tests test **the production build** in `dist/`. Be sure to run `npm run build` before running tests (or keep `npm run dev` running in the background, which compiles as-you-work)! |
| 74 | + |
| 75 | +To run the entire test suite once, run: |
| 76 | + |
| 77 | + |
| 78 | +```bash |
68 | 79 | npm test
|
69 | 80 | ```
|
70 | 81 |
|
71 | 82 | To run an individual test:
|
72 | 83 |
|
73 |
| -``` |
74 |
| -npx vitest [part of filename] |
| 84 | +```bash |
| 85 | +npx vitest [partial filename] |
75 | 86 | ```
|
76 | 87 |
|
77 |
| -Or to start all tests in watch mode: |
| 88 | +To start the entire test suite in watch mode: |
78 | 89 |
|
79 |
| -``` |
| 90 | +```bash |
80 | 91 | npx vitest
|
81 | 92 | ```
|
82 | 93 |
|
83 |
| -[See docs](https://vitest.dev) |
84 |
| -
|
85 |
| -## Help needed |
| 94 | +### Running linting |
86 | 95 |
|
87 |
| -Please check out the [the open issues][issues]. Issues labelled [**Help Wanted**][help-wanted] and [**Good First |
88 |
| -Issue**][good-first-issue] are especially good to help with. |
| 96 | +To run ESLint on the project: |
89 | 97 |
|
90 |
| -Also, please watch the repo and respond to questions/bug reports/feature requests! Thanks! |
91 |
| -
|
92 |
| -[all-contributors]: https://github.com/all-contributors/all-contributors |
93 |
| -[egghead]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github |
94 |
| -[eslint]: https://eslint.org/ |
95 |
| -[good-first-issue]: |
96 |
| - https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22 |
97 |
| -[help-wanted]: https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22 |
98 |
| -[issues]: https://github.com/drwpow/openapi-typescript/issues |
| 98 | +```bash |
| 99 | +npm run lint |
| 100 | +``` |
0 commit comments