簡體   English   中英

如何從swagger生成java代碼時將“double”字段視為“BigDecimal”?

[英]How to treat a “double” field as “BigDecimal” while generating java code from a swagger?

我正在大搖大擺地發出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>

下面是swagger的片段,需要生成為“BigDecimal”

    "Quantity": {
      "description": "Represent a quantity",
      "required": [
        "Amount"
      ],
      "type": "object",
      "properties": {
        "Amount": {
          "format": "double",
          "description": "Amount",
          "type": "number"
        }
      }
    },

找到我的問題的答案

https://github.com/swagger-api/swagger-codegen/issues/5587#issuecomment-368805748

如果有人有同樣的問題,請在下面發布解決方案

        <configuration>
            ....
            <typeMappings>
                <typeMapping>Double=java.math.BigDecimal</typeMapping>
            </typeMappings>
        </configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM