Flatten nested unions in `Schema.toJsonSchemaDocument`
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 74/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- json, typescript
- Ambito
- backend
Direzione di ricerca
Read packages/effect/src/internal/schema/toJsonSchemaDocument.ts, especially compileJsonSchema's Union case around the linked lines 611–623, and compare it with the existing nested allOf handling in appendJsonSchema around lines 187–190. Add coverage for nested anyOf output, including members with annotations or $refs and the stated oneOf limitation. Done when eligible nested anyOf members are flattened while other members retain their structure.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What is the problem this feature would solve?
The current output is valid; this is about its shape. Schema.toJsonSchemaDocument writes each member of a Union as one anyOf option, whatever that member is. NullOr of a union, or a union of unions, then comes out as an anyOf inside an anyOf:
import { Schema } from 'effect';
const Person = Schema.Struct({ name: Schema.String });
const Company = Schema.Struct({ company: Schema.String });
const Team = Schema.Struct({ team: Schema.String });
const owner = Schema.NullOr(Schema.Union([Person, Company]));
const member = Schema.Union([Schema.Union([Person, Company]), Team]);
console.log(JSON.stringify(Schema.toJsonSchemaDocument(owner).schema));
console.log(JSON.stringify(Schema.toJsonSchemaDocument(member).schema));
Output (abridged):
{"anyOf":[{"anyOf":[{…name…},{…company…}]},{"type":"null"}]}
{"anyOf":[{"anyOf":[{…name…},{…company…}]},{…team…}]}
The nested form means the same as the flat one, but it's harder to read in rendered docs, and client generators turn it into nested union types.
What is the feature you are proposing to solve the problem?
Write the flat form:
{"anyOf":[{…name…},{…company…},{"type":"null"}]}
{"anyOf":[{…name…},{…company…},{…team…}]}
In the Union case of compileJsonSchema, an anyOf member whose only keyword is anyOf can be replaced by its own members. A member carrying anything else, like an annotation or a $ref to a definition, has to stay as it is:
appendJsonSchema already splices a nested allOf this way:
The oneOf mode can't be flattened like this: a value matching every option of { oneOf: [{ oneOf: [a, b] }, c] } is accepted, while { oneOf: [a, b, c] } rejects it.
What alternatives have you considered?
Flattening the output afterwards, in each tool that consumes it. That's being proposed for an OpenAPI converter too, but output used directly, and every other consumer, would stay nested. The same nesting comes from other libraries' JSON Schema output:
- standard-community/standard-openapi#41
- open-circle/valibot#1710
- colinhacks/zod#6673
Version: effect 4.0.5
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 10h 22m
- PR unite (30g)
- 771
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Effect-TS/effect
-
BrowserWorkerRunner: port finalizer throws when the worker global has no close() (Bun)Forse già presa @santiago-ramos-02 l’ha presa 19 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Effect-TS/effect#8635 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Support {self: this} for fnUntracedForse di nuovo libera @ArjunCodess l’ha presa 30 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Effect-TS/effect#8101 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
HashMap.set keeps the old value when the new one is Equal to itForse già presa @schutzelaars l’ha presa oggi. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
I maintainer di solito rispondono entro 1 giorno
-
OpenApi: optional query and header parameters are documented as nullableForse già presa @Marve10s l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
I maintainer di solito rispondono entro 1 giorno
-
OpenApi.fromApi drops the data schema of `HttpApiSchema.StreamSse({ data })`: `Schema.fromJsonString` no longer emits `contentSchema`Forse già presa @effect-bot l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Effect-TS/effect#9353 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
area: aria/combobox gemini-triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
angular/components#33973 ·
I maintainer di solito rispondono entro 1 giorno
-
bug priority: P2
Difficoltà 1/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
[bug] status, list and push crash with an uncaught NotInitializedError stack trace when teamai is not initializedForse già presa @jay23606 l’ha presa oggi. Apertabug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Tencent/teamai-cli#1227 ·
I maintainer di solito rispondono entro 1 giorno
-
[Tool]: YapAperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 62/100
withkarann/aifoxx#417 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sindresorhus/eslint-plugin-unicorn#3921 ·
I maintainer di solito rispondono entro 1 giorno