express-openapi: extend expressJS Request Handler Parameters through express-openapi#817
Open
joshAg wants to merge 1 commit intokogosoftwarellc:mainfrom
Open
express-openapi: extend expressJS Request Handler Parameters through express-openapi#817joshAg wants to merge 1 commit intokogosoftwarellc:mainfrom
joshAg wants to merge 1 commit intokogosoftwarellc:mainfrom
Conversation
The added generic types for RequestHandler come from expressJS and allow the user to give types to various parts of the request and response object in a way that allows typescript to infer types. Currently if the user wants typescript to infer one of these parts has a certain type they have to explicitly case the object as such. This will remove the need to cast at all. This change is necessary because with the current code the user cannot explicitly type req or res because the compiler will complain about assigning a function where they have been more defined to the Operation type since Operation is missing those specific type definitions.
For example
```
// normally generated from the openAPI definition
interface myExampleDictionary extends core.ParamsDictionary {
key: string
}
const GET: Operation = async (req: express.Request<myExampleDictionary>, res: express.Response, next: express.NextFunction) => {
```
Instead we currently have to do something like
```
// normally generated from the openAPI definition
interface myExampleDictionary extends core.ParamsDictionary {
key: string
}
const GET: Operation = async (req, res, next) => {
const params = req.params as myExampleDictionary;
```
Contributor
|
@joshAg please get the build to pass |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The added generic types for RequestHandler come from expressJS and allow the user to give types to various parts of the request and response object in a way that allows typescript to infer types. Currently if the user wants typescript to infer one of these parts has a certain type they have to explicitly case the object as such. This will remove the need to cast at all. This change is necessary because with the current code the user cannot explicitly type req or res because the compiler will complain about assigning a function where they have been more defined to the Operation type since Operation is missing those specific type definitions.
For example
Instead we currently have to do something like
Note: This checklist isn't meant to show up on the actual Pull Request (PR). It is added here to make you aware of items our maintainers will look for when reviewing your PR. If your PR is missing any of these items it will be rejected! Please delete this message and the following checklist and replace it with your own message as you see fit.
express-openapi: fixing something) Note: You can use the bin/commit script to automate this.openapi-jsonschema-parameters: Adding examples to the validation keywords (fixes #455)).