Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default-flat-param-object does not take effect #2181

Closed
Charles7c opened this issue Mar 30, 2023 · 2 comments · Fixed by #2183
Closed

default-flat-param-object does not take effect #2181

Charles7c opened this issue Mar 30, 2023 · 2 comments · Fixed by #2183
Labels
invalid This doesn't seem right

Comments

@Charles7c
Copy link

If you ❤️ this project consider becoming a sponsor.
If you already use the springdoc-openapi, please do not forget adding a github star to this repository.

Describe the bug

I upgraded the springdoc-openapi dependencies from 1.6.9 to 1.6.15, and then I tried to use the new feature default-flat-pam-object, but it didn't work after the configuration was complete.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    Spring Boot 2.7.10

  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi 1.6.15

  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    I had to make extensive use of the @ParameterObject annotation before, and I hope that with this configuration I can get rid of this hassle.

  • Provide with a sample code (HelloController) or Test that reproduces the problem

springdoc:
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    operations-sorter: alpha
    show-extensions: true
  api-docs:
    enabled: ${springdoc.swagger-ui.enabled}
    path: /v3/api-docs
  group-configs:
    - group: 'default'
      paths-to-match: '/**'
      packages-to-scan: top.charles7c.cnadmin.webapi.controller
  default-flat-param-object: true

https://github.com/Charles7c/continew-admin

Screenshots
image

uc4w6c added a commit to uc4w6c/springdoc-openapi that referenced this issue Mar 30, 2023
@uc4w6c
Copy link
Collaborator

uc4w6c commented Mar 30, 2023

I haven't been able to reproduce it perfectly, but I have found the code for the bug.

https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-common/src/main/java/org/springdoc/core/DelegatingMethodParameter.java#L130
It seems that it is not treated as a paramobject if it is annotated.

A simple code is below.

@GetMapping("/test1")
public String test1(@Validated Person person) {
  return null;
}

Since there is no test code in the repository, I don't know why annotations are checked, but since AbstractRequestService.isRequestTypeToIgnore determines which class should be processed, I will remove it.
https://github.com/springdoc/springdoc-openapi/pull/1805/files

@Charles7c
Copy link
Author

Ah ha, I see. I had my doubts but I couldn't believe it.

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Apr 1, 2023
Charles7c referenced this issue in continew-org/continew-admin Apr 8, 2023
1.使用 default-flat-param-object 全局设置对象型参数展示形式。此设置是在 springdoc-openapi v1.6.11 版本开始添加的新特性(详情请参阅:https://github.com/springdoc/springdoc-openapi/pull/1805),在此之前,只能在所有需要处理的对象型参数类上使用 @ParameterObject,工作量较大。
2.作者在使用上方这个配置时还遇到了一个 Bug,那就是只要在对象型参数前使用了注解,例如:@validated PageQuery pageQuery,这个配置就不会生效了。此问题已在 GitHub 提交了相应 issue(详情请参阅:https://github.com/springdoc/springdoc-openapi/issues/2181),并且 springdoc-openapi 社区某个小伙伴儿已在当前最新发布的 v2.1.0 和 v1.7.0 中修复。
注意:由于当前使用的 Knife4j 版本其内部引入的 springdoc-openapi 相关依赖非最新版本,所以为了解决配置不生效问题,暂时将部分对象型参数移除了 @validated 注解(除了 PageQuery,其他类当前也未实际添加校验,所以直接移除了)。当然如果不想移除的话,也可以从依赖上功夫,即移除 Knife4j 内引入的 springdoc-openapi 相关依赖,然后自行添加 springdoc-openapi 相关依赖并指定最新版本即可。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants