Skip to content

Commit

Permalink
Merge pull request #26 from jfrconley/joco/relax-openapi-router
Browse files Browse the repository at this point in the history
make implement route less strict
  • Loading branch information
jfrconley authored Mar 21, 2024
2 parents 20e9929 + 9ad9ce7 commit 14fbee6
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 470 deletions.
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

0 comments on commit 14fbee6

Please sign in to comment.