-
Notifications
You must be signed in to change notification settings - Fork 0
poc: add schema command to fetch Clerk API specs
#37
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
Draft
kylemac
wants to merge
3
commits into
main
Choose a base branch
from
kylemac/add-openapi-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # `clerk schema` | ||
|
|
||
| Fetch and output the OpenAPI specification for Clerk APIs. Supports full-spec output, path-based introspection, type lookups, and `$ref` resolution. | ||
|
|
||
| ## Usage | ||
|
|
||
| ``` | ||
| clerk schema # List available APIs and versions | ||
| clerk schema backend # Backend API (latest, YAML) | ||
| clerk schema frontend # Frontend API (latest, YAML) | ||
| clerk schema platform # Platform API (latest, YAML) | ||
| clerk schema webhooks # Webhooks spec (latest, YAML) | ||
| clerk schema backend /users # Just the /users endpoint | ||
| clerk schema backend User # Just the User schema type | ||
| clerk schema backend /users --resolve-refs # Endpoint with all $refs inlined | ||
| clerk schema backend User --resolve-refs # Type with all $refs inlined | ||
| clerk schema backend --format json # Full spec as JSON | ||
| clerk schema backend --spec-version 2024-10-01 # Specific version | ||
| clerk schema platform --output spec.yml # Write to file | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | | ||
| | ---------------------- | --------------------------------------------------- | | ||
| | `[path]` | Endpoint path (e.g. `/users`) or type (e.g. `User`) | | ||
| | `--spec-version <ver>` | Spec version (default: latest for the API) | | ||
| | `--format <fmt>` | Output format: `yaml` (default) or `json` | | ||
| | `--output <file>` | Write spec to a file instead of stdout | | ||
| | `--resolve-refs` | Inline `$ref` references for self-contained output | | ||
|
|
||
| ## Path introspection | ||
|
|
||
| When a second argument is provided, the command extracts just the matching portion of the spec: | ||
|
|
||
| - **Endpoint paths** start with `/` — e.g. `clerk schema backend /users` looks up the `/users` endpoint. Automatically tries `/v1` and `/v2` prefixes if an exact match isn't found. | ||
| - **Schema types** don't start with `/` — e.g. `clerk schema backend User` looks up the `User` schema in `components.schemas`. Case-insensitive matching is supported. | ||
|
|
||
| If no match is found, the command suggests similar paths or types. | ||
|
|
||
| ## `--resolve-refs` | ||
|
|
||
| Inlines all `$ref` references so the output is fully self-contained. Circular references are detected and marked with a `$comment: "circular reference"` annotation instead of causing infinite expansion. | ||
|
|
||
| This is especially useful for AI agents that need a complete type definition without chasing references. | ||
|
|
||
| ## APIs | ||
|
|
||
| | Name | Aliases | Latest version | All versions | | ||
| | ---------- | ------- | -------------- | ---------------------------------------------------------- | | ||
| | `backend` | `bapi` | `2025-11-10` | 2021-02-05, 2024-10-01, 2025-03-12, 2025-04-10, 2025-11-10 | | ||
| | `frontend` | `fapi` | `2025-11-10` | 2021-02-05, 2024-10-01, 2025-03-12, 2025-04-10, 2025-11-10 | | ||
| | `platform` | | `beta` | beta | | ||
| | `webhooks` | | `2025-04-15` | 2025-04-15 | | ||
|
|
||
| Specs are fetched from https://github.com/clerk/openapi-specs. | ||
|
|
||
| ## Caching | ||
|
|
||
| Specs are cached locally for 24 hours to avoid repeated network requests. Cache is stored in the CLI's standard cache directory. | ||
|
|
||
| ## No authentication required | ||
|
|
||
| This command fetches publicly available specs from GitHub and does not require authentication. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to have: you could use
.choices(["yaml", "json"])here instead of the manual validation inschema(). Commander would reject invalid values automatically and display the allowed values in--helpoutput. Same idea for the[api]argument --.choices(["backend", "frontend", "platform", "webhooks", "bapi", "fapi"])would give you free validation and help text.