You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarkus-OpenAPI-Generator生成客户端后构建失败求助

解决方案

针对你遇到的BaseCompositeAuthenticationProvider缺少Bean定义注解的问题,可尝试以下几种解决方式:

1. 检查OpenAPI规范中的认证配置

你的addressapi.yaml可能包含了多种认证方式(如API Key + OAuth2组合),而petstore.yaml仅使用单一认证,这会触发生成器创建复合认证提供者,但Quarkus 3.x的CDI要求Bean必须有明确的作用域注解。如果不需要多认证,可简化yaml中的认证配置,只保留实际需要的认证scheme。

2. 手动注册该类为CDI Bean

创建一个简单的类,通过CDI Producer或RegisterBean机制将BaseCompositeAuthenticationProvider注册为Bean:

方式一:使用Producer方法

import io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;

public class AuthProviderProducer {

    @Produces
    @ApplicationScoped
    public BaseCompositeAuthenticationProvider createAuthProvider() {
        return new BaseCompositeAuthenticationProvider();
    }
}

方式二:使用@RegisterBean注解(Quarkus 3.x+支持)

import io.quarkiverse.openapi.generator.providers.BaseCompositeAuthenticationProvider;
import jakarta.enterprise.context.ApplicationScoped;
import io.quarkus.arc.RegisterBean;

@RegisterBean(types = BaseCompositeAuthenticationProvider.class, scope = ApplicationScoped.class)
public class AuthProviderRegistration {
}

将上述类放在项目的src/main/java下的任意包路径中即可。

3. 配置OpenAPI生成器指定单一认证类型

如果你的API确实需要多种认证,但想避免生成复合提供者,可在application.properties中强制指定使用的认证类型:

# 替换为你实际需要的认证类型,比如apiKey、oauth2等
quarkus.openapi-generator.codegen.spec.addressapi_yaml.auth-type=apiKey
# 若有多个同类型认证,可指定具体的scheme名称
quarkus.openapi-generator.codegen.spec.addressapi_yaml.auth-scheme=your_auth_scheme_name

4. 验证版本兼容性

Quarkus 3.22.2属于较新的版本,quarkus-openapi-generator 2.10.0可能存在兼容性适配问题。尝试升级openapi-generator扩展到最新稳定版本(如3.x系列),或降级Quarkus到与2.10.0匹配的版本。

内容的提问来源于stack exchange,提问作者Tchypp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 03:15:00