openapi 3/spring boot@requestpart不是可选的

hivapdat  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(265)

我在api中创建上传路径时有点问题。例如:

/test/upload:
    post:
      operationId: post form attachemnts
      requestBody:
        content:
          multipart/form-data: 
            schema:            
              type: object
              required:
                - testId
              properties:
                testId:
                  type: string
                  example: 1
                document:
                  type: string
                  format: binary

我想发送testid(必需-这是可以的),但我的文档(jpg,pdf)必须是可选的。
由openapi生成器maven创建的一段代码-plugin:4.2.3:

@RequestParam(value="testId", required=true)  String testId,@ApiParam(value = "") @Valid @RequestPart("document") MultipartFile document

当我在 Postman 那里寄出一份只有填好的证明的邮件时,我收到了: "Required request part 'document' is not present" 我认为问题在一定程度上 @RequestPart("document") MultipartFile document 生成的正确代码应该如下所示 @RequestPart(value="document", required=false) MultipartFile document . 但你是怎么做到的?
在swagger editor、openapi 3.0.2、sb 2.2.1中创建的文档。发布声明的依赖项:

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.6.0</version>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp</groupId>
    <artifactId>okhttp</artifactId>
    <version>2.7.5</version>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp</groupId>
    <artifactId>logging-interceptor</artifactId>
    <version>2.7.5</version>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.6</version>
</dependency>

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.10.5</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.10.2</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.10.2</version>
</dependency>
<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>jackson-databind-nullable</artifactId>
    <version>0.2.1</version>
</dependency>

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <type>jar</type>
    <version>1.1.0.Final</version>
</dependency>
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
</dependency>
<dependency>
    <groupId>org.threeten</groupId>
    <artifactId>threetenbp</artifactId>
    <version>1.4.1</version>
</dependency>
<dependency>
    <groupId>io.gsonfire</groupId>
    <artifactId>gson-fire</artifactId>
    <version>1.7.1</version>
</dependency>
</dependencies>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题