Skip to content

Commit d77c756

Browse files
committed
Commit source schemas to Git
1 parent 585e294 commit d77c756

File tree

1,361 files changed

+644938
-36
lines changed

Some content is hidden

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

1,361 files changed

+644938
-36
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ bin
22
coverage
33
dist
44
examples
5-
test/fixtures

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
with:
3333
node-version: 18
3434
- run: pnpm i
35-
- run: npm run download:schemas
3635
- run: npm run test:coverage
3736
test-node-versions:
3837
runs-on: ubuntu-22.04
@@ -48,7 +47,6 @@ jobs:
4847
with:
4948
node-version: ${{ matrix.node-version }}
5049
- run: pnpm i
51-
- run: npm run download:schemas
5250
- run: npm test
5351
test-macos:
5452
runs-on: macos-12
@@ -61,5 +59,4 @@ jobs:
6159
with:
6260
version: 18
6361
- run: pnpm i
64-
- run: npm run download:schemas
6562
- run: npm test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
coverage/
33
dist
44
node_modules
5-
test/fixtures/**/*

.prettierignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
examples/**/*.ts
2-
test/fixtures/**/*
3-
*.md
1+
examples
42
*.yaml
53
*.yml

CONTRIBUTING.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ This library has both unit tests (tests that test a tiny part of a schema) and s
5555

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

58+
#### Updating snapshot tests
59+
60+
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.
61+
5862
### Generating types
5963

