Skip to content
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

feat: creation of a new .getOperationById() method #892

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

erunion
Copy link
Member

@erunion erunion commented Aug 23, 2024

🧰 Changes

This creates a new .getOperationById() method on the main Oas instance that allows us to retrieve an Operation or Webhook instance by either the operationId that's set to the schema, or if that's missing then the default generated behavior from Operation.getOperationId().

I plan on using this within our main app to retrieve path and method for an operation based on the data I have for it: just an operationId.

🧬 QA & Testing

The tests I wrote have been sort of ported over from the Operation.getOperationById() tests but heavily reduced as I don't need to re-test that thing.

@erunion erunion added the enhancement New feature or request label Aug 23, 2024
@erunion erunion requested review from kanadgupta, julshotal and a team August 23, 2024 01:00
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to look at this file with whitespace changes turned off 🙃

@@ -76,13 +76,13 @@ Because this library has full TypeScript types and docblocks this README is not
<!-- prettier-ignore-start -->
| Method | Description |
| :--- | :--- |
| `#dereference()` | Dereference the current OpenAPI definition. Note that this will ignore circular references. |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed these # to a . to better indicate that they're instance methods, not static.

| `.findOperation()` | Discover an operation with the current OpenAPI definition that matches a given URL and HTTP method. |
| `.findOperationWithoutMethod()` | Like `.findOperation()` but without supplying an HTTP method. |
| `.getOperation()` | Same as `.findOperation()` but this returns an instance of the `Operation` class. |
| `.getOperationById()` | Retrieve an operation in an OpenAPI definition by an `operationId`. |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs for the new method ^

await circular.dereference();

const reduced = reducer(circular.api as any, { paths: { '/anything': ['get'] } });
expect(Object.keys(reduced.paths['/anything'])).toStrictEqual(['get', 'post']);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someday 😭

Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo otherwise LGTM!

packages/oas/src/index.ts Outdated Show resolved Hide resolved
await circular.dereference();

const reduced = reducer(circular.api as any, { paths: { '/anything': ['get'] } });
expect(Object.keys(reduced.paths['/anything'])).toStrictEqual(['get', 'post']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someday 😭

packages/oas/src/index.ts Show resolved Hide resolved
@erunion erunion merged commit 76c10f0 into main Aug 23, 2024
@erunion erunion deleted the feat/getbyoperationid branch August 23, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants