swagger-api / swagger-api/swagger-codegen

[CPPREST] [C++] Required string fields are not handled properly in the cpprest generator

Open
#6,055 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C++ Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

In ModelBase.cpp, the default code generated for stringFromJson() is:

utility::string_t ModelBase::stringFromJson(web::json::value& val)
{
return val.is_string() ? val.as_string() : U("");
}

As you can see, this supplies an empty string when no value is given.

However, this is a problem if the field is flagged as a required field. If a required string field is missing, instead of getting a 500 Internal error response, the field is given a default value of "" and processed onward.

Swagger-codegen version

Using the new online editor on 13-JUL-2017. 3.x maybe?

Swagger declaration file content or url
 ExampleContext:
    type: object
    required:
      - taskName
      - examName
    properties:
      taskName:
        type: string
      examName:
        type: string
Command line used for generation
Steps to reproduce
Related issues
Suggest a Fix

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 by locating the C++ generator template or entry point that produces ModelBase.cpp and inspect stringFromJson(). Reproduce the behavior with the provided YAML containing required taskName and examName fields. Done means a missing required string is not silently converted to an empty string and processed onward.

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.