6064
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).
@@ -82,7 +86,6 @@ This library uses [Vitest](https://vitest.dev/) for testing. There’s a great [
8286

8387
To run the entire test suite once, run:
8488

85-
8689
```bash
8790
npm test
8891
```
@@ -106,3 +109,11 @@ To run ESLint on the project:
106109
```bash
107110
npm run lint
108111
```
112+
113+
### Updating snapshot examples
114+
115+
⚠️ This may break tests if schemas have been updated
116+
117+
```bash
118+
npm run update:examples
119+
```

examples/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# openapi-typescript examples
2+
3+
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.
4+
5+
| Generated Types | Source | License |
6+
| :-------------------------------- | :-------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------- |
7+
| `digital-ocean-api.ts` | [GitHub](https://github.com/digitalocean/openapi) | [Apache 2.0](https://github.com/digitalocean/openapi/blob/main/LICENSE) |
8+
| `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) |
9+
| `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) |
10+
| `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) |
11+
| `stripe-api.ts` | [GitHub](https://github.com/stripe/openapi) | [MIT](https://github.com/stripe/openapi/blob/master/LICENSE) |
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ReDoc Index Main
2+
# This workflow uploads the latest `docs-preview/redoc-index.html` to the
3+
# team spaces directory when a change is detected on the file.
4+
# The previous file will be overwritten.
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- 'docs-preview/redoc-index.html'
12+
13+
jobs:
14+
15+
upload-index-preview:
16+
name: Upload Index Preview
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Upload index to spaces
22+
env:
23+
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }}
24+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_ACCESS_SECRET }}
25+
AWS_DEFAULT_OUTPUT: json
26+
SPACES_PATH: ${{ secrets.SPACES_PATH }}
27+
SPACES_ENDPOINT: ${{ secrets.SPACES_ENDPOINT }}
28+
AWS_EC2_METADATA_DISABLED: true
29+
run: >-
30+
aws s3 cp docs-preview/redoc-index.html
31+
${{ env.SPACES_PATH }}/redoc-index.html
32+
--endpoint=${{ env.SPACES_ENDPOINT }}
33+
--acl public-read
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: ReDoc Index PR
2+
# This workflow uploads a copy of the `docs-preview/redoc-index.html` to the
3+
# team spaces directory when a change is detected on the file.
4+
# For PRs, the uploaded file name will be suffixed with the PR number.
5+
# e.g. `docs-preview/redoc-index-pr-123.html`
6+
7+
on:
8+
pull_request_target:
9+
paths:
10+
- 'docs-preview/redoc-index.html'
11+
12+
jobs:
13+
14+
upload-index-preview:
15+
name: Upload Index Preview
16+
runs-on: ubuntu-latest
17+
18+
env:
19+
REDOC_INDEX_FILENAME: redoc-index-pr-${{ github.event.number }}.html
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Upload index to spaces
25+
env:
26+
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }}
27+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_ACCESS_SECRET }}
28+
AWS_DEFAULT_OUTPUT: json
29+
SPACES_PATH: ${{ secrets.SPACES_PATH }}
30+
SPACES_ENDPOINT: ${{ secrets.SPACES_ENDPOINT }}
31+
AWS_EC2_METADATA_DISABLED: true
32+
run: >-
33+
aws s3 cp docs-preview/redoc-index.html
34+
${{ env.SPACES_PATH }}/${{ env.REDOC_INDEX_FILENAME }}
35+
--endpoint=${{ env.SPACES_ENDPOINT }}
36+
--acl public-read
37+
38+
- uses: Sibz/github-status-action@v1
39+
with:
40+
authToken: ${{secrets.GITHUB_TOKEN}}
41+
context: ReDoc Index Preview URL
42+
description: Ready
43+
state: success
44+
sha: ${{ github.event.pull_request.head.sha }}
45+
target_url: https://api-engineering.nyc3.digitaloceanspaces.com/spec-ci/${{ env.REDOC_INDEX_FILENAME }}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Spec Main
2+
# This workflow uploads the latest spec to the team spaces.
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'specification/**'
10+
- 'spectral/**'
11+
workflow_dispatch:
12+
13+
jobs:
14+
lint:
15+
name: Validate style
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Run linter
20+
run: make lint
21+
22+
generate-main-preview:
23+
name: Generate Main Preview
24+
runs-on: ubuntu-latest
25+
needs: lint
26+
steps:
27+
- uses: actions/checkout@v2
28+
29+
- uses: actions/setup-node@v1
30+
with:
31+
node-version: '14.x'
32+
33+
- name: Bundle
34+
run: make bundle
35+
36+
- uses: actions/upload-artifact@v2
37+
with:
38+
name: openapi-bundled
39+
path: tests/openapi-bundled.yaml
40+
- name: Set outputs
41+
id: vars
42+
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
43+
- name: Check outputs
44+
run: echo ${{ steps.vars.outputs.sha_short }}
45+
- name: Upload Main spec
46+
run: >-
47+
aws s3 cp tests/openapi-bundled.yaml
48+
${{ env.SPACES_PATH }}/DigitalOcean-public.v2.yaml
49+
--endpoint=${{ env.SPACES_ENDPOINT }}
50+
--acl public-read
51+
env:
52+
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }}
53+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_ACCESS_SECRET }}
54+
AWS_DEFAULT_OUTPUT: json
55+
SPACES_PATH: ${{ secrets.SPACES_PATH }}
56+
SPACES_ENDPOINT: ${{ secrets.SPACES_ENDPOINT }}
57+
AWS_EC2_METADATA_DISABLED: true
58+
- name: Upload revision spec
59+
# this uploads a duplicate of the bundled spec with the short sha
60+
# appended to the file name for reference during client generation.
61+
run: >-
62+
aws s3 cp tests/openapi-bundled.yaml
63+
${{ secrets.SPACES_PATH }}/DigitalOcean-public-${{ steps.vars.outputs.sha_short }}.v2.yaml
64+
--endpoint=${{ secrets.SPACES_ENDPOINT }}
65+
--acl public-read
66+
env:
67+
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }}
68+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_ACCESS_SECRET }}
69+
AWS_DEFAULT_OUTPUT: json
70+
SPACES_PATH: ${{ secrets.SPACES_PATH }}
71+
SPACES_ENDPOINT: ${{ secrets.SPACES_ENDPOINT }}
72+
AWS_EC2_METADATA_DISABLED: true
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Spec Comment Trigger
2+
# This workflow uploads a copy of the spec with the respective changes in the PR
3+
# to the team Space when triggered by commenting "!deploy" on the PR.
4+
#
5+
# The name of the uploaded file will be prefixed with the PR number.
6+
# e.g. `spec-ci/previews/123-spec.yaml
7+
8+
on:
9+
pull_request_review:
10+
11+
jobs:
12+
generate-preview-on-trigger:
13+
# Check that the issue is a PR and that the comment starts with "!deploy"
14+
if: startsWith(github.event.review.body, '!deploy')
15+
name: Generate Preview on Review Comment Trigger
16+
runs-on: ubuntu-latest
17+
steps:
18+
# Ensure that the comment is made by someone in the DigitalOcean org
19+
- name: isDigitalOceanMember?
20+
id: is-digitalocean-member
21+
uses: actions/github-script@v3
22+
with:
23+
result-encoding: string
24+
script: |
25+
const organization = 'digitalocean';
26+
const user = "${{ github.event.review.user.login }}";
27+
28+
try {
29+
org = await github.orgs.checkMembershipForUser({
30+
org: organization,
31+
username: user,
32+
});
33+
34+
console.log(`${org.headers.status}: ${user} found in ${organization}`);
35+
return 'true';
36+
37+
} catch(err) {
38+
console.log(`${err.headers.status}: ${user} not found in ${organization}`);
39+
return 'false';
40+
};
41+
42+
- uses: actions/setup-node@v1
43+
if: steps.is-digitalocean-member.outputs.result == 'true'
44+
with:
45+
node-version: '14.x'
46+
47+
- name: Get PR Branch
48+
if: steps.is-digitalocean-member.outputs.result == 'true'
49+
id: get-pr-branch
50+
uses: actions/github-script@v3
51+
with:
52+
script: |
53+
repository = '${{ github.repository }}'
54+
result = await github.pulls.get({
55+
owner: repository.split('/')[0],
56+
repo: repository.split('/')[1],
57+
pull_number: ${{ github.event.pull_request.number }},
58+
});
59+
60+
return result.data.head
61+
62+
- name: Checkout PR Branch
63+
if: steps.is-digitalocean-member.outputs.result == 'true'
64+
uses: actions/checkout@v2
65+
with:
66+
repository: ${{ fromJSON(steps.get-pr-branch.outputs.result).repo.full_name }}
67+
ref: ${{ github.event.review.commit_id }}
68+
69+
- name: Bundle
70+
if: steps.is-digitalocean-member.outputs.result == 'true'
71+
run: make bundle
72+
73+
- uses: actions/upload-artifact@v2
74+
if: steps.is-digitalocean-member.outputs.result == 'true'
75+
with:
76+
name: openapi-bundled
77+
path: tests/openapi-bundled.yaml
78+
79+
- name: Upload PR spec
80+
if: steps.is-digitalocean-member.outputs.result == 'true'
81+
run: >-
82+
aws s3 cp tests/openapi-bundled.yaml
83+
${{ env.SPACES_PATH }}/previews/${{ github.event.issue.number }}-spec.yaml
84+
--endpoint=${{ env.SPACES_ENDPOINT }}
85+
--acl public-read
86+
env:
87+
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY }}
88+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_ACCESS_SECRET }}
89+
AWS_DEFAULT_OUTPUT: json
90+
SPACES_PATH: ${{ secrets.SPACES_PATH }}
91+
SPACES_ENDPOINT: ${{ secrets.SPACES_ENDPOINT }}
92+
AWS_EC2_METADATA_DISABLED: true
93+
94+
- name: Comment on PR
95+
if: steps.is-digitalocean-member.outputs.result == 'true' && success()
96+
uses: actions/github-script@v3
97+
with:
98+
script: |
99+
var previewComment = '🔎 API documentation preview: https://api-engineering.nyc3.digitaloceanspaces.com/spec-ci/redoc-index.html?pr=' + '${{ github.event.pull_request.number }}';
100+
var repository = '${{ github.repository }}'
101+
github.issues.createComment({
102+
issue_number: '${{ github.event.pull_request.number }}',
103+
owner: repository.split('/')[0],
104+
repo: repository.split('/')[1],
105+
body: previewComment
106+
});

0 commit comments

Comments
 (0)