Skip to content

Commit

Permalink
feat: adding openapi upload (#1116)
Browse files Browse the repository at this point in the history
| 🚥 Resolves RM-11384 |
| :------------------- |

## 🧰 Changes

`rdme openapi` has now been replaced by `rdme openapi upload` 🚀

highlights:

- much simpler flag structure
- more intuitive slug-based identifying system, thanks to API v2
- better error messages, thanks to API v2

code review notes
- a lot of the diff is related to setting up boilerplate for interacting
with API v2
- feedback appreciated on the docs — feel free to review
`documentation/commands/openapi.md` or `src/commands/openapi/upload.ts`
- feedback appreciated on whether the optional flag should be called
`--slug` or `--identifier` or something else. went with `--slug` since
it's short and it was easy to write clear explainer docs around

<details>

<summary>outstanding tasks (archived)</summary>

- [x] command
- [x] tests
- [x] ~~optional `--action` arg?~~ **edit**: might be a good enhancement
further down the line, but going to pass on this for now!
- [x] tests for `useSpecVersion`
- [x] test for `pending` timeout (there's a nock API for duplicating an
interceptor, use that!)
- [x] finalize command docs
- [x] set up [test project](https://rdme-refactored-test.readme.io) for
syncing in CI (i.e., adding back what i removed in
d69d1aa)

</details>

<details>

<summary>follow-up enhancements</summary>

- tests for `readmeAPIv2Fetch`
- optional `--action` arg for use in CI to prevent accidental overwrites
- optional `--timeout` arg to allow user to configure timeout
- GHA onboarding support

</details>

## 🧬 QA & Testing

this can only be tested locally for now:

1. in your local dev server, load up a project that uses readme
refactored
2. set up an API key for said project
3. change the value on [this
line](https://github.com/readmeio/rdme/blob/af0e0dca7f715847bd5359d5bf60e1df63a81246/src/lib/config.ts#L4)
to be `http://api.readme.local:3000/v2`
4. check out this branch and run the following:

  ```sh
  # setup
  npm ci && npm run build

  # try running any or all of the following:
  bin/dev.js openapi upload # try logging in
  bin/dev.js openapi upload --key <key> # try selecting a file
bin/dev.js openapi upload --key <key>
__tests__/__fixtures__/petstore-simple-weird-version.json # without a
version arg
bin/dev.js openapi upload --key <key>
__tests__/__fixtures__/petstore-simple-weird-version.json --version=1.0
# with a version arg
bin/dev.js openapi upload --key <key>
__tests__/__fixtures__/petstore-simple-weird-version.json
--useSpecVersion # use the version defined in the spec
  ```

---------

Co-authored-by: Jon Ursenbach <[email protected]>
  • Loading branch information
kanadgupta and erunion authored Dec 12, 2024
1 parent 0ef7ec6 commit 8a33ed4
Show file tree
Hide file tree
Showing 13 changed files with 989 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,25 @@ jobs:
if: ${{ github.ref }} == 'refs/heads/next'
with:
rdme: openapi validate oas-examples-repo/3.1/json/petstore.json

# Docs: https://rdme-test.readme.io
- name: Run `openapi` command
uses: ./rdme-repo/
with:
rdme: openapi upload oas-examples-repo/3.1/json/petstore.json --key=${{ secrets.RDME_REFACTORED_TEST_PROJECT_API_KEY }}
- name: Run `openapi` command with env var
uses: ./rdme-repo/
with:
rdme: openapi upload oas-examples-repo/3.1/json/petstore.json
env:
RDME_API_KEY: ${{ secrets.RDME_REFACTORED_TEST_PROJECT_API_KEY }}
- name: Run `openapi` command with other env var
uses: ./rdme-repo/
with:
rdme: openapi upload oas-examples-repo/3.1/json/petstore.json
env:
README_API_KEY: ${{ secrets.RDME_REFACTORED_TEST_PROJECT_API_KEY }}
- name: Run `openapi` command with weird arg syntax
uses: ./rdme-repo/
with:
rdme: openapi upload "oas-examples-repo/3.1/json/petstore.json" --key "${{ secrets.RDME_REFACTORED_TEST_PROJECT_API_KEY }}"
Loading

0 comments on commit 8a33ed4

Please sign in to comment.