Coder Social home page Coder Social logo

参数required = false无效 about knife4j HOT 6 CLOSED

xiaoymin avatar xiaoymin commented on May 16, 2024
参数required = false无效

from knife4j.

Comments (6)

AKcheng avatar AKcheng commented on May 16, 2024 1

以上问题我已经修改过DApiUI.js来修复此问题,已实现@ApiModelProperty注解中required无效的问题,同时增加了example显示列,当然修改以上代码是不够的,还需要修改后台代码,后台代码可以参考我的文章
https://my.oschina.net/honesty/blog/1838007
@yidao620c @xiaoymin
swagger-bootstrap-ui

from knife4j.

xiaoymin avatar xiaoymin commented on May 16, 2024

你好,原始传参,如果使用的是

public RestMessage reqbody(@requestbody ReqEntity reqEntity)
这种接收实体类的,即使ReqEntity对象定义ApiModelProperty,因为swagger解析出来的json没有该字段,所以展现出来默认给处理成true了
如果用参数的形式 比如

public RestMessage deletetest(@RequestParam(value = "code") String code)
这种,设置required是有效的
这里我是改成将实体类字段解析出来,针对写了ApiModelProperty注解的中文字段解析出来
swagger的默认ui处理就是一个json,字段没有列出

from knife4j.

xiaoymin avatar xiaoymin commented on May 16, 2024

根据swagger的响应,目前已可以显示,使用版本1.7.7,欢迎升级反馈,谢谢:)
谢谢@AKcheng的建议

from knife4j.

einsitang avatar einsitang commented on May 16, 2024

@xiaoymin

<dependency>
      <groupId>com.github.xiaoymin</groupId>
      <artifactId>knife4j-spring-boot-starter</artifactId>
      <version>2.0.5</version>
</dependency>

也存在上述问题。

如果我试用@PostMapping和@requestbody的方式定义rest api接口,doc.html上的 Swagger Models 显示属性都是false,我看到接口上有单独的required字段,并且也和@ApiModelProperty定义的一致。

请问这个版本可以解决吗?我们正在使用springboot 2.1.18

from knife4j.

wanbolantian avatar wanbolantian commented on May 16, 2024

我用的2.0.5 版本,也是存在不能显示 required=true的情况

Spring boot 版本

org.springframework.boot
spring-boot-starter-parent
2.1.7.RELEASE

knife4j版本

com.github.xiaoymin
knife4j-spring-boot-starter
2.0.5

实体类定义
image

from knife4j.

xiaoymin avatar xiaoymin commented on May 16, 2024

我用的2.0.5 版本,也是存在不能显示 required=true的情况

Spring boot 版本 org.springframework.boot spring-boot-starter-parent 2.1.7.RELEASE

knife4j版本 com.github.xiaoymin knife4j-spring-boot-starter 2.0.5

实体类定义 image

2.0.5存在这个bug,后面的版本修复了,可以参考一下版本日志

https://xiaoym.gitee.io/knife4j/changelog/

另外如果Spring Boot的版本太低,可以考虑单纯用新版本的ui,排除掉老的,例如

<dependency>
	<groupId>com.github.xiaoymin</groupId>
	<artifactId>knife4j-spring-boot-starter</artifactId>
	<exclusions>
              <!--排除老的->
		<exclusion>
			<groupId>com.github.xiaoymin</groupId>
			<artifactId>knife4j-spring-ui</artifactId>
		</exclusion>
	</exclusions>
</dependency>

 <!--使用新的->
<dependency>
	<groupId>com.github.xiaoymin</groupId>
	<artifactId>knife4j-spring-ui</artifactId>
       <version>2.0.9</version>
</dependency>

from knife4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.