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

