如何使用 Swagger Codegen 生成具有数据类型为 Currency(java.util) 的变量的模型

How to generate models that have a variable whose data type is Currency(java.util) with Swagger Codegen

有没有办法使用 Swagger Codegen 生成具有数据类型为 Currency(java.util) 的变量的模型?

注意:我使用的是 Swagger 2.0 版和 Swagger Codegen 2.2.3 版

您可以在规范中定义一个 Currency 对象,然后使用 --import-mappings 避免为其创建模型。

(部分)规范:

definitions:
  Bill:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      category:
        $ref: "#/definitions/Currency"
  Currency:
    type: "object"

命令:

java -jar swagger-codegen-cli.jar generate -l java -i MySpec.yaml --import-mappings Currency=java.util.Currency

或者,如果您使用的是 Maven,请将其添加到 pom.xml:

<configOptions> 
  <import-mappings>Currency=java.util.Currency</import-mapping‌​s>
</configOptions>