swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

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

Open javakrieg opened this issue 9 years ago • 2 comments

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

javakrieg avatar Jul 13 '17 21:07 javakrieg

v2.2.3 has been released with many enhancement to C++ (cpprest) generator. Please give that a try.

If it's still an issue, we'll reopen this.

wing328 avatar Jul 17 '17 06:07 wing328

This is still an issue. Please reopen.

javakrieg avatar Jul 31 '17 20:07 javakrieg