Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated CLI is not supporting command that works properly in GUI #2915

Open
keith-mcclellan opened this issue Mar 19, 2023 · 2 comments
Open

Comments

@keith-mcclellan
Copy link

keith-mcclellan commented Mar 19, 2023

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:

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:

{
  "tables": [
    "NYCTaxiData",
    "NYCTaxiDataDim",
    "promo_codes",
    "rides",
    "rides_test",
    "user_promo_codes",
    "users",
    "vehicle_location_histories",
    "vehicles"
  ]
}

Screenshot 2023-03-19 at 4 14 00 PM

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

@youyuanwu
Copy link
Member

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.

@fredbi fredbi added the CLI label Dec 10, 2023
@fredbi fredbi added the needs testing Needs more testing for issue confirmation/qualification label Jan 5, 2024
@fredbi
Copy link
Contributor

fredbi commented Jan 5, 2024

@keith-mcclellan

  • 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.

@fredbi fredbi added question invalid swagger spec and removed needs testing Needs more testing for issue confirmation/qualification labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants