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

FastAPI生成的OpenAPI规范是否合规?openapi-generator报错排查

问题:FastAPI生成的OpenAPI文件被openapi-generator-cli判定无效的原因排查

我不确定问题出在哪里——FastAPI生成的OpenAPI文件我认为是有效的,但最新版本的openapi-generator-cli判定该文件无效。报错信息如下:

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 2
Errors: 
        -attribute paths.'/units/{id}/charts/'(get).parameters.[group_mode].schemas.required is not of type `array`
Warnings: 
        -attribute paths.'/units/{id}/charts/'(get).parameters.[group_mode].schemas.required is not of type `array`

        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:701)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:728)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:519)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

对应的OpenAPI参数结构显示:group_mode参数的schemas字段下存在required属性,其值为布尔类型true。

我编写的FastAPI代码如下:

group_mode: GroupMode = Query(
        default="1d",
        description="Group by a parameter. Options are Minute, Hour, Day, Week, Month, Year.",
        required=True,
    ),

想请教问题根源:

  • 是OpenAPI规范有效但代码生成器配置错误?
  • 还是代码生成器判定正确而FastAPI生成的规范有误?
  • 或是我的代码存在问题?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 18:07:30