Skip to content

Commit

Permalink
Update OpenAPI client, add client validity check (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkachel authored Dec 20, 2024
1 parent f58e6df commit 1592de5
Show file tree
Hide file tree
Showing 12 changed files with 5,331 additions and 4,082 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,50 @@ jobs:
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
file: ./coverage.xml

openapi-generated-client-check-v0:
# This job checks that the output of openapi-generator-typescript-axios that
# is checked into version control is up-to-date.
env:
OPENAPI_SCHEMA: ./openapi/specs/v0.yaml
GENERATOR_IGNORE_FILE: ./frontends/api/.openapi-generator-ignore
GENERATOR_OUTPUT_DIR_CI: ./frontends/api/tmp/generated/v0
GENERATOR_OUTPUT_DIR_VC: ./frontends/api/src/generated/v0
COREPACK_ENABLE_DOWNLOAD_PROMPT: 0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: "^20"
cache: "npm"
cache-dependency-path: "package-lock.json"

- name: Install dependencies
run: npm i

- name: Generate Fresh API Client
uses: openapi-generators/openapitools-generator-action@v1
with:
generator: typescript-axios
openapi-file: $OPENAPI_SCHEMA
generator-tag: v7.2.0
command-args: |
--output $GENERATOR_OUTPUT_DIR_CI \
--ignore-file-override $GENERATOR_IGNORE_FILE \
-c scripts/openapi-configs/typescript-axios-v0.yaml
- name: Format freshly generated client
run: npx prettier $GENERATOR_OUTPUT_DIR_CI/**/*.ts --no-semi --write

# Kept getting tripped up on npmignore and the git push script, neither
# of which are really important, so just check the generated TypeScript
# files instead.
- name: Check VC client is up-to-date
run: |
mkdir $GENERATOR_OUTPUT_DIR_VC/ts
mkdir $GENERATOR_OUTPUT_DIR_CI/ts
cp $GENERATOR_OUTPUT_DIR_VC/*.ts $GENERATOR_OUTPUT_DIR_VC/ts
cp $GENERATOR_OUTPUT_DIR_CI/*.ts $GENERATOR_OUTPUT_DIR_CI/ts
diff $GENERATOR_OUTPUT_DIR_CI/ts $GENERATOR_OUTPUT_DIR_VC/ts \
|| { echo "OpenAPI spec is out of date. Please regenerate via ./scripts/generate_openapi.sh"; exit 1; }
27 changes: 24 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# A bunch of frontend related stuff is commented out here - this is because we don't
# have a frontend yet.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand All @@ -15,8 +13,29 @@ repos:
- id: check-merge-conflict
- id: check-toml
- id: debug-statements
- repo: local
hooks:
- id: prettier
name: prettier
entry: npx prettier --write
language: node
types_or:
[
javascript,
jsx,
ts,
tsx,
json,
scss,
sass,
css,
yaml,
markdown,
html,
sh,
]
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.8.0-1
rev: v3.10.0-1
hooks:
- id: shfmt
- repo: https://github.com/adrienverge/yamllint.git
Expand Down Expand Up @@ -58,3 +77,5 @@ repos:
hooks:
- id: shellcheck
args: ["--severity=warning"]
ci:
skip: [prettier]
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"semi": false,
"plugins": ["prettier-plugin-django-alpine"]
"plugins": ["prettier-plugin-sh"]
}
7 changes: 0 additions & 7 deletions .yarnrc.yml

This file was deleted.

5 changes: 0 additions & 5 deletions frontends/api/src/generated/v0/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,3 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

**/.npmignore
**/.gitignore
**/git_push.sh
**/.openapi-generator-ignore
Loading

0 comments on commit 1592de5

Please sign in to comment.