Hi team!
Using the OpenApi maven plugin, I've noticed that the Date types are properly inferrred but not imported in the generated rest client interface.
I'm using plugin version 6.0.5 and java 21 with the following configuration:
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>6.0.5</version>
<executions>
<execution>
<id>openapi</id>
<phase>generate-sources</phase>
<goals>
<goal>openapi-generation</goal>
</goals>
<configuration>
<specFiles>
<specFile>
<filePath>${project.basedir}/src/main/resources/api/TestService.yml</filePath>
<apiPackage>org.test.service.infrastructure.rest.api</apiPackage>
<modelPackage>org.test.service.infrastructure.rest.api.model</modelPackage>
<modelNameSuffix>DTO</modelNameSuffix>
</specFile>
</specFiles>
<springBootVersion>3</springBootVersion>
</configuration>
</execution>
</executions>
</plugin>
Below is the OpenAPI specification file, where we've defined both a path variable and a query parameter as date-time string:
openapi: 3.0.1
info:
title: A simple Open API definition
version: '1.0'
servers:
- url: 'http://localhost:8080'
description: Generated server url
paths:
'/test/{pathVariableDate}':
get:
tags:
- simple-service
summary: A simple service
description: A simple service description
operationId: simpleServiceId
parameters:
- name: pathVariableDate
in: path
required: true
schema:
type: string
format: date-time
- name: QueryParamDate
in: query
required: true
schema:
type: string
format: date-time
responses:
'200':
description: The OK response
When the compile phase is executed in maven, an error occurs due to a missing symbol. As seen below, the java.time package has not been imported in the generated interface:
package org.test.service.infrastructure.rest.api;
import java.util.Optional;
import java.util.List;
import java.util.Map;
import jakarta.validation.Valid;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.http.MediaType;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.NativeWebRequest;
public interface TestApi {
/**
* GET /test/{pathVariableDate}: A simple service
* @param pathVariableDate true @param QueryParamDate true
* @return The OK response; (status code 200)
*/
@Operation(
operationId = "simpleServiceId",
summary = "A simple service",
tags = {"simple-service"},
responses = {
@ApiResponse(responseCode = "200", description = "The OK response")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/test/{pathVariableDate}",
produces = {"application/json"}
)
default ResponseEntity<Void> simpleServiceId(@Parameter(name = "pathVariableDate", required = true, schema = @Schema(description = "")) @PathVariable("pathVariableDate") LocalDateTime pathVariableDate , @Parameter(name = "QueryParamDate", required = true, schema = @Schema(description = "")) @RequestParam(required = true) LocalDateTime QueryParamDate) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
Best Regards.
Hi team!
Using the OpenApi maven plugin, I've noticed that the
Datetypes are properly inferrred but not imported in the generated rest client interface.I'm using plugin version
6.0.5andjava 21with the following configuration:Below is the
OpenAPIspecification file, where we've defined both a path variable and a query parameter asdate-timestring:When the
compilephase is executed in maven, an error occurs due to a missing symbol. As seen below, thejava.timepackage has not been imported in the generated interface:Best Regards.