OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.54k stars 6.27k forks source link

[BUG][RUST-SERVER] binary strings should not be base64 encoded #3189

Open lelongg opened 5 years ago

lelongg commented 5 years ago

The rust-server code generator handles binary and byte string format the same way. Both are base64 encoded automatically while binary strings should not perform this transformation as stated in OAS3.2.

Description

The formats defined by the OAS are:

type format Comments
string byte base64 encoded characters
string binary any sequence of octets
openapi-generator version

Tested with docker image openapitools/openapi-generator-cli with version 4.0.1-SNAPSHOT.

OpenAPI declaration file content or url
responses:
    "200":
      description: "OK"
      content:
        image/png:
          schema:
            type: string
            format: binary
Command line used for generation
docker run --rm -u $(id -u ${USER}):$(id -g ${USER}) -v ${PWD}:/local -w /local openapitools/openapi-generator-cli generate \
    --enable-post-process-file \
    --generate-alias-as-model \
    -i /local/openapi/openapi.yaml \
    -g rust-server \
    -o /local/packages/rust-server \
    -DpackageName=server
Related issues/PRs

Issue #538 mentions binary and byte string but doesn't mention how they should be handled differently.

Suggest a fix

Vec<u8> should be used for binary string instead ofswagger::ByteArray.

auto-labeler[bot] commented 5 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

wing328 commented 4 years ago

Vec should be used for binary string instead of swagger::ByteArray.

@lelongg that sounds reasonable. Can you please file a PR with the suggested fix?