Reputation: 85
I'm facing a problem with class generation by Swagger codegen plugnin. The plug in doesn't generate the correct date format for some fields in some model classes. LocalDate is translated into org.joda.time.LocalDate instead of java.time.LocalDate.
Here is my plugin configuration in my pom.xml:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<id>1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>http:aCertainHttpAdress</inputSpec>
<language>spring</language>
<modelPackage>${project.groupId}.model.myPackage</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<generateApis>false</generateApis>
<output>src/main/gen</output>
<configOptions>
<sourceFolder>/</sourceFolder>
</configOptions>
</configuration>
</execution>
I have tried already to add these two configurations:
<typeMappings>
<typeMapping>LocalDate=LocalDate</typeMapping>
</typeMappings>
<importMappings>
<importMapping>org.joda.time.LocalDate=java.time.LocalDate</importMapping>
</importMappings>
but with no success.
I've also added this one:
<dateLibrary>java8</dateLibrary>
same result...
Here is the generated model class with the wrong import:
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* VoceBilancioDto
*/
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2021-02-10T18:39:49.642+01:00")
public class VoceBilancioDto {
@JsonProperty("codeItem")
private String codeItem = null;
@JsonProperty("dateUpdateValue")
private LocalDate dateUpdateValue = null;
@JsonProperty("value")
private BigDecimal value = null;
public VoceBilancioDto codeItem(String codeItem) {
this.codeItem = codeItem;
return this;
}
/**
* Get codeItem
* @return codeItem
**/
@ApiModelProperty(value = "")
public String getCodeItem() {
return codeItem;
}
public void setCodeItem(String codeItem) {
this.codeItem = codeItem;
}
public VoceBilancioDto dateUpdateValue(LocalDate dateUpdateValue) {
this.dateUpdateValue = dateUpdateValue;
return this;
}
/**
* Get dateUpdateValue
* @return dateUpdateValue
**/
@ApiModelProperty(value = "")
@Valid
public LocalDate getDateUpdateValue() {
return dateUpdateValue;
}
public void setDateUpdateValue(LocalDate dateUpdateValue) {
this.dateUpdateValue = dateUpdateValue;
}
public VoceBilancioDto value(BigDecimal value) {
this.value = value;
return this;
}
/**
* Get value
* @return value
**/
@ApiModelProperty(value = "")
@Valid
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
VoceBilancioDto voceBilancioDto = (VoceBilancioDto) o;
return Objects.equals(this.codeItem, voceBilancioDto.codeItem) &&
Objects.equals(this.dateUpdateValue, voceBilancioDto.dateUpdateValue) &&
Objects.equals(this.value, voceBilancioDto.value);
}
@Override
public int hashCode() {
return Objects.hash(codeItem, dateUpdateValue, value);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class VoceBilancioDto {\n");
sb.append(" codeItem: ").append(toIndentedString(codeItem)).append("\n");
sb.append(" dateUpdateValue: ").append(toIndentedString(dateUpdateValue)).append("\n");
sb.append(" value: ").append(toIndentedString(value)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
anyone can help?
Many thanks
Upvotes: 1
Views: 11022
Reputation: 85
I soved the problem by using this version of the plugin:
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.18</version>
and by adding <dateLibrary>Java8<dateLibrary>
in the single configuration option for the single call to an api
Upvotes: 1
Reputation: 36113
You are using a very old version of swagger codegen.
Please use the newest v3 version:
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.24</version>
This will use java.time.LocalDate
Upvotes: 2