swagger-api / swagger-api/swagger-codegen

[CPPREST] default values unused

Open
#8,960 2 comments 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 values are unused in the generated classes constructors.

Swagger-codegen version

2.3.1

Swagger declaration file content
definitions:
  MyData:
    required:
      - name
      - status
    properties:
      name:
        type: string
        default: 'unset'
      status:
        type: boolean
        default: true

will generate this code :

MyData:: MyData()
{
    m_ name = utility::conversions::to_string_t("");
    m_ status = false;
}

while I would like it to be:

MyData:: MyData()
{
    m_ name = utility::conversions::to_string_t("unset");
    m_ status = true;
}
Suggest a fix/enhancement

I've got a fix that I'll submit as a PR to this issue

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 the CPPREST generator path that creates the generated MyData constructor and compare it with the YAML default fields shown in the issue. Regenerate the example and confirm that the string default becomes "unset" and the boolean default becomes true in the constructor output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.