swagger-api / swagger-api/swagger-codegen
[CPPREST] [C++] Required string fields are not handled properly in the cpprest generator
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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