Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

@effect/openapi-generator: generated output triggers the language service `schemaNumber` and `unnecessaryTypeofType` diagnostics

Đã đóng
#7,646 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #7647 của @Stanzilla — đã đóng, không merge
  • #9694 của @effect-bot — đã 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
Lĩnh vực
api, tooling

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

  1. Numbers from JSON are always finite, so Schema.Finite (and Schema.Int for type: integer) would satisfy schemaNumber. The generator already appends Schema.isFinite() for number, so the intent is there; only the base schema differs.
  2. Operation signatures reference typeof X.Type even though the generator emits export type X = ... for the same name in the same file. Emitting X would satisfy unnecessaryTypeofType.

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.