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

启用private缓存的Cache-Control注解的Ballerina服务生成OpenAPI时编译错误

Ballerina中使用@http:Cache(isPrivate=true)执行bal build --export-openapi编译失败

在构建启用私有缓存配置的@http:Cache注解的Ballerina服务时,执行bal build --export-openapi命令生成OpenAPI规范会触发编译错误。

编译失败示例代码

type SampleHttpResponse record {|
    *http:Ok;
    string body;
|};

type ErrorResponse record {|
    *http:InternalServerError;
    string body;
|};

resource function get sample(@http:Header {name: "X-JWT-Assertion"} string jwtAssertion)
    returns @http:Cache {isPrivate: true} SampleHttpResponse|ErrorResponse {
    
    // ...
}

编译错误信息

error: compilation failed: The compiler extension 'io.ballerina.openapi.build.OpenAPIBuildCompilerPlugin' failed to complete. No value present

观察结果

  • 移除@http:Cache注解中的isPrivate: true配置后,编译恢复正常
  • 仅配置maxAge参数的@http:Cache注解,可正常生成OpenAPI规范

编译成功示例代码

无参数的@http:Cache

resource function get sample(@http:Header {name: "X-JWT-Assertion"} string jwtAssertion)
    returns @http:Cache SampleHttpResponse|ErrorResponse {
    
    // ...
}

仅配置maxAge的@http:Cache

resource function get sample(@http:Header {name: "X-JWT-Assertion"} string jwtAssertion)
    returns @http:Cache {maxAge: 86400} SampleHttpResponse|ErrorResponse {
    
    // ...
}

环境信息

  • OS: MacOS 13.3.1 (22E261)
  • 架构: Apple M1
  • Ballerina版本: Swan Lake Update 4 (2201.4.1)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 06:13:11