-
Notifications
You must be signed in to change notification settings - Fork 7
feat(api): add generic workos api gateway
#142
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
Open
nicknisi
wants to merge
17
commits into
main
Choose a base branch
from
feat/api-gateway
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.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
50e3b55
feat(api): add generic `workos api` gateway for raw API requests
nicknisi ca3c9af
feat(api): add interactive request builder and fix duplicate resolveA…
nicknisi 619b578
fix: Temporarily copy over the YAML spec
nicknisi 0054db9
refactor(api): use @workos/openapi-spec package instead of vendored YAML
nicknisi 5a5ad2b
chore(build): remove vendored YAML copy from postbuild
nicknisi 39c67aa
refactor(api): address code review findings
nicknisi add7794
fix(api): handle invalid JSON body in dry-run JSON mode and add tests
nicknisi aaaa66f
fix(api): emit pure JSON in JSON mode and gracefully handle missing -…
devin-ai-integration[bot] ff3b3e7
fix(api): emit structured error from runApiInteractive in JSON mode
devin-ai-integration[bot] 2d87eb7
fix(api): respect empty bodies and require --yes for mutating JSON re…
devin-ai-integration[bot] 0b23d79
fix(api): close remaining bugs flagged by Devin Review and CodeRabbit
devin-ai-integration[bot] f2af84f
fix(api): refuse JSON-mode interactive flow even in a TTY
devin-ai-integration[bot] 37ef3b8
fix(api): expose --insecure-storage in help-json for the api command
devin-ai-integration[bot] 4912d24
fix(api): tighten edge-case handling in body, path, and fetch flows
devin-ai-integration[bot] b843058
fix(api): URL-encode path param values in interactive mode
devin-ai-integration[bot] a57f38d
fix(api): resolve $ref params and dedupe path/operation overlap
devin-ai-integration[bot] 11e5ffb
fix(api): switch catalog spec read to async to match CLAUDE.md
devin-ai-integration[bot] 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,247 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { parseSpec, endpointsByTag, type EndpointInfo } from './catalog.js'; | ||
|
|
||
| const SAMPLE_SPEC = ` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test | ||
| version: 1.0.0 | ||
| paths: | ||
| /organizations: | ||
| get: | ||
| operationId: listOrganizations | ||
| summary: List organizations | ||
| tags: [Organizations] | ||
| parameters: | ||
| - name: limit | ||
| in: query | ||
| required: false | ||
| description: Max items | ||
| post: | ||
| operationId: createOrganization | ||
| summary: Create organization | ||
| tags: [Organizations] | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| /organizations/{id}: | ||
| parameters: | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| description: Organization id | ||
| get: | ||
| operationId: getOrganization | ||
| summary: Get organization | ||
| tags: [Organizations] | ||
| delete: | ||
| operationId: deleteOrganization | ||
| summary: Delete organization | ||
| tags: [Organizations] | ||
| /users: | ||
| get: | ||
| operationId: listUsers | ||
| summary: List users | ||
| tags: [Users] | ||
| `; | ||
|
|
||
| describe('parseSpec', () => { | ||
| it('returns endpoints for each method on a path', () => { | ||
| const catalog = parseSpec(SAMPLE_SPEC); | ||
| const ops = catalog.endpoints.filter((e) => e.path === '/organizations').map((e) => e.method); | ||
| expect(ops.sort()).toEqual(['GET', 'POST']); | ||
| }); | ||
|
|
||
| it('captures summary, tag, and operationId', () => { | ||
| const catalog = parseSpec(SAMPLE_SPEC); | ||
| const get = catalog.endpoints.find((e) => e.path === '/organizations' && e.method === 'GET'); | ||
| expect(get).toMatchObject({ | ||
| summary: 'List organizations', | ||
| tag: 'Organizations', | ||
| operationId: 'listOrganizations', | ||
| }); | ||
| }); | ||
|
|
||
| it('extracts path parameters from shared parameters block', () => { | ||
| const catalog = parseSpec(SAMPLE_SPEC); | ||
| const get = catalog.endpoints.find((e) => e.path === '/organizations/{id}' && e.method === 'GET'); | ||
| expect(get?.pathParams).toEqual([{ name: 'id', description: 'Organization id', required: true }]); | ||
| expect(get?.queryParams).toEqual([]); | ||
| }); | ||
|
|
||
| it('extracts query parameters from operation', () => { | ||
| const catalog = parseSpec(SAMPLE_SPEC); | ||
| const get = catalog.endpoints.find((e) => e.path === '/organizations' && e.method === 'GET'); | ||
| expect(get?.queryParams).toEqual([{ name: 'limit', description: 'Max items', required: false }]); | ||
| }); | ||
|
|
||
| it('flags hasRequestBody when requestBody is present', () => { | ||
| const catalog = parseSpec(SAMPLE_SPEC); | ||
| const post = catalog.endpoints.find((e) => e.path === '/organizations' && e.method === 'POST'); | ||
| const get = catalog.endpoints.find((e) => e.path === '/organizations' && e.method === 'GET'); | ||
| expect(post?.hasRequestBody).toBe(true); | ||
| expect(get?.hasRequestBody).toBe(false); | ||
| }); | ||
|
|
||
| it('produces a sorted unique tags list', () => { | ||
| const catalog = parseSpec(SAMPLE_SPEC); | ||
| expect(catalog.tags).toEqual(['Organizations', 'Users']); | ||
| }); | ||
|
|
||
| it('returns an empty catalog when paths is missing', () => { | ||
| const catalog = parseSpec('openapi: 3.0.0\ninfo:\n title: t\n version: 1.0.0\n'); | ||
| expect(catalog.endpoints).toEqual([]); | ||
| expect(catalog.tags).toEqual([]); | ||
| }); | ||
|
|
||
| it('resolves $ref parameters against components.parameters', () => { | ||
| const yaml = ` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test | ||
| version: 1.0.0 | ||
| components: | ||
| parameters: | ||
| SharedId: | ||
| name: id | ||
| in: path | ||
| required: true | ||
| description: Shared id parameter | ||
| SharedLimit: | ||
| name: limit | ||
| in: query | ||
| required: false | ||
| description: Page size | ||
| paths: | ||
| /widgets/{id}: | ||
| parameters: | ||
| - $ref: '#/components/parameters/SharedId' | ||
| get: | ||
| operationId: getWidget | ||
| summary: Get widget | ||
| parameters: | ||
| - $ref: '#/components/parameters/SharedLimit' | ||
| `; | ||
| const catalog = parseSpec(yaml); | ||
| const ep = catalog.endpoints.find((e) => e.path === '/widgets/{id}' && e.method === 'GET'); | ||
| expect(ep?.pathParams).toEqual([{ name: 'id', description: 'Shared id parameter', required: true }]); | ||
| expect(ep?.queryParams).toEqual([{ name: 'limit', description: 'Page size', required: false }]); | ||
| }); | ||
|
|
||
| it('skips $ref parameters that cannot be resolved instead of leaking placeholders', () => { | ||
| const yaml = ` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test | ||
| version: 1.0.0 | ||
| paths: | ||
| /widgets/{id}: | ||
| parameters: | ||
| - $ref: '#/components/parameters/Missing' | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| description: Inline id | ||
| get: | ||
| operationId: getWidget | ||
| summary: Get widget | ||
| `; | ||
| const catalog = parseSpec(yaml); | ||
| const ep = catalog.endpoints[0]; | ||
| // The unresolvable $ref should be silently dropped; the inline param survives. | ||
| expect(ep?.pathParams).toEqual([{ name: 'id', description: 'Inline id', required: true }]); | ||
| }); | ||
|
|
||
| it('deduplicates params by (name, in) — operation-level overrides path-level', () => { | ||
| const yaml = ` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test | ||
| version: 1.0.0 | ||
| paths: | ||
| /widgets/{id}: | ||
| parameters: | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| description: From path-level | ||
| get: | ||
| operationId: getWidget | ||
| summary: Get widget | ||
| parameters: | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| description: From operation-level (wins) | ||
| `; | ||
| const catalog = parseSpec(yaml); | ||
| const ep = catalog.endpoints[0]; | ||
| expect(ep?.pathParams).toEqual([{ name: 'id', description: 'From operation-level (wins)', required: true }]); | ||
| }); | ||
|
|
||
| it('falls back to "other" tag when none is provided', () => { | ||
| const yaml = ` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test | ||
| version: 1.0.0 | ||
| paths: | ||
| /noop: | ||
| get: | ||
| operationId: noop | ||
| summary: No tag | ||
| `; | ||
| const catalog = parseSpec(yaml); | ||
| expect(catalog.endpoints[0]?.tag).toBe('other'); | ||
| expect(catalog.tags).toEqual(['other']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('endpointsByTag', () => { | ||
| const endpoints: EndpointInfo[] = [ | ||
| { | ||
| method: 'GET', | ||
| path: '/users', | ||
| summary: '', | ||
| tag: 'Users', | ||
| operationId: 'listUsers', | ||
| pathParams: [], | ||
| queryParams: [], | ||
| hasRequestBody: false, | ||
| }, | ||
| { | ||
| method: 'POST', | ||
| path: '/organizations', | ||
| summary: '', | ||
| tag: 'Organizations', | ||
| operationId: 'createOrg', | ||
| pathParams: [], | ||
| queryParams: [], | ||
| hasRequestBody: true, | ||
| }, | ||
| { | ||
| method: 'DELETE', | ||
| path: '/users/{id}', | ||
| summary: '', | ||
| tag: 'Users', | ||
| operationId: 'deleteUser', | ||
| pathParams: [], | ||
| queryParams: [], | ||
| hasRequestBody: false, | ||
| }, | ||
| ]; | ||
|
|
||
| it('groups endpoints by tag preserving insertion order', () => { | ||
| const grouped = endpointsByTag(endpoints); | ||
| expect([...grouped.keys()]).toEqual(['Users', 'Organizations']); | ||
| expect(grouped.get('Users')?.map((e) => e.operationId)).toEqual(['listUsers', 'deleteUser']); | ||
| expect(grouped.get('Organizations')?.map((e) => e.operationId)).toEqual(['createOrg']); | ||
| }); | ||
|
|
||
| it('returns an empty map when no endpoints are provided', () => { | ||
| expect(endpointsByTag([]).size).toBe(0); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.