Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#9,765 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@effect-bot ci sta già lavorando.

Dal 22/10/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.
Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
11h 24m
PR unite (30g)
848

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.