Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Effect 3: add `~standard.jsonSchema` to `Schema.standardSchemaV1`

已关闭
#9,765 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@effect-bot 已经在做这个了。

开始于 2026年10月22日。

评估

这个 Issue 还没有评估数据。

描述

What is the problem this feature would solve?

Effect 4 implements Standard JSON Schema through Schema.toStandardJSONSchemaV1. On Effect 3 ([email protected]), Schema.standardSchemaV1 only implements Standard Schema validation:

import { Schema } from "effect"

const Note = Schema.Struct({ title: Schema.String, pinnedAt: Schema.NumberFromString })
const standard = Schema.standardSchemaV1(Note)["~standard"]
console.log(Object.keys(standard).join(", "))
console.log(standard.jsonSchema)
version, vendor, validate
undefined

Tools that accept Standard JSON Schema can't derive JSON Schema from Effect 3 schemas, even though JSONSchema.make already generates draft-07 and draft 2020-12 on 3.x. The ~standard object is built in standardSchemaV1:

https://github.com/Effect-TS/effect/blob/57b747f0cf4ddec47f23c08553c9e7011e31f8a4/packages/effect/src/Schema.ts#L202-L205

The README says Effect 3 lives on the v3 branch and that Effect 3 issues and pull requests should target it, and that branch still receives fixes. It doesn't say whether new features are accepted there, so if 3.x only takes fixes, feel free to close this.

What is the feature you are proposing to solve the problem?

Add jsonSchema to the ~standard object returned by Schema.standardSchemaV1, mapping draft-07 to jsonSchema7 and draft-2020-12 to jsonSchema2020-12, and throwing for other targets as the spec asks. In userland:

import { JSONSchema, Schema } from "effect"

const targets = { "draft-07": "jsonSchema7", "draft-2020-12": "jsonSchema2020-12" }

const converter = (schema) => ({ target }) => {
  if (!Object.hasOwn(targets, target)) {
    throw new Error(`Unsupported target: ${target}`)
  }
  return JSONSchema.make(schema, { target: targets[target] })
}

const standardJSONSchemaV1 = (schema) => {
  const standard = Schema.standardSchemaV1(schema)
  standard["~standard"].jsonSchema = {
    input: converter(Schema.encodedSchema(schema)),
    output: converter(Schema.typeSchema(schema)),
  }
  return standard
}

const Note = Schema.Struct({ title: Schema.String, pinnedAt: Schema.NumberFromString })
const { jsonSchema } = standardJSONSchemaV1(Note)["~standard"]
console.log(JSON.stringify(jsonSchema.input({ target: "draft-2020-12" })))
console.log(JSON.stringify(jsonSchema.output({ target: "draft-07" })))
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","required":["title","pinnedAt"],"properties":{"title":{"type":"string"},"pinnedAt":{"type":"string","description":"a string to be decoded into a number"}},"additionalProperties":false}
{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","required":["title","pinnedAt"],"properties":{"title":{"type":"string"},"pinnedAt":{"type":"number"}},"additionalProperties":false}

The StandardJSONSchemaV1 types arrived in @standard-schema/[email protected], while effect 3.x declares ^1.0.0, so the range would need a bump:

https://github.com/Effect-TS/effect/blob/57b747f0cf4ddec47f23c08553c9e7011e31f8a4/packages/effect/package.json#L58

What alternatives have you considered?
  • The userland wrapper above, which every project on 3.x would have to copy.
  • Upgrading to Effect 4, the long-term path, which isn't always possible right away for an existing 3.x codebase.
主要语言
TypeScript
星标
16.7k
派生
808
平均合并
11 小时 24 分钟
30 天内合并 PR
848

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。