Skip to content

Commit ee70e44

Browse files
committed
update options
1 parent 08813a9 commit ee70e44

File tree

6 files changed

+7
-62
lines changed

6 files changed

+7
-62
lines changed

packages/openapi/src/adapters/fetch/openapi-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
1111
private readonly standardHandler: StandardHandler<T>
1212

1313
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>) {
14-
const matcher = options?.matcher ?? new OpenAPIMatcher(options)
15-
const codec = options?.codec ?? new OpenAPICodec(options)
14+
const matcher = options?.matcher ?? new OpenAPIMatcher()
15+
const codec = options?.codec ?? new OpenAPICodec()
1616

1717
this.standardHandler = new StandardHandler(router, matcher, codec, options)
1818
}

packages/openapi/src/adapters/standard/openapi-codec.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ describe('openAPICodec', () => {
1313
deserialize: vi.fn(),
1414
} as any
1515

16-
const codec = new OpenAPICodec({
17-
serializer,
18-
})
16+
const codec = new OpenAPICodec(serializer)
1917

2018
describe('.decode', () => {
2119
describe('with compact structure', () => {

packages/openapi/src/adapters/standard/openapi-codec.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ import { OpenAPISerializer } from '@orpc/client/openapi'
66
import { fallbackContractConfig } from '@orpc/contract'
77
import { isObject } from '@orpc/shared'
88

9-
export interface OpenAPICodecOptions {
10-
serializer?: OpenAPISerializer
11-
}
12-
139
export class OpenAPICodec implements StandardCodec {
14-
private readonly serializer: OpenAPISerializer
15-
16-
constructor(options?: OpenAPICodecOptions) {
17-
this.serializer = options?.serializer ?? new OpenAPISerializer()
10+
constructor(
11+
private readonly serializer: OpenAPISerializer = new OpenAPISerializer(),
12+
) {
1813
}
1914

2015
async decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown> {
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import type { Context } from '@orpc/server'
22
import type { RPCHandlerOptions } from '@orpc/server/standard'
3-
import type { OpenAPICodecOptions } from './openapi-codec'
4-
import type { OpenAPIMatcherOptions } from './openapi-matcher'
53

6-
export interface OpenAPIHandlerOptions<T extends Context>
7-
extends RPCHandlerOptions<T>, OpenAPIMatcherOptions, OpenAPICodecOptions {}
4+
export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T> {}

packages/openapi/src/adapters/standard/openapi-matcher.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,30 +185,6 @@ describe('openapiMatcher', () => {
185185
expect(pongLoader).toHaveBeenCalledTimes(4)
186186
})
187187

188-
it('with ignoreUndefinedMethod=true', async () => {
189-
const rpcMatcher = new OpenAPIMatcher({ ignoreUndefinedMethod: true })
190-
rpcMatcher.init(router)
191-
192-
expect(await rpcMatcher.match('POST', '/base')).toEqual(undefined)
193-
194-
expect(await rpcMatcher.match('DELETE', '/ping/unnoq')).toEqual({
195-
path: ['nested', 'ping'],
196-
procedure: routedPing,
197-
params: { ping: 'unnoq' },
198-
})
199-
200-
expect(await rpcMatcher.match('GET', '/pong/something')).toEqual({
201-
path: ['pong'],
202-
procedure: routedPong,
203-
params: { pong: 'something' },
204-
})
205-
206-
expect(await rpcMatcher.match('POST', '/nested/pong')).toEqual(undefined)
207-
208-
expect(await rpcMatcher.match('POST', '/')).toEqual(undefined)
209-
expect(await rpcMatcher.match('POST', '/not_found')).toEqual(undefined)
210-
})
211-
212188
it('/ in path', async () => {
213189
const ping1 = new Procedure({
214190
...ping['~orpc'],

packages/openapi/src/adapters/standard/openapi-matcher.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ import { convertPathToHttpPath, createContractedProcedure, eachContractProcedure
55
import { addRoute, createRouter, findRoute } from 'rou3'
66
import { standardizeHTTPPath } from '../../utils'
77

8-
export interface OpenAPIMatcherOptions {
9-
/**
10-
* Ignore procedure that does not have a method defined in the contract.
11-
*
12-
* @default false
13-
*/
14-
ignoreUndefinedMethod?: boolean
15-
}
16-
178
export class OpenAPIMatcher implements StandardMatcher {
189
private readonly tree = createRouter<{
1910
path: string[]
@@ -22,25 +13,13 @@ export class OpenAPIMatcher implements StandardMatcher {
2213
router: AnyRouter
2314
}>()
2415

25-
private readonly ignoreUndefinedMethod: boolean
26-
27-
constructor(
28-
options?: OpenAPIMatcherOptions,
29-
) {
30-
this.ignoreUndefinedMethod = options?.ignoreUndefinedMethod ?? false
31-
}
32-
3316
private pendingRouters: (EachContractProcedureLaziedOptions & { httpPathPrefix: HTTPPath, laziedPrefix: string | undefined }) [] = []
3417

3518
init(router: AnyRouter, path: string[] = []): void {
3619
const laziedOptions = eachContractProcedure({
3720
router,
3821
path,
3922
}, ({ path, contract }) => {
40-
if (!contract['~orpc'].route.method && this.ignoreUndefinedMethod) {
41-
return
42-
}
43-
4423
const method = fallbackContractConfig('defaultMethod', contract['~orpc'].route.method)
4524
const httpPath = contract['~orpc'].route.path
4625
? toRou3Pattern(contract['~orpc'].route.path)

0 commit comments

Comments
 (0)