Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Springfox-接口的模式为空_Java_Jackson_Springfox - Fatal编程技术网

Java Springfox-接口的模式为空

Java Springfox-接口的模式为空,java,jackson,springfox,Java,Jackson,Springfox,我使用的是springfox 3.0.0,我有一个用作@RequestBody的接口 pom.xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> 模型 //assume

我使用的是springfox 3.0.0,我有一个用作
@RequestBody
的接口

pom.xml

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>
模型

//assume Lombok or standard getter/setters/constructors
class Clazz implements StringInterface {
  String s;
  Integer i; 
}

@JsonDeserialize(as = Clazz.class)
interface StringInterface {
  String getString();
}
在Springfox 2.9.*中,
StringInterface
的模式是

{
  "title": "StringInterface",
   "type": "object",
   "properties": {
     "s": {
       "type": "String"
    }
  }
}
但是,当我升级到3.0.0时,模式现在为空

{
  "title": "StringInterface",
  "type": "object"
}

常规类显示正确。这似乎只是界面的问题。

我建议切换到SpringDoc

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-ui</artifactId>
</dependency>
您还必须稍微改变config类的设置&用@RestController注释控制器。我个人从未见过将接口用作RequestBody,所以这种情况有点奇怪


然而,如果你开始使用你的依赖版本,那么我认为这与swagger模式生成如何解释你的JsonDeserialization有关。

。不幸的是,它需要对涉及的每个接口进行一些配置

@JsonDeserialize(as = Clazz.class)
interface StringInterface {
  static class Model {
    String getString();
  }
}
SwaggerConfig.java 类SwaggerConfig{

  @Bean
  Docket api() {
    return new Docket(OAS_30)
      .select()
      .apis(RequestHandlerSelectors.basePackage(
          "org.springframework.boot").negate())
      .directModelSubstitute(StringInterface.class, StringInterface.Model.class)
      .build();
  }

  @Component
  @Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER)
  static class ModelDeclaringClassName implements TypeNameProviderPlugin {
    boolean supports(DocumentationType delimiter) {
      return true;
  }

  String nameFor(type: Class<?>) {
    Class<?> actualClass = type.getSimpleName().equals("Model") ? 
      type.getDeclaringClass() :
      type;
  
      return type.getSimpleName();
    }
  }
}
用法如下:

private inline fun <reified T> Docket.substituteModel() =
    T::class.java.let {
        directModelSubstitute(
            it,
            it.declaredClasses.first { c ->
                c.simpleName == "Model"
            }
        )
    }
.substituteModel<StringInterface>()
.substituteModel()

您使用的依赖项是什么?您能展示您的自信吗configurtion@user3696953我更新了问题这和Springfox有同样的问题
private inline fun <reified T> Docket.substituteModel() =
    T::class.java.let {
        directModelSubstitute(
            it,
            it.declaredClasses.first { c ->
                c.simpleName == "Model"
            }
        )
    }
.substituteModel<StringInterface>()