Skip to content

Commit f01f7b1

Browse files
authored
feat(json-schema): stable SmartCoercionPlugin (#1285)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **API Updates** * SmartCoercionPlugin and JsonSchemaCoercer are now available as stable public APIs. * SmartCoercionPluginOptions and JsonSchemaCoerceOptions are now stable configuration interfaces. * Update your project imports to reference the new stable API exports for continued compatibility. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b2d00a3 commit f01f7b1

File tree

14 files changed

+20
-22
lines changed

14 files changed

+20
-22
lines changed

apps/content/docs/openapi/plugins/smart-coercion.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ Configure the plugin with [JSON Schema Converters](/docs/openapi/openapi-specifi
4343

4444
```ts
4545
import { OpenAPIHandler } from '@orpc/openapi/fetch'
46-
import {
47-
experimental_SmartCoercionPlugin as SmartCoercionPlugin
48-
} from '@orpc/json-schema'
46+
import { SmartCoercionPlugin } from '@orpc/json-schema'
4947

5048
const handler = new OpenAPIHandler(router, {
5149
plugins: [

packages/json-schema/src/coercer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable prefer-regex-literals */
2-
import { experimental_JsonSchemaCoercer as JsonSchemaCoercer } from './coercer'
2+
import { JsonSchemaCoercer } from './coercer'
33

44
describe('jsonSchemaCoercer', () => {
55
const coercer = new JsonSchemaCoercer()

packages/json-schema/src/coercer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { JsonSchemaXNativeType } from './types'
44

55
const FLEXIBLE_DATE_FORMAT_REGEX = /^[^-]+-[^-]+-[^-]+$/
66

7-
export interface experimental_JsonSchemaCoerceOptions {
7+
export interface JsonSchemaCoerceOptions {
88
components?: Record<string, JsonSchema>
99
}
1010

11-
export class experimental_JsonSchemaCoercer {
12-
coerce(schema: JsonSchema, value: unknown, options: experimental_JsonSchemaCoerceOptions = {}): unknown {
11+
export class JsonSchemaCoercer {
12+
coerce(schema: JsonSchema, value: unknown, options: JsonSchemaCoerceOptions = {}): unknown {
1313
const [, coerced] = this.#coerce(schema, value, options)
1414
return coerced
1515
}
1616

17-
#coerce(schema: JsonSchema, originalValue: unknown, options: experimental_JsonSchemaCoerceOptions): [satisfied: boolean, coerced: unknown] {
17+
#coerce(schema: JsonSchema, originalValue: unknown, options: JsonSchemaCoerceOptions): [satisfied: boolean, coerced: unknown] {
1818
if (typeof schema === 'boolean') {
1919
return [schema, originalValue]
2020
}

packages/json-schema/src/smart-coercion-plugin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as z from 'zod'
22
import { ZodToJsonSchemaConverter } from '../../zod/src/zod4'
3-
import { experimental_SmartCoercionPlugin as SmartCoercionPlugin } from './smart-coercion-plugin'
3+
import { SmartCoercionPlugin } from './smart-coercion-plugin'
44

55
describe('smartCoercionPlugin', () => {
66
it('should coerce input based on schema', async () => {

packages/json-schema/src/smart-coercion-plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import type { JsonSchema } from './types'
66
import { CompositeSchemaConverter } from '@orpc/openapi'
77
import { toArray } from '@orpc/shared'
88
import {
9-
experimental_JsonSchemaCoercer as JsonSchemaCoercer,
9+
JsonSchemaCoercer,
1010
} from './coercer'
1111

12-
export interface experimental_SmartCoercionPluginOptions {
12+
export interface SmartCoercionPluginOptions {
1313
schemaConverters?: readonly ConditionalSchemaConverter[]
1414
}
1515

16-
export class experimental_SmartCoercionPlugin<T extends Context> implements StandardHandlerPlugin<T> {
16+
export class SmartCoercionPlugin<T extends Context> implements StandardHandlerPlugin<T> {
1717
private readonly converter: SchemaConverter
1818
private readonly coercer: JsonSchemaCoercer
1919
private readonly cache: WeakMap<AnySchema, JsonSchema> = new WeakMap()
2020

21-
constructor(options: experimental_SmartCoercionPluginOptions = {}) {
21+
constructor(options: SmartCoercionPluginOptions = {}) {
2222
this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters))
2323
this.coercer = new JsonSchemaCoercer()
2424
}

playgrounds/astro/src/pages/api/[...rest].ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import '../../polyfill'
22
import { OpenAPIHandler } from '@orpc/openapi/fetch'
33
import { onError } from '@orpc/server'
44
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
5-
import { experimental_SmartCoercionPlugin as SmartCoercionPlugin } from '@orpc/json-schema'
5+
import { SmartCoercionPlugin } from '@orpc/json-schema'
66
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
77
import { router } from '../../routers'
88
import type { APIRoute } from 'astro'

playgrounds/cloudflare-worker/worker/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RPCHandler } from '@orpc/server/fetch'
22
import { OpenAPIHandler } from '@orpc/openapi/fetch'
33
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
4-
import { experimental_SmartCoercionPlugin as SmartCoercionPlugin } from '@orpc/json-schema'
4+
import { SmartCoercionPlugin } from '@orpc/json-schema'
55
import { upgradeDurableIteratorRequest } from '@orpc/experimental-durable-iterator/durable-object'
66
import { BatchHandlerPlugin } from '@orpc/server/plugins'
77
import { router } from './routers'

playgrounds/contract-first/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { OpenAPIHandler } from '@orpc/openapi/node'
33
import { onError } from '@orpc/server'
44
import { RPCHandler } from '@orpc/server/node'
55
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
6-
import { experimental_SmartCoercionPlugin as SmartCoercionPlugin } from '@orpc/json-schema'
6+
import { SmartCoercionPlugin } from '@orpc/json-schema'
77
import { router } from './routers'
88
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
99
import './polyfill'

playgrounds/nest/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ReferenceController } from './reference/reference.controller'
77
import { ReferenceService } from './reference/reference.service'
88
import { onError, ORPCModule } from '@orpc/nest'
99
import { REQUEST } from '@nestjs/core'
10-
import { experimental_SmartCoercionPlugin as SmartCoercionPlugin } from '@orpc/json-schema'
10+
import { SmartCoercionPlugin } from '@orpc/json-schema'
1111
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
1212
import { Request } from 'express'
1313

playgrounds/next/src/app/api/[[...rest]]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { router } from '@/routers'
22
import { OpenAPIHandler } from '@orpc/openapi/fetch'
33
import { onError } from '@orpc/server'
44
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
5-
import { experimental_SmartCoercionPlugin as SmartCoercionPlugin } from '@orpc/json-schema'
5+
import { SmartCoercionPlugin } from '@orpc/json-schema'
66
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
77
import '../../../polyfill'
88
import { NewUserSchema, UserSchema } from '@/schemas/user'

0 commit comments

Comments
 (0)