swagger-api / swagger-api/swagger-codegen
Swift4 -- some msg classes being encoded with Optional(value)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Our GCP Endpoints V2 API was failing with 400 errors before ever reaching our server code. I used Postman to validate the API was working properly. I then moved to the client and began debugging the generated Swagger lib ... specifically
let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: body)
and discovered that the value in key "jsonData" (when decoded), looked like this:
{ "FieldName": "Optional(2)"}
which of course is not valid JSON.
Swagger-codegen version
Latest Swift4 as of 8/1/2018
Command line used for generation
java -jar /Users/dgaedcke/dev/swagger-codegen/swagger-codegen-cli.jar generate -c apigen_config.json -l swift4 -i /Users/dgaedcke/dev/tsSwagger/tstone1_0_1openapi.json -o /Users/dgaedcke/Downloads/TsApiBackend
Steps to reproduce
I'm working on a simple case & will post it later
Suggest a fix/enhancement
my 1st thought was that the Swift compiler was not auto-synthesizing "Codable" for some of the generated Msg Structs and thus it was using the "backup" version of this method:
open class func encodingParameters<T:Encodable>(forEncodableObject encodableObj: T?)
but reviewing the generated code, I see that all ARE marked Codable so that's clearly not the cause. I'm still investigating.
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
Start at JSONEncodingHelper.encodingParameters(forEncodableObject:) and compare the generic Encodable path with the backup overload used by the generated Swift4 message structs. Reproduce the reported GCP Endpoints request once a minimal case is available; done means encoded JSON contains values such as 2 rather than strings like "Optional(2)".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100