Search code examples
swaggerswagger-2.0swagger-codegen

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


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


Solution

  • 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>