Skip to content

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

Open
@javakrieg

Description

@javakrieg
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions