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

make implement route less strict #26

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tender-fans-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nornir/rest": patch
---

Update handler type of implement route to be less persnickety
7 changes: 4 additions & 3 deletions packages/rest/src/runtime/openapi/openapi-router.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type GenericRouteBuilder = (chain: Nornir<OpenAPIHttpRequest>) => Nornir<OpenAPI

type RouteKey = `${HttpMethod}:${string}`


export class OpenAPIRouter<
const InputSpec,
const Spec extends OpenAPIV3_1.Document = DereferenceSpec<InputSpec>
Expand Down Expand Up @@ -181,8 +182,9 @@ export class OpenAPIRouter<
const Method extends UnionIntersection<keyof NonNullable<NonNullable<Spec["paths"]>[Path]>, OpenAPIHttpMethods>,
Operation extends OpenAPIV3_1.OperationObject = OperationFromDocument<Spec, Path, Method>,
InputType = RequestTypeFromOperation<Operation>,
ResponseType = ResponseTypeFromOperation<Operation>
>(path: Path, method: Method, handler: (chain: Nornir<NoInfer<InputType>>) => Nornir<NoInfer<InputType>, NoInfer<ResponseType>>) {
ResponseType = ResponseTypeFromOperation<Operation>,
Handler extends (chain: Nornir<NoInfer<InputType>>) => Nornir<NoInfer<InputType>, NoInfer<ResponseType>> = (chain: Nornir<NoInfer<InputType>>) => Nornir<NoInfer<InputType>, NoInfer<ResponseType>>
>(path: Path, method: Method, handler: NoInfer<Handler>) {
const route = {
path: path as string,
method: method.toUpperCase() as HttpMethod,
Expand Down Expand Up @@ -284,4 +286,3 @@ export class OpenAPIRouter<
}
}
}

Loading
Loading