代替swagger

编程入门 行业动态 更新时间:2024-10-27 04:33:56

代替<a href=https://www.elefans.com/category/jswz/34/1769105.html style=swagger"/>

代替swagger

感觉在swagger-ui上加了一些功能,基本配置

rebel+idea 热部署

坑:

接口文档设置属性不生效

接口文档修改不生效

解决:

注意是否有重复字段,检查是否继承基础类,父子类有属性重复,用了@ApiModelProperty的name属性,你用就用,name的值要和字段保持一次,别拼错了,害人害己,不加也可用,搞不懂为什么要加

我不知道是我没配置好还是knife退化了,swagger-ui的文档,接口顺序是按照代码顺序来的,knife不一致,别给我说去手动一个个加顺序注解,还有一个是实体的字段顺序,也是的,不和代码顺序一致,希望改进下,还要加个配置类,没有默认集成

接口排序

.html#tags%E5%88%86%E7%BB%84%E6%8E%92%E5%BA%8F

实体字段排序

import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.googlemon.base.Optional;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.schema.ModelPropertyBuilderPlugin;
import springfox.documentation.spi.schema.contexts.ModelPropertyContext;
import springfox.documentation.swaggermon.SwaggerPluginSupport;import java.lang.reflect.Field;import static springfox.documentation.schema.Annotations.findPropertyAnnotation;
import static springfox.documentation.swagger.schema.ApiModelProperties.findApiModePropertyAnnotation;/*** <Description>** @author CJJ* @version 1.0* @createDate 2020/07/13 14:38* @see com.suncnpapmon.config.swagger*/
@Slf4j
@Component
public class CustomApiModelPropertyPositionBuilder implements ModelPropertyBuilderPlugin {@Overridepublic boolean supports(DocumentationType delimiter) {return SwaggerPluginSupport.pluginDoesApply(delimiter);}@Overridepublic void apply(ModelPropertyContext context) {Optional<BeanPropertyDefinition> beanPropertyDefinitionOpt = context.getBeanPropertyDefinition();Optional<ApiModelProperty> annotation = Optional.absent();if (context.getAnnotatedElement().isPresent()) {annotation = annotation.or(findApiModePropertyAnnotation(context.getAnnotatedElement().get()));}if (context.getBeanPropertyDefinition().isPresent()) {annotation = annotation.or(findPropertyAnnotation(context.getBeanPropertyDefinition().get(), ApiModelProperty.class));}if (beanPropertyDefinitionOpt.isPresent()) {BeanPropertyDefinition beanPropertyDefinition = beanPropertyDefinitionOpt.get();if (annotation.isPresent() && annotation.get().position() != 0) {return;}AnnotatedField field = beanPropertyDefinition.getField();Class<?> clazz = field.getDeclaringClass();Field[] declaredFields = clazz.getDeclaredFields();Field declaredField;try {declaredField = clazz.getDeclaredField(field.getName());} catch (NoSuchFieldException | SecurityException e) {log.error("", e);return;}int indexOf = -1;for (int i = 0; i < declaredFields.length; i++) {if(declaredFields[i].equals(declaredField)) {indexOf = i;break;}}if (indexOf != -1) {context.getBuilder().position(indexOf);}}}}

不要搞那么多花里胡哨的行不行,行不行,好浪费时间找你们留的bug...........

更多推荐

代替swagger

本文发布于:2024-03-15 03:13:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1737989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:swagger

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!