swagger-api / swagger-api/swagger-codegen

[cpprest] JSON format:byte incorrectly converted to ByteArray

Open
#7,875 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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: https://github.com/swagger-api/swagger-codegen/issues/4824
Similar issue for C#: https://github.com/swagger-api/swagger-codegen/issues/3554

Suggest a fix/enhancement

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

Reproduce the issue with the shown swagger-codegen-cli command and the cpprest generator, then trace how a string with format byte becomes the generated ByteArray.h include and accessors. Done means the generated C++ uses string instead of the unknown ByteArray type and compiles successfully.

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.