[BUG][RUBY-NEXTGEN] Nothing autoloads when moduleName is not the camelized gemName
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 70/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- backend-api-design, devtools
Línea de trabajo
El error está en la plantilla gem.mustache del generador Ruby NextGen. Comience localizando modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache en el repositorio. El problema es que Zeitwerk::Loader.for_gem espera que el nombre de la gema coincida con el nombre del módulo, pero cuando difieren, la autocarga falla. La solución es usar siempre el cargador explícito (Zeitwerk::Loader.new + push_dir) en lugar de hacerlo condicionalmente. Pruebe generando una gema Ruby con gemName y moduleName que no coincidan, luego requiriéndola y verificando si las constantes se cargan. El diff proporcionado muestra el cambio exacto necesario.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Java
- Estrellas
- 26.8k
- Forks
- 7.7k
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 103
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de OpenAPITools/openapi-generator
-
Issue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenAPITools/openapi-generator#25021 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OpenAPITools/openapi-generator#25014 ·
Los mantenedores suelen responder en 1 día
-
Issue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenAPITools/openapi-generator#24859 ·
Los mantenedores suelen responder en 1 día
-
[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=trueAbiertoIssue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
OpenAPITools/openapi-generator#24842 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
OpenAPITools/openapi-generator#24830 ·
Los mantenedores suelen responder en 1 día
Todos los issues de OpenAPITools/openapi-generator
Issues similares
-
P2 testing
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
area/core kind/bug status/triage team/core-shared
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
checkstyle/checkstyle#21755 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
spring-projects/spring-integration#11495 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día