Schema: accept a Standard Schema (Zod, Valibot, ArkType) as an Effect schema
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 22/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- api
Hướng nghiên cứu
Read Schema.toStandardSchemaV1 and Schema.declare in packages/effect/src/Schema.ts first, since the inbound adapter mirrors the outbound one and must carry a JSON Schema where a declaration carries none. Then look at SchemaRepresentation.fromJsonSchemaDocument to see how a JSON Schema document is attached to a schema, since the OpenAPI output depends on it. Done means Schema.fromStandardSchemaV1 exists with InferOutput/InferInput types, decoding delegates to ~standard.validate with issue paths mapped, JSON Schema comes from ~standard.jsonSchema.input, and new tests in packages/effect/test cover Zod/Valibot/ArkType and the empty {} fallback.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is the problem this feature would solve?
Effect can turn its schemas into Standard Schemas (Schema.toStandardSchemaV1, Schema.toStandardJSONSchemaV1) but can't take one in. HttpApi, Rpc and AI tools only accept Effect schemas, so a team with existing Zod, Valibot or ArkType schemas has to rewrite them first.
Wrapping one in a declaration handles validation, but the JSON Schema is lost. A declaration has no JSON Schema of its own, so the field becomes {} even though Zod knows the shape ([email protected], [email protected]):
import { Schema } from "effect"
import * as z from "zod"
const User = z.object({ name: z.string(), age: z.number().int().min(18) })
const Body = Schema.Struct({
user: Schema.declare((u): u is z.output<typeof User> => User.safeParse(u).success)
})
console.log(JSON.stringify(User["~standard"].jsonSchema.input({ target: "draft-2020-12" })))
console.log(JSON.stringify(Schema.toJsonSchemaDocument(Body).schema))
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"name":{"type":"string"},"age":{"type":"integer","minimum":18,"maximum":9007199254740991}},"required":["name","age"]}
{"type":"object","properties":{"user":{}},"required":["user"],"additionalProperties":true}
HttpApi's OpenAPI output has the same {} for a payload wrapped this way.
What is the feature you are proposing to solve the problem?
An inbound adapter, something like Schema.fromStandardSchemaV1(schema), with the name and shape up to you.
- The type is
InferOutputand the encoded type isInferInput. - Decoding calls
~standard.validate, sync or async, and maps each issue to its path. - JSON Schema comes from
~standard.jsonSchema.input({ target: "draft-2020-12" })when the schema has it, otherwise{}. Zod 4 and ArkType 2.2 have it, and Valibot has it throughtoStandardJsonSchemafrom@valibot/to-json-schema. - Standard Schema has no encode, so encoding either fails or passes the value through unchanged. Passthrough is right when the input and output types match, but that's your call.
The JSON Schema part is what userland can't do today, since a declaration can't supply its own. Happy to send a PR if you'd take one.
What alternatives have you considered?
- A
Schema.declareConstructorwrapper that maps issues. Validation works, including nested paths and async refinements, but the JSON Schema is{}as above. - Rebuilding the encoded side from the library's JSON Schema with
SchemaRepresentation.fromJsonSchemaDocument, thenSchema.decodeTothe declared type. The JSON Schema is right, but every value is validated twice. Effect's rebuilt schema runs first and stops at its first issue, so users see "Expected a value greater than or equal to 18" instead of the library's message, andpatternhas to be ignored. - An Effect integration shipped by Zod. I maintain Zod and would rather not, since it'd hit the same JSON Schema problem and only cover Zod users.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 21 giờ 22 phút
- Pull request đã merge (30 ngày)
- 486
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Effect-TS/effect
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`@effect/ui-native` (Effect-TS/ui): `kit/VirtualList` `list` part widens `R` to `any`, poisoning enclosing componentsCó thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#11097 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`@effect/ui-native` (Effect-TS/ui): Controlled `input` rejected-edit restore never calls `host.commit()`Có thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#11096 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Effect-TS/effect
Issue tương tự
-
check:failed streams:edit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
iptv-org/iptv#60585 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Critical path skips a child span that ends exactly when the next one startsCó thể đã có người làm @Piyush4801 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jaegertracing/jaeger-ui#4865 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
anthropics/claude-code#112972 ·
-
Type: Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày