OpenApi: optional query and header parameters are documented as nullable
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 57/100
- Loại issue
- Lỗi
- Độ 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
Start in OpenApi.ts at processParameters, the entry point named in the issue, and trace how optional query and header parameter schemas pass through the representation pipeline. Compare those parameter schemas with the body handling described in the issue, then inspect or add focused tests for OpenApi.fromApi query and header output. Done means optional parameters omit JSON null while preserving the documented string forms, with body behavior unchanged.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What version of Effect is running?
4.0.5. Also seen on 4.0.0. OpenApi.ts on main is the same as in 4.0.5.
What steps can reproduce the bug?
OpenApi.fromApi documents a query parameter declared with Schema.optional as anyOf: [T, null]. A query string has no way to send null, and the server's query decoder doesn't accept one.
import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
const Query = Schema.Struct({
limit: Schema.optional(Schema.FiniteFromString),
cursor: Schema.optional(Schema.NullOr(Schema.String))
})
const Api = HttpApi.make("api").add(
HttpApiGroup.make("items").add(
HttpApiEndpoint.get("list", "/items", { query: Query, success: Schema.String })
)
)
console.log(JSON.stringify(OpenApi.fromApi(Api).paths["/items"].get.parameters, null, 2))
// What the server does with the `null` the document allows
const decodeQuery = Schema.decodeUnknownExit(Schema.toCodecStringTree(Query))
console.log(decodeQuery({ limit: "null" })._tag) // "Failure"
What is the expected behavior?
limit documented as { "type": "string" } with required: false. required: false already says the parameter can be left out, so the undefined that Schema.optional adds has nothing left to describe.
cursor documented with only the string form of its NullOr, anyOf: [{ "type": "string", "enum": ["null"] }, { "type": "string" }], and no JSON null around it.
What do you see instead?
[
{
"name": "limit",
"in": "query",
"schema": { "anyOf": [{ "type": "string" }, { "type": "null" }] },
"required": false
},
{
"name": "cursor",
"in": "query",
"schema": {
"anyOf": [
{ "anyOf": [{ "type": "string", "enum": ["null"] }, { "type": "string" }] },
{ "type": "null" }
]
},
"required": false
}
]
cursor shows the mismatch most clearly. Its NullOr gets the query codec's representation, the string "null". The undefined from Schema.optional gets the JSON codec's, where Undefined encodes as null. One parameter ends up described by two codecs.
Additional information
- Headers have the same problem:
headers: Schema.Struct({ "x-trace": Schema.optional(Schema.String) })comes out asanyOf: [{ "type": "string" }, { "type": "null" }]. - Bodies are fine. A JSON body does decode
nulltoundefined, soT | nullis the right description there. - Effect's own
HttpApiClientis unaffected, since it dropsundefinedbefore building the URL. Clients generated from the document are the ones that break. We generate ours with orval, which typeslimitasstring | nulland sends?limit=nullwhen givennull. The service then rejects the request, or, for a plainSchema.String, reads"null"as a real value. - Switching to
Schema.optionalKeyfixes the document. It also makes{ limit: undefined }fail to encode, so every caller that builds a query from a possibly-undefined value has to leave the key out by hand, which is whatSchema.optionalexists to avoid. - A possible workaround until it's fixed: an
OpenApi.Transformthat drops thenullmember from every parameter whererequiredisfalse. - My guess at the cause, from reading the source:
processParametersqueues parameter schemas as"properties"ops, and those go through the same representation pipeline as bodies, so an optional property'sundefinedgets the JSON rule.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 11 giờ 24 phút
- Pull request đã merge (30 ngày)
- 848
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 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
AI providers: tool results cannot carry images because non-string results are JSON.stringify'dCó thể đã có người làm @nmnmcc đã nhận hôm nay. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Effect-TS/effect#9857 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`Schema.Literals`: add `omit`, the complement of `pick`Có thể đã có người làm @effect-bot đã nhận 1 ngày trước. Đang mởenhancement Needs Evaluation
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Support the `openapi-3.0` target in `Schema.toStandardJSONSchemaV1`Có thể đã có người làm @MichaelDeBoey đã nhận 1 ngày trước. Đang mởenhancement Needs Evaluation
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Effect-TS/effect#9764 · 3 bình luận ·
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ự
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
openclaw/openclaw#182077 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
aikido high security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
dequelabs/axe-linter-action#161 ·
-
[Feature Request] Update the DimCode agent icon to the 45:32 brand markCó thể đã có người làm @eric8810 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]: 建议导入源后,自动切换到新导入的源Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
lyswhut/lx-music-desktop#3026 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
abhigyanpatwari/GitNexus#3704 ·
Maintainer thường phản hồi trong vòng 1 ngày