I am having trouble generating the client code with the right type mapping. My client is broken because fields of type date are generated as string :
//Server code (Java)
@ApiModel(description = "ContractExtensionDto")
@Data
@NoArgsConstructor
public class ContractExtensionDto {
@NotNull
protected Integer id;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = PatternConfig.DATE_TIME_FORMAT)
protected Date dateStart;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = PatternConfig.DATE_TIME_FORMAT)
protected Date dateEnd;
//omitted code
}
//Generated client code (Typescript)
export interface ContractExtensionDto {
id: number;
dateStart?: string;
dateEnd?: string;
//omitted code
}
In my pom.xml I have added both typeMappings and importMappings :
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.directory}/classes/swagger/swagger.json</inputSpec>
<generatorName>typescript-angular</generatorName>
<output>frontend/src/app/services/rest-api</output>
<skipValidateSpec>true</skipValidateSpec>
<configOptions>
<ngVersion>10.2.5</ngVersion>
<dateLibrary>java8</dateLibrary>
</configOptions>
<typeMappings>Date=Date</typeMappings>
<importMappings>Date=Date</importMappings>
<!-- I have tried this as well but in vain -->
<!--
<typeMappings>DateTime=Date</typeMappings>
<importMappings>DateTime=Date</importMappings>
-->
</configuration>
</execution>
</executions>
</plugin>
but still the client date fields are generated as string typed.
Define
typeMappingsas below, instead:This worked with
typescript-angulargenerator, at least.