swagger-api / swagger-api/swagger-codegen

[SymfonyServerCodegen] Bug: ignore default integer value for models

Open
#8,369 1 comment 0 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

Default value of integer property in model ignored and used null.
But for string property all ok.

Swagger-codegen version

java -jar swagger-codegen-cli.jar version
2.3.1

Swagger declaration file content or url

https://gist.github.com/4n70w4/fd58b3273461c57e5289e3fb587be71e

      test:
        type: integer
        default: 0
      test2:
        type: string
        default: 0
Command line used for generation

java -jar swagger-codegen-cli.jar generate --input-spec test.yml --lang io.swagger.codegen.languages.SymfonyServerCodegen --output app/demo

Steps to reproduce

see demo/SymfonyBundle-php/Model/ApiResponse.php

    public function __construct(array $data = null)
    {
        $this->test = isset($data['test']) ? $data['test'] : null;
        $this->test2 = isset($data['test2']) ? $data['test2'] : '0';
    }

Why for type: integer; default: 0 generated $data['test'] : null; ?

Related issues/PRs

N/A

Suggest a fix/enhancement

N/A

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

Reproduce the generation command with the supplied Swagger declaration and inspect demo/SymfonyBundle-php/Model/ApiResponse.php, especially the constructor defaults for test and test2. Trace the SymfonyServerCodegen model template or generator logic that emits these assignments; done means an integer default of 0 is preserved like the string default.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php, symfony
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.