OpenAPITools / OpenAPITools/openapi-generator
[BUG][SWIFT5] Boolean arguments in GET request get JsonEncoded
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
If a request builder builds a GET URL with query parameters, these parameters get JSON Encoded. This also happens with Boolean values. For example, if I have a property called includeRead=false, it's not added to the URL as ?includeRead=false, but as ?includeRead=ZmFsc2U%3D. This of course makes no sense to the middleware.
openapi-generator version
openapi-generator-cli 5.4.0
commit : 4a36be7
built : 2022-01-31T05:31:36Z
OpenAPI declaration file content or url
{
"swagger" : "2.0",
"info" : {
"description" : "Example",
"version" : "v1",
"title" : "Example",
"termsOfService" : "None"
},
"host" : "example.com",
"basePath" : "/Foo",
"schemes" : [ "https" ],
"produces" : [ "application/json" ],
"paths" : {
"/api/{country}/v1/messages" : {
"get" : {
"tags" : [ "Messages" ],
"operationId" : "Messages_GetMessages",
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "includeRead",
"in" : "query",
"required" : false,
"type" : "boolean",
"default" : false
}, {
"name" : "country",
"in" : "path",
"required" : true,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "OK",
"schema" : {
"$ref" : "#/definitions/GetMessagesOutput"
}
}
}
}
}
},
"definitions" : {
"Message" : {
"type" : "object",
"required" : [ "isRead" ],
"properties" : {
"body" : {
"type" : "string"
},
"from" : {
"type" : "string"
},
"isRead" : {
"type" : "boolean"
},
"messageId" : {
"type" : "string"
},
"sentTimestamp" : {
"type" : "string"
},
"subject" : {
"type" : "string"
},
"userId" : {
"type" : "string"
}
}
},
"GetMessagesOutput" : {
"type" : "object",
"properties" : {
"messages" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Message"
}
}
}
}
}
}
Generation Details
Run the most basic generate command:
$ openapi-generator generate -i ./test.json -g swift5
If you now look at OpenAPIClient/Classes/OpenAPIs/APIs/MessagesAPI.swift you'll see:
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"includeRead": includeRead?.encodeToJSON(),
])
This line creates a JSON string representation of the boolean value.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the basic openapi-generator command with the supplied specification and inspect OpenAPIClient/Classes/OpenAPIs/APIs/MessagesAPI.swift, especially the queryItems construction for includeRead. Trace how the Swift5 client serializes boolean query parameters; done means a generated GET URL represents false as includeRead=false rather than a JSON-encoded value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100