I am having trouble sending parameter via swagger-ui into my spring io microservice. When I insert all parameters into swagger-ui I am getting this error: Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/octet-stream' is not supported].
This is my controller method:
@Operation(summary = "Generate a pdf and sign it.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Pdf is successfully generated and signed."),
@ApiResponse(responseCode = "404", description = "Something went wrong while generating or signing the pdf."),
@ApiResponse(responseCode = "4215", description = "Something went wrong while generating or signing the pdf.")
})
@PostMapping(path = "/list/sequenceId/{sequenceId}",
consumes = {MULTIPART_FORM_DATA_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
public void generateAndSignList(@PathVariable(name = "sequenceId") Integer sequenceId,
@RequestPart(value="sign", required = false)
boolean sign,
@RequestPart String pathToTemplate,
@io.swagger.v3.oas.annotations.parameters.RequestBody(
content = @Content(mediaType = MULTIPART_FORM_DATA_VALUE,
schema = @Schema(name = "itemWrapper",
ref = "#/components/schemas/Map")))
@RequestPart ItemWrapper itemWrapper)
throws SftpException {
List<Item> list = itemWrapper.getList();
double totalSum = itemWrapper.getTotalSum();
Session session = this.sftpUpload.getSession();
ChannelSftp channel = this.sftpUpload.getChannel(session);
Integer number = this.sftpUpload.numberOfPdfs(channel, sequenceId, ".pdf") + 1;
Generated generatedPdf = pdfGenerator.generateListFromHtml(pathToTemplate, list, totalSum,
number.toString());
if(sign) {
byte[] signedPdf = this.signingService.signPdf(generatedPdf.getPdfContent());
generatedPdf.setPdfContent(signedPdf);
}
//this.sftpUpload.uploadPdf(channel, generatedPdf.getPdfContent(), sequenceId, generatedPdf.getFileName());
//this.sftpUpload.disconnectChannelAndSession(channel, session);
}
These are my dependencies in pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-models</artifactId>
<version>2.2.20</version>
</dependency>
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-v3</artifactId>
<version>2.1.20</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.22</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.64</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.64</version>
</dependency>
<dependency> <!--SWAGGER-UI-->
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0-M1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency> <!-- SFTP -->
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.16</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This is my OpenApi @Bean:
@Bean
public OpenAPI api() {
return new OpenAPI()
.components(new Components()
.addSchemas("Map", new Schema<Map<String, Object>>()
.addProperties("< * >", new ObjectSchema())
))
.info(apiInfo());
}
private io.swagger.v3.oas.models.info.Info apiInfo() {
return new io.swagger.v3.oas.models.info.Info()
.title("Pdf generator, signer and uploader API")
.description("Micro-service generates, signs and uploads pdfs to sftp.")
.version("1.0")
.contact(new io.swagger.v3.oas.models.info.Contact()
.email("[email protected]")
.name("name")
.url("https://www.url.com"));
}
and I am adding a print-screen from my swagger-ui: print-screen from my swagger-ui
I tried using various @Schema and @Component annotations. I would like my code to work.