swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.98k stars 6.03k forks source link

[JAVA] yaml int64 format query param translates to Integer type (regression) #8874

Open shoffmeister opened 5 years ago

shoffmeister commented 5 years ago
Description

yaml containing an int64 format query parameter of type integer gets the parameter translated to a Java Integer type. This should be a Java Long type.

Following the yaml below, currently generated code is public void getData(Integer unixTimestamp) which should be public void getData(Long unixTimestamp)

Swagger-codegen version

Regression in 3.0.2; worked correctly in 2.3.1

Swagger declaration file content or url
swagger: '2.0'
basePath: "/"
info:
  version: "1"
  title: "x"

schemes:
- https
consumes:
- application/json
produces:
- application/json
paths:
  /data:
    get:
      operationId: "getData"
      parameters:
      - $ref: '#/parameters/unixTimestampQuery'
      responses:
        '403':
          description: Forbidden
parameters:
  unixTimestampQuery:
    in: query
    name: unixTimestamp
    type: integer
    format: int64
Command line used for generation

See reproduction.

Steps to reproduce

config.json

{
  "excludeTests": true, 
  "generateApiTests": false, 
  "generateModelTests": false,

  "hideGenerationTimestamp": true,
  "dateLibrary": "java8",
  "java8": true,
  "library": "resttemplate",

  "modelPackage": "my.client.model",
  "apiPackage": "my.client.api",
  "invokerPackage": "my.client"
}

bash script:

#!/usr/bin/env bash

set -e

wget https://repo.maven.apache.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.2/swagger-codegen-cli-3.0.2.jar -O swagger-codegen-cli.jar

SILO_SWAGGER_FILE_LOCATION=./api.yaml

TARGET_DIRECTORY=./generated_by_swagger_codegen

rm -rf ${TARGET_DIRECTORY}

java -jar swagger-codegen-cli.jar generate -c config.json -l java \
 -i ${SILO_SWAGGER_FILE_LOCATION} \
 -o ${TARGET_DIRECTORY}

Verify: grep -rw unixTimestamp on the generated output.

This should indicate Long in all cases, instead of Integer

shoffmeister commented 5 years ago

I was able to try release 3.0.8 - and the fix made by @barney2k7 in https://github.com/swagger-api/swagger-parser/pull/1033 fixes this problem here.

Many thanks to @barney2k7 !