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

1.5k Views Asked by At

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

Note: I use Swagger Version 2.0 and Swagger Codegen Version 2.2.3

1

There are 1 best solutions below

1
On BEST ANSWER

You can define a Currency object in your spec and then use --import-mappings to avoid creating a model for it.

The (partial) spec:

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

The command:

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

Or if you are using Maven, add this to the pom.xml:

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