OpenAPITools / OpenAPITools/openapi-generator

[BUG][Swift] String / Byte array gets mapped to Data instead of String in Model

Open
#14,377 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I have a property in my Open API specifications that is defined as a byte array. In the Model that is generated for Swift this is mapped to a Data type instead of a String type.

And this wouldn't be too big of a deal, since I should be able in Swift to convert a Data object to a String, but for some reason if I do that the encoding gets all messed up. So this might even be a totally different issue. But what I do know, is that if I manually edit the Model and replace Data with String then everything works fine.

openapi-generator version
  • 6.2.1
OpenAPI declaration file content or url
{
  "swagger" : "2.0",
  "info" : {
    "description" : "Example",
    "version" : "v1",
    "title" : "Example",
    "termsOfService" : "None",
    "contact" : {
      "name" : "Foo",
      "url" : "https://www.example.com"
    }
  },
  "host" : "www.example.com",
  "basePath" : "/Example",
  "schemes" : [ "https" ],
  "produces" : [ "application/json" ],
  "paths" : {
    "/api/example" : {
      "get" : {
        "responses" : {
          "200" : {
            "description" : "OK",
            "schema" : {
              "$ref" : "#/definitions/ViewPinProvisionOutput"
            }
          }
        }
      }
    }
  },
  "definitions" : {
    "Example" : {
      "type" : "object",
      "properties" : {
        "signature" : {
          "type" : "string",
          "format" : "byte",
          "pattern" : "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
        }
      }
    }
  }
}
Generation Details

Just generate it the default way:

openapi-generator generate -i example.json -g swift5

Expected Result

The Example struct that is generated should have a property called signature of type String?

Actual Result

The Example struct that is generated has a property called signature of type Data?

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 supplied example.json and the openapi-generator generate -i example.json -g swift5 command. Start by tracing how the Swift generator maps a string with format: byte, then add regression coverage for the generated Example model. Done means the signature property is generated as String? without breaking related byte-string handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.