Search code examples
swagger-uiopenapispringfoxopenapi-generatorapi-doc

OpenAPI generator: wrong format for the example value of date datatype. Is it possible to customize?


I am using openapi-generator of the latest version (4.2.2) for generation of Java Spring API. Configuration looks like this:

openApiGenerate {
    generatorName = "spring"
    inputSpec = "${projectDir}/src/main/resources/api/users-spec.yaml"
    outputDir = "${buildDir}/generated/open-api"
    apiPackage = "com.example.accounts.api"
    invokerPackage = "com.example.accounts.handler"
    modelPackage = "com.example.accounts.model"
    modelNameSuffix = "Json"
    configOptions = [
            delegatePattern: "true"
    ]
}

I found out that definitions containing datatypes of date with example values produce differently formatted values in the output Java models.

definitions:
  User:
    properties:
      birthday:
        description: Date of birth
        type: string
        format: date
        example: "2020-01-01"

The generated model is:

  @ApiModelProperty(example = "Wed Jan 01 03:00:00 MSK 2020", value = "Date of birth")
  @Valid
  public LocalDate getBirthday() {
    return birthday;
  }

After the creation of swagger ui with springfox (2.9.2) I am having an example request as {"birthday": "Wed Jan 01 03:00:00 MSK 2020"}. It is confusing because a standard Jackson date deserializer cannot deserialize such value. Can I have an example value in yyyy-mm-dd format?


Solution

  • i found a solution here

    birthday:
        description: Date of birth
        type: date
        format: yyyy-mm-dd
        example: "2020-01-01"