Skip to content

Expose original request on Middleware.onResponse #1697

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

Conversation

armandabric
Copy link
Contributor

Changes

Add the req as thrid params of the onResponse middleware. Its useful to create log on the on response (the Response did not contains some information of the original request)

Checklist

  • Unit tests updated
  • docs/ updated (if necessary) (will be done if

Copy link

changeset-bot bot commented Jun 17, 2024

⚠️ No Changeset found

Latest commit: 9f8e465

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@armandabric armandabric force-pushed the middleware-expose-original-request-on-response branch from 78fe9b8 to 9f8e465 Compare June 17, 2024 13:33
| `options` | `MergedOptions` | Combination of [createClient](/openapi-fetch/api#create-client) options + [fetch overrides](/openapi-fetch/api#fetch-options) |
| `req` | `MiddlewareRequest` | A standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) with `schemaPath` (OpenAPI pathname) and `params` ([params](/openapi-fetch/api#fetch-options) object) |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
| `req` | `MiddlewareRequest` | A standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) with `schemaPath` (OpenAPI pathname) and `params` ([params](/openapi-fetch/api#fetch-options) object) |
| `req` | `MiddlewareRequest` | The original [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request), see `onRequest` |

export function onResponse(
res: Response,
options: MergedOptions,
req: MiddlewareRequest,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 This is a good non-breaking change. Will probably opt for a more “logical” ordering in a future breaking change

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

Great addition. Thanks for adding! There’s no reason not to have this available, and it wasn’t ever omitted intentionally.

@drwpow drwpow merged commit e77ce50 into openapi-ts:main Jun 17, 2024
6 checks passed
@armandabric armandabric deleted the middleware-expose-original-request-on-response branch June 18, 2024 12:23
@armandabric
Copy link
Contributor Author

armandabric commented Jun 18, 2024

Two suggestions for the v7:

  • it could nice de rework the paramater order (req, res, options)
  • and avoid to surcharge the standard Request and pass the data in the options argument

@drwpow
Copy link
Contributor

drwpow commented Jun 21, 2024

@armandabric suggestions taken, and updated in 0.10.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants