swagger-api / swagger-api/swagger-codegen

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

Open
#8,874 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with api.yaml and config.json, then run the supplied bash generation script with the Java resttemplate library and inspect the generated output with the stated grep command. Trace the Java generator's handling of an integer query parameter with format int64; done means every generated unixTimestamp signature uses Long rather than Integer, with regression coverage if the project provides a matching generator test entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, yaml
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.