@effect/openapi-generator: generated output triggers the language service `schemaNumber` and `unnecessaryTypeofType` diagnostics
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 58/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- openapi, typescript
Hướng nghiên cứu
Start at the @effect/openapi-generator path handling generator.generate with format: 'httpclient', using the minimal OpenAPI spec in the issue to reproduce the output. Check generated number schemas and operation response types against the language-service diagnostics, then verify the output also avoids the reported unused decodeError case under noUnusedLocals.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The httpclient output of @effect/openapi-generator 4.0.0-rc.112 is flagged by @effect/language-service (via @effect/tsgo 0.38.0) with two suggestion diagnostics that the generator could avoid by construction.
Reproduction (spec in the collapsed block below, format: 'httpclient'):
const generator = await Effect.runPromise(OpenApiGenerator.make);
const out = await Effect.runPromise(
generator.generate(spec, { name: 'ReproClient', format: 'httpclient' }),
);
Generated (abridged):
export const Addon = Schema.Struct({
"id": Schema.Number.check(Schema.isInt().annotate({ "expected": "an integer" })),
"downloads": Schema.Number.check(Schema.isFinite().annotate({ "expected": "a finite number" })),
})
// ...
readonly "getAddon": <Config extends OperationConfig>(id: string, options: ...) =>
Effect.Effect<WithOptionalResponse<typeof GetAddon200.Type, Config>, HttpClientError.HttpClientError | SchemaError>
tsc with the language-service plugin reports:
repro.ts(11,51): suggestion TS377098: This Schema number API accepts `NaN`, `Infinity`, and `-Infinity`. Use `Schema.Finite` for finite domain numbers. ... effect(schemaNumber)
repro.ts(11,140): suggestion TS377098: ... effect(schemaNumber)
repro.ts(98,170): suggestion TS377090: This `typeof ... .Type` query can be replaced with `GetAddon200`. effect(unnecessaryTypeofType)
Expected
- Numbers from JSON are always finite, so
Schema.Finite(andSchema.Intfortype: integer) would satisfyschemaNumber. The generator already appendsSchema.isFinite()fornumber, so the intent is there; only the base schema differs. - Operation signatures reference
typeof X.Typeeven though the generator emitsexport type X = ...for the same name in the same file. EmittingXwould satisfyunnecessaryTypeofType.
Since both tools live in this monorepo, it would be good for the generator's default output to pass the language service's defaults. We currently post-process the output (replace Schema.Number with Schema.Finite, and typeof X.Type with X when the alias exists), which works but should not be necessary.
Side observation: for a spec with no error responses, the generated client declares decodeError without using it, which fails under noUnusedLocals (TS6133).
Minimal spec
{
"openapi": "3.0.0",
"info": { "title": "Repro", "version": "1.0.0" },
"paths": {
"/addons/{id}": {
"get": {
"operationId": "getAddon",
"parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "integer" } }],
"responses": {
"200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Addon" } } } }
}
}
}
},
"components": {
"schemas": {
"Addon": {
"type": "object",
"required": ["id", "downloads"],
"properties": { "id": { "type": "integer" }, "downloads": { "type": "number" } }
}
}
}
}
Versions: @effect/openapi-generator 4.0.0-rc.112, effect 4.0.0-rc.112, @effect/tsgo 0.38.0.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 11 giờ 33 phút
- Pull request đã merge (30 ngày)
- 855
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
-
`fromJsonSchemaDocument`: import open `patternProperties`Có thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#10048 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`fromJsonSchemaDocument`: intersect an object with `anyOf` branches that re-declare an enum propertyĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`fromJsonSchemaDocument`: import `dependentRequired` (draft-07 `dependencies`)Có thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#10046 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`fromJsonSchemaDocument`: import `if` / `then` / `else`Có thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#10045 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`fromJsonSchemaDocument`: import the `not` keywordCó thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#10044 · 1 người được giao ·
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ự
-
e2e-failure ready-to-code
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
redhat-developer/rhdh-plugin-export-overlays#4616 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-handle
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nextlevelbuilder/dewee-web-v2#73 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
PoCInnovation/Distribox#255 ·
Maintainer thường phản hồi trong vòng 1 ngày