Skip to content
Back to skills

Orpc Smart Coercion

ASecurity

Automatically converts input values to match schema types without manual coercion logic.

  • 8 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
toolsgitapiperformance

Works with

  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 12, 2026

npx -y skills add ali-master/skills --skill orpc-smart-coercion --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Orpc Smart Coercion?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Orpc Smart Coercion
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ali-master-orpc-smart-coercion/badge)](https://www.skillsdirectory.com/skills/ali-master-orpc-smart-coercion)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: oRPC Smart Coercion Plugin
description: Automatically converts input values to match schema types without manual coercion logic.
license: MIT
metadata:
  author: Ali Torki
  homepage: https://github.com/ali-master
  version: "1.0.0"
---

# Smart Coercion Plugin

Automatically converts input values to match schema types.

> Impacts performance. For high-performance applications, manually define coercion in your schema validation.

## Installation

```sh
npm install @orpc/json-schema@latest
```

## Setup

```ts
import { OpenAPIHandler } from '@orpc/openapi/fetch'
import { SmartCoercionPlugin } from '@orpc/json-schema'

const handler = new OpenAPIHandler(router, {
  plugins: [
    new SmartCoercionPlugin({
      schemaConverters: [
        new ZodToJsonSchemaConverter(),
      ],
    })
  ]
})
```

## How It Works

1. **Schema-guided** — Only converts when the schema specifies type
2. **Safe only** — Only safe conversions like `'123'` to `123`
3. **Keep original** — Unsafe conversions keep the original value
4. **Smart unions** — Picks the best for union types
5. **Deep conversion** — Works inside nested structures

## Native Type Support

For non-JSON-native types, oRPC uses `x-native-type` metadata:

* `x-native-type: 'bigint'` for BigInt
* `x-native-type: 'date'` for Date
* `x-native-type: 'regexp'` for RegExp
* `x-native-type: 'url'` for URL
* `x-native-type: 'set'` for Set
* `x-native-type: 'map'` for Map

## Conversion Rules

### String → Boolean

* `'true'`, `'on'` → `true`
* `'false'`, `'off'` → `false`

### String → Number

* `'123'` → `123`
* `'3.14'` → `3.14`

### String/Number → BigInt

* `'12345678901234567890'` → `12345678901234567890n`

### String → Date

* ISO format: `'2023-10-01'`, `'2020-01-01T06:15:00Z'`, etc.

### String → RegExp

* `'/^\\d+$/i'` → `new RegExp('^\\d+$', 'i')`

### String → URL

* `'https://example.com'` → `new URL('https://example.com')`

### Array → Set

* `['apple', 'banana']` → `new Set(['apple', 'banana'])`

### Array → Object

* `['apple', 'banana']` → `{ 0: 'apple', 1: 'banana' }`

### Array → Map

* `[['key1', 'value1'], ['key2', 'value2']]` → `new Map(...)`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.