Support `format: "password"` as `Redacted` in JSON Schema import/export and the OpenAPI generator
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Need
Password fields in OpenAPI specs and JSON Schema documents come out as plain string, both from @effect/openapi-generator and from SchemaRepresentation.fromJsonSchemaDocument. That means credentials, API keys and tokens can show up in logs, error messages and traces, and generated schemas have no way to mark them as secrets.
Wrapping them by hand is hard to get right. The httpclient format sends payloads with bodyJsonUnsafe and never encodes them, so if you swap a field to Schema.Redacted, the request carries the literal string "<redacted>". Today the only workaround is a hand-written wrapper module around each affected operation.
Spec
OpenAPI defines password as one of the formats built into the OAS (alongside int32, int64, float and double). It applies to string:
- OAS 3.1.1, §4.4.1 Data Type Format: "A hint to obscure the value."
- OAS 3.0.3, §4.4 Data Types: "A hint to UIs to obscure input."
- OpenAPI Format Registry,
password: "a string that hints to obscure the value."
JSON Schema's own format list doesn't include password. There, format is an annotation, so the value carries over unchanged from OpenAPI specs to the JSON Schema documents produced from them.
Proposal
The mapping is format: "password" ↔ Redacted, in both directions:
- JSON Schema import (
fromJsonSchemaDocument): astringwithformat: "password"becomesSchema.RedactedFromValue(Schema.String). Decoding a JSON value gives aRedacted, encoding gives back the plain string, and checks such asminLengthstill apply to the inner string. Strings used as record keys orpropertyNamesstay plain. - Code generation (
toCodeDocument): printSchema.Redacted(Schema.String)with typeRedacted.Redacted<string>. Generated schemas keep Type and Encoded equal and go throughtoCodecJsonfor JSON, as HttpApi and generated response decoding already do. - JSON Schema export (
toJsonSchemaDocument): strings wrapped bySchema.RedactedorSchema.RedactedFromValueemitformat: "password", unless the inner schema already sets aformat. An HttpApi server's OpenAPI spec would then regenerate into a client with the sameRedactedfields. @effect/openapi-generator:httpapi: works as soon as the schemas useSchema.Redacted.httpclient: operations whose params or payload contain a password field encode them throughSchema.toCodecJsonbefore sending. Every other operation's output stays the same. Multipart bodies can't go through the JSON codec because of their files, so they unwrap their top-levelRedactedfields instead.httpclient-type-only: keeps plainstring, since nothing decodes there.
Open questions
- Default or opt-in? Turning it on by default changes the generated types of existing password fields from
stringtoRedacted<string>. That is a breaking change for those users, so it probably needs a minor release. An option would avoid that, but most users would never find out it exists. - Open objects. A
StructWithRestindex signature also applies to declared keys, so an open object'sRecord(String, Json)rest rejects theRedactedvalue when encoding. One fix is to import open objects that contain a password field as a plainStruct: extra properties are still accepted on decode but stripped instead of kept. Is that acceptable, or should the rest exclude declared keys?
I have a working prototype of all of the above, with tests. I'm happy to open a PR once we agree on the direction.
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 11h 31m
- PR unite (30g)
- 834
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
-
Xml: `positions` decode option that puts `line` and `column` on `StartElement` eventsForse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#10400 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
effect/ai: support the MCP Apps extension (`io.modelcontextprotocol/ui`)Forse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#10399 · 2 commenti · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Flat RPC client and AtomRpc query/mutation: type-check cost grows with RPCs in the group × tags calledForse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#10396 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Versioned schemas with version negotiation in HttpApi, Rpc and clusterForse già presa @effect-bot l’ha presa 1 giorno fa. Aperta
Effect-TS/effect#10383 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Schema encoding can return an internal symbol across module copiesForse già presa @schickling-assistant l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
hugomrdias/playwright-test#753 ·
I maintainer di solito rispondono entro 1 giorno
-
Review view: Daily/Weekly Review header buttons use the app-wide toolbar control styleForse già presa @colherdesopa l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 90/100
dongdongbh/Mindwtr#1515 ·
I maintainer di solito rispondono entro 1 giorno
-
pending-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
kirodotdev/Kiro#12301 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100