Skip to content

[cpprest] JSON format:byte incorrectly converted to ByteArray #7875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
skydoctor opened this issue Mar 20, 2018 · 2 comments · May be fixed by #9427
Open

[cpprest] JSON format:byte incorrectly converted to ByteArray #7875

skydoctor opened this issue Mar 20, 2018 · 2 comments · May be fixed by #9427

Comments

@skydoctor
Copy link

Description

JSON element with {"type": "string", "format": "byte"} is being translated to unknown type 'ByteArray'. The ByteArray.h file being included as a result fails compilation. It appears like similar problems were fixed for Java, C#, and potentially other libraries.

Swagger-codegen version

2.3.1

Swagger declaration file content or url
"key": {
          "description": "key is the key in bytes. An empty key is not allowed.",
          "type": "string",
          "format": "byte"
        },
Command line used for generation

java -jar swagger-codegen-cli.jar generate -l cpprest -i example.yaml -o example/src/

Steps to reproduce

The swagger JSON snippet above results in the following generated C++ snippet:

...
#include "ByteArray.h"
...

/// key is the key in bytes. An empty key is not allowed.
ByteArray getKey() const;
bool keyIsSet() const;
void unsetKey();
void setKey(ByteArray value);

This should probably be just string

Related issues/PRs

Similar issue for Java: #4824
Similar issue for C#: #3554

Suggest a fix/enhancement
@jbelloncastro
Copy link

jbelloncastro commented May 2, 2018

You can fix this by adding the following line to CppRestClientCodegen.java:139
typeMapping.put("ByteArray", "std::string");

IMHO these lines should belong to AbstractCppCodegen, since they are duplicated in all C++ server and client implementations.

@skydoctor
Copy link
Author

Thanks! Would you want to submit a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants