启用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
相关产品推荐
相关产品推荐

