You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to generate a CLI for the swagger.json for our application. Commands that work in the GUI are not being properly handled by the CLI.
I'm getting error messages like Error: json: cannot unmarshal object into Go value of type string for many CLI commands that return a list in a JSON format. For example:
keith@Keiths-MBP startree-platform % startree table listTables --debug
2023/03/19 16:09:28 Using config file: /Users/keith/.config/startree/config.yaml
2023/03/19 16:09:28 Server url: https://xxxxxxxxxxxxxxx
GET /tables HTTP/1.1
Host: xxxxxxxxxxxxxxx
User-Agent: Go-http-client/1.1
Accept: application/json
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxx=
Accept-Encoding: gzip
HTTP/1.1 200 OK
Content-Length: 145
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE
Access-Control-Allow-Origin: *
Content-Type: application/json
Pinot-Controller-Host: pinot-pinot-controller-0.pinot-pinot-controller-headless.managed.svc.cluster.local
Pinot-Controller-Version: Unknown
{"tables":["NYCTaxiData","NYCTaxiDataDim","promo_codes","rides","rides_test","user_promo_codes","users","vehicle_location_histories","vehicles"]}
Error: json: cannot unmarshal object into Go value of type string
I have run the same query from the Swagger GUI and it parses the response properly:
Can you write a go program using the generated client code without the cli?
I suspect the problem is in the generated client code. Unmarshal is done in the client code.
The API contract for the GET /tables operation specifies a return type: "string"
It looks that your server returns an object {tables: ["...", ...]}
So basically the server doesn't abide by this contract. Strongly typed clients such as the go-swagger client will fail to unmarshal. This is unlike the swagger UI js code, which does not validate the response.
This particular response is not described anywhere in the provided spec.
So not saying the generated CLI is perfect... But it builds and does the job of trying to unmarshal this json object into a string and fail.
Problem statement
I am attempting to generate a CLI for the swagger.json for our application. Commands that work in the GUI are not being properly handled by the CLI.
I'm getting error messages like
Error: json: cannot unmarshal object into Go value of type string
for many CLI commands that return a list in a JSON format. For example:I have run the same query from the Swagger GUI and it parses the response properly:
Swagger specification
swagger.json.zip
full source is available here: https://github.com/keith-mcclellan/startree-cli
Steps to reproduce
Environment
swagger version: v0.30.4
go version go1.20.2 darwin/arm64
OS:
MacOS
The text was updated successfully, but these errors were encountered: