我正在大张旗鼓地产生pojos。招摇是由第三方提供的,不能更改。我希望将“ double”字段生成为“ BigDecimal”。如何自定义代码生成器以实现此目标?
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<id>generateSquiree</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/schema/sample.swagger.json</inputSpec>
<configOptions>
<modelPackage>${basepackage}.model</modelPackage>
<apiPackage>${basepackage}.api</apiPackage>
</configOptions>
</configuration>
</execution>
</executions>
<configuration>
<language>spring</language>
<configOptions>
<serializableModel>true</serializableModel>
<java8>false</java8>
<javaVersion>${java.version}</javaVersion>
<jdk8>true</jdk8>
<dateLibrary>joda</dateLibrary>
<useTags>true</useTags>
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</plugin>
下面是招摇的片段,需要将其生成为 “ BigDecimal”
"Quantity": {
"description": "Represent a quantity",
"required": [
"Amount"
],
"type": "object",
"properties": {
"Amount": {
"format": "double",
"description": "Amount",
"type": "number"
}
}
},
答案 0 :(得分:1)
在以下位置找到了我的问题的答案
https://github.com/swagger-api/swagger-codegen/issues/5587#issuecomment-368805748
如果有人有相同的问题,请在下面发布解决方案
<configuration>
....
<typeMappings>
<typeMapping>Double=java.math.BigDecimal</typeMapping>
</typeMappings>
</configuration>