-
Notifications
You must be signed in to change notification settings - Fork 11
feat: automate OpenAPI spec sync with endpoint filtering #132
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
Changes from 1 commit
07e2f1a
fa09deb
cf12993
66746b4
036dc7f
91ef9e8
d2cb2f1
dbd9ae1
4ad6da2
7320518
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| title: Account | ||
| description: Account management endpoints | ||
| full: true | ||
| _openapi: | ||
| toc: [] | ||
| structuredData: | ||
| headings: [] | ||
| contents: [] | ||
| --- | ||
|
|
||
| {/* This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again. */} | ||
|
|
||
| <APIPage document={"specs/competitions.json"} operations={[]} webhooks={[]} hasHead={true} /> |
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import fs from "fs/promises"; | ||
|
|
||
| const SOURCE_URL = | ||
| "https://raw.githubusercontent.com/recallnet/js-recall/main/apps/api/openapi/openapi.json"; | ||
| const OUTPUT_PATH = "specs/competitions.json"; | ||
|
|
||
| const BLOCKED_PATH_PATTERNS = [ | ||
| /^\/api\/admin\//, | ||
| /^\/api\/user\//, | ||
| /^\/api\/auth\/login$/, | ||
| /^\/api\/competitions\/[^/]+\/partners$/, | ||
| /^\/nfl\//, | ||
| ]; | ||
|
|
||
| const BLOCKED_TAGS = ["Admin", "User", "NFL"]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another spot where it doesn't feel right to have something like NFL hard coded here. I think, if this is just a temp solution, this is fine for now... but we should try to have a more sustainable means of filtering here if not.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completely agree. Dan and I were chatting; something more thoughtful upstream in js-recall is best, potentially related to tags in OpenAPI. i.e. API endpoint authors should be responsible for indicating whether their endpoints are (something like) |
||
|
|
||
| function isPathBlocked(path: string): boolean { | ||
| return BLOCKED_PATH_PATTERNS.some((pattern) => pattern.test(path)); | ||
| } | ||
|
|
||
| async function main(): Promise<void> { | ||
| console.log(`Fetching OpenAPI spec from ${SOURCE_URL}...`); | ||
|
|
||
| const response = await fetch(SOURCE_URL); | ||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`); | ||
| } | ||
|
|
||
| const spec = await response.json(); | ||
|
|
||
|
derrekcoleman marked this conversation as resolved.
|
||
| const originalPaths = Object.keys(spec.paths); | ||
| const filteredPaths: Record<string, unknown> = {}; | ||
|
|
||
| for (const [path, value] of Object.entries(spec.paths)) { | ||
|
derrekcoleman marked this conversation as resolved.
Outdated
|
||
| if (!isPathBlocked(path)) { | ||
| filteredPaths[path] = value; | ||
| } | ||
| } | ||
|
|
||
| spec.paths = filteredPaths; | ||
|
|
||
| const removedPathCount = originalPaths.length - Object.keys(filteredPaths).length; | ||
| console.log(`Filtered ${removedPathCount} blocked endpoints (${Object.keys(filteredPaths).length} remaining)`); | ||
|
|
||
| if (spec.tags) { | ||
| const originalTagCount = spec.tags.length; | ||
| spec.tags = spec.tags.filter( | ||
| (tag: { name: string }) => !BLOCKED_TAGS.includes(tag.name) | ||
| ); | ||
| console.log(`Filtered ${originalTagCount - spec.tags.length} blocked tags`); | ||
| } | ||
|
|
||
|
derrekcoleman marked this conversation as resolved.
Outdated
|
||
| spec.components ??= {}; | ||
| spec.components.securitySchemes ??= {}; | ||
|
|
||
| // Upstream uses AgentApiKey in /api/auth/* endpoints but doesn't define it. | ||
| // Inject the definition if missing. Remove this block once upstream defines AgentApiKey. | ||
| if (!spec.components.securitySchemes.AgentApiKey) { | ||
| spec.components.securitySchemes.AgentApiKey = { | ||
| type: "http", | ||
| scheme: "bearer", | ||
| description: "Agent API key provided as Bearer token", | ||
| }; | ||
| console.log("Injected missing AgentApiKey security scheme"); | ||
| } | ||
|
|
||
| // Upstream uses bearerAuth (lowercase) in some endpoints but doesn't define it. | ||
| // Inject the definition if missing. Remove this block once upstream defines bearerAuth. | ||
| if (!spec.components.securitySchemes.bearerAuth) { | ||
| spec.components.securitySchemes.bearerAuth = { | ||
| type: "http", | ||
| scheme: "bearer", | ||
| description: "Bearer token authentication", | ||
| }; | ||
| console.log("Injected missing bearerAuth security scheme"); | ||
| } | ||
|
|
||
| await fs.writeFile(OUTPUT_PATH, JSON.stringify(spec, null, 2) + "\n"); | ||
| console.log(`Written to ${OUTPUT_PATH}`); | ||
|
derrekcoleman marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| void main(); | ||
|
derrekcoleman marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.