[BUG][RUBY-NEXTGEN] Nothing autoloads when moduleName is not the camelized gemName
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 70/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend-api-design, devtools
Hướng nghiên cứu
Lỗi nằm trong mẫu gem.mustache của trình tạo Ruby NextGen. Bắt đầu bằng cách định vị modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache trong kho lưu trữ. Vấn đề là Zeitwerk::Loader.for_gem mong đợi tên gem khớp với tên mô-đun, nhưng khi chúng khác nhau, việc tự động tải sẽ thất bại. Cách sửa là luôn sử dụng bộ tải rõ ràng (Zeitwerk::Loader.new + push_dir) thay vì sử dụng có điều kiện. Kiểm tra bằng cách tạo một gem Ruby với gemName và moduleName không khớp, sau đó yêu cầu nó và kiểm tra xem các hằng số có được tải không. Diff được cung cấp cho thấy thay đổi chính xác cần thiết.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
When moduleName is not the camelized gemName (e.g. gemName=things_api, moduleName=Things), none of the generated constants load. For a single-level moduleName, gem.mustache sets Zeitwerk up with Zeitwerk::Loader.for_gem, which expects lib/things_api/** to define constants under ThingsApi. The generated files define them under Things, so Things::Client is never autoloaded and eager_load fails on ThingsApi.
gem.mustache already has a loader that works (Zeitwerk::Loader.new + push_dir(..., namespace: self)), but it only emits it when moduleName is nested.
openapi-generator version
master, 7.26.0-SNAPSHOT, 05b61f34d7fb0199330e1d6c57e6159f72427837
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: zeitwerk
version: 1.0.0
paths:
/things:
get:
operationId: listThings
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Thing'
components:
schemas:
Thing:
type: object
properties:
name:
type: string
Generation Details
java -jar openapi-generator-cli.jar generate -g ruby-nextgen -i spec.yaml -o out \
--additional-properties=gemName=things_api,moduleName=Things
Generated lib/things_api.rb (comments trimmed):
module Things
class << self
attr_reader :loader
end
@loader = Zeitwerk::Loader.for_gem
@loader.setup
def self.eager_load!
@loader.eager_load
end
end
Steps to reproduce
$LOAD_PATH.unshift 'out/lib'
require 'things_api'
Things::Client.new(base_url: 'http://localhost')
Actual (ruby 3.3, zeitwerk 2.8.3):
uninitialized constant Things::Client (NameError)
Things.eager_load! raises uninitialized constant ThingsApi (NameError).
Expected: the client loads, as it does with gemName=things.
Related issues/PRs
None found.
Suggest a fix
Always use the explicit loader. push_dir(namespace: self) doesn't depend on gemName matching moduleName. With this change the snippet works for both gemName=things_api and gemName=things, and Things::VERSION still resolves.
--- a/modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache
+++ b/modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache
@@ -21,10 +21,9 @@
attr_reader :loader
end
-{{#moduleNameNested}}
- # Nested moduleName: for_gem can't target a nested namespace, so drive Zeitwerk
- # explicitly. The parent module(s) above are pre-defined so `module {{moduleName}}`
- # (here and in every generated file) reopens rather than raising NameError.
+ # for_gem derives the namespace from gemName, which need not match moduleName (and
+ # can't target a nested one), so drive Zeitwerk explicitly. Any parent module(s) above
+ # are pre-defined so `module {{moduleName}}` reopens rather than raising NameError.
@loader = Zeitwerk::Loader.new
@loader.push_dir("#{__dir__}/{{gemName}}", namespace: self)
# version.rb defines VERSION (not a `Version` class). for_gem's GemInflector special-cases
@@ -32,10 +31,6 @@
# {{moduleName}}::VERSION available.
@loader.ignore("#{__dir__}/{{gemName}}/version.rb")
require_relative "{{gemName}}/version"
-{{/moduleNameNested}}
-{{^moduleNameNested}}
- @loader = Zeitwerk::Loader.for_gem
-{{/moduleNameNested}}
{{#zeitwerkInflections.0}}
# Model names keep their acronym casing (e.g. HTTPConfig), but Zeitwerk's default
# inflector would expect HttpConfig from the file name. Register the exceptions so
Generated with Claude Code
- Ngôn ngữ chính
- Java
- Star
- 26.8k
- Fork
- 7.7k
- Merge trung bình
- 2 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 103
Chuẩn bị môi trường
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 OpenAPITools/openapi-generator
-
Issue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenAPITools/openapi-generator#25021 ·
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
OpenAPITools/openapi-generator#25014 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Issue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenAPITools/openapi-generator#24859 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=trueĐang mởIssue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OpenAPITools/openapi-generator#24842 · 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 86/100
OpenAPITools/openapi-generator#24830 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của OpenAPITools/openapi-generator
Issue tương tự
-
ScyllaDB Manual: 3 broken linksĐang mởlink-check link-check:manual
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
open-telemetry/opentelemetry-java#8870 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
P2 testing
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement javascript
Độ 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
-
area/core kind/bug status/triage team/core-shared
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày