Skip to content

Commit source schemas to Git #978

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 10, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ bin
coverage
dist
examples
test/fixtures
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
with:
node-version: 18
- run: pnpm i
- run: npm run download:schemas
- run: npm run test:coverage
test-node-versions:
runs-on: ubuntu-22.04
Expand All @@ -48,7 +47,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: pnpm i
- run: npm run download:schemas
- run: npm test
test-macos:
runs-on: macos-12
Expand All @@ -61,5 +59,4 @@ jobs:
with:
version: 18
- run: pnpm i
- run: npm run download:schemas
- run: npm test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
coverage/
dist
node_modules
test/fixtures/**/*
4 changes: 1 addition & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
examples/**/*.ts
test/fixtures/**/*
*.md
examples
*.yaml
*.yml
13 changes: 12 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ This library has both unit tests (tests that test a tiny part of a schema) and s

For most PRs, **snapshot tests can be avoided.** But for scenarios similar to the ones mentioned, they can ensure everything is working as expected.

#### Updating snapshot tests

To add a schema as a snapshot test, modify the [/scripts/download-schemas.ts](/scripts/download-schemas.ts) script with a path to download. There are both single-file schemas as well as multi-file schemas.

### Generating types

It may be surprising to hear, but _generating TypeScript types from OpenAPI is opinionated!_ Even though TypeScript and OpenAPI are very close relatives, both being JavaScript/JSON-based, they are nonetheless 2 different languages and thus there is always some room for interpretation. Likewise, some parts of the OpenAPI specification can be ambiguous on how they’re used, and what the expected type outcomes may be (though this is generally for more advanced usecasees, such as specific implementations of `anyOf` as well as [discriminator](https://spec.openapis.org/oas/latest.html#discriminatorObject) and complex polymorphism).
Expand Down Expand Up @@ -82,7 +86,6 @@ This library uses [Vitest](https://vitest.dev/) for testing. There’s a great [

To run the entire test suite once, run:


```bash
npm test
```
Expand All @@ -106,3 +109,11 @@ To run ESLint on the project:
```bash
npm run lint
```

### Updating snapshot examples

⚠️ This may break tests if schemas have been updated

```bash
npm run update:examples
```
11 changes: 11 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# openapi-typescript examples

These examples show the generation from an OpenAPI schema to its associated types. None of the example schemas here are associated with this project, and all code are © their respective owners.

| Generated Types | Source | License |
| :-------------------------------- | :-------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------- |
| `digital-ocean-api.ts` | [GitHub](https://github.com/digitalocean/openapi) | [Apache 2.0](https://github.com/digitalocean/openapi/blob/main/LICENSE) |
| `github-api.ts` | [GitHub](https://github.com/github/rest-api-description/tree/main/descriptions/api.github.com) | [MIT](https://github.com/github/rest-api-description/blob/main/LICENSE.md) |
| `github-api-next.ts` | [GitHub](https://github.com/github/rest-api-description/tree/main/descriptions-next/api.github.com) | [MIT](https://github.com/github/rest-api-description/blob/main/LICENSE.md) |
| `octokit-ghes-3.6-diff-to-api.ts` | [GitHub](https://github.com/octokit/octokit-next.js/tree/main/packages/types-openapi-ghes-3.6-diff-to-api.github.com) | [MIT](https://github.com/octokit/octokit-next.js/blob/main/LICENSE) |
| `stripe-api.ts` | [GitHub](https://github.com/stripe/openapi) | [MIT](https://github.com/stripe/openapi/blob/master/LICENSE) |
1,544 changes: 1,544 additions & 0 deletions examples/digital-ocean-api/DigitalOcean-public.v2.yaml

Large diffs are not rendered by default.

Loading