Question

Generating Clients/SDKs Using Swagger Codegen

  • 18 November 2015
  • 44 replies
  • 1450 views

  • Anonymous
  • 0 replies

The Looker API v3.0 has a custom authentication scheme which requires a SHA-1 hash of the query parameters. Does the generated code know how to do this or I need to modify the generated code.


44 replies

Hello there!


I’m having a similar problem to @scottmdavidson. But, my base_url is already correct syntax. I’m getting an ApiException: (400) error. It only happens when using functions whose method in the response variable is ‘POST’ (create_user, create_user_access_filter). I am able to run anything else that I’ve tried (all_users, all_user_access_filters).


What I mean by response variable whose method is post:



    response = self.api_client.call_api(resource_path, 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='User',
auth_settings=auth_settings,
callback=params.get('callback'))


Any thoughts? Thanks!

Solved - disregard 🙂

Userlevel 3
Badge

👍

I am not able to get the GIT.


git clone git@github.com:swagger-api/swagger-codegen.git


It prompts me an error


Cloning into ‘swagger-codegen’…

ssh: connect to host github.com port 22: Connection refused

fatal: Could not read from remote repository.


Please make sure you have the correct access rights

Hey @svarun ,


It sounds like you might have a firewall between your ssh host and github that is blocking traffic on port 22. Try from a location outside of your internal network.


Cheers,

William

William_Lane thanks for the update. This make sense. I shall try via different channel and come back.

But do we have any other way to manually get this configured ?

@svarun


You could indeed use the github site and hit “Clone or Download”:




I hope this helps!


@scott.hoover


How and from where do I get the swagger.json file and place the similar as below ?


/Users/scott/Desktop/looker_python_client/swagger.json


I am stuck with this file from few days. Can you help me out?


Cheers

VS

William - thanks for your input this was informative but it didn’t help me completely.


Appreciated. This is going to help me in future thou 🙂

Finally I was able to make till end. Thanks to all support.

Now I am stuck with testing my Looker_Connect.py


when I run the .py code I am getting error as below Help!!!


Traceback (most recent call last):

File “/Users/sv/LookerPython/LKCONNECT2.py”, line 15, in

token = unauthenticated_authApi.login(client_id=client_id, client_secret=client_secret)

File “/Users/sv/LookerPython/swagger_client/apis/api_auth_api.py”, line 122, in login

callback=params.get(‘callback’))

File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 322, in call_api

response_type, auth_settings, callback)

File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 149, in __call_api

post_params=post_params, body=body)

File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 358, in request

body=body)

File “/Users/sv/LookerPython/swagger_client/rest.py”, line 208, in POST

body=body)

File “/Users/sv/LookerPython/swagger_client/rest.py”, line 177, in request

raise ApiException(http_resp=r)

ApiException: (404)

Reason: Not Found

HTTP response headers: HTTPHeaderDict({‘Vary’: ‘Accept-Encoding’, ‘Content-Length’: ‘69’, ‘Content-Type’: ‘application/json;charset=utf-8’, ‘X-Content-Type-Options’: ‘nosniff’})

HTTP response body: {“message”:“Not found”,“documentation_url”:“http://docs.looker.com/”}

Hello @scott.hoover -

I am stuck with the python script here. when I run the client side I get below error


Traceback (most recent call last):

File “/Users/sv/LookerPython/LKCONNECT2.py”, line 15, in

token = unauthenticated_authApi.login(client_id=client_id, client_secret=client_secret)

File “/Users/sv/LookerPython/swagger_client/apis/api_auth_api.py”, line 122, in login

callback=params.get(‘callback’))

File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 322, in call_api

response_type, auth_settings, callback)

File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 149, in __call_api

post_params=post_params, body=body)

File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 358, in request

body=body)

File “/Users/sv/LookerPython/swagger_client/rest.py”, line 208, in POST

body=body)

File “/Users/sv/LookerPython/swagger_client/rest.py”, line 177, in request

raise ApiException(http_resp=r)

ApiException: (404)

Reason: Not Found

HTTP response headers: HTTPHeaderDict({‘Vary’: ‘Accept-Encoding’, ‘Content-Length’: ‘69’, ‘Content-Type’: ‘application/json;charset=utf-8’, ‘X-Content-Type-Options’: ‘nosniff’})

HTTP response body: {“message”:“Not found”,“documentation_url”:“http://docs.looker.com/”}

Userlevel 2

Take a look at Step 2 under the “Setup” section.


https://<your_looker_endpoint>:19999/api/3.0/swagger.json


You can retrieve the JSON from the above-mentioned endpoint.

@scott.hoover

I am getting 404 error similar well not similar its same as mentioned by @Grayson_Williams. I am not sure how this was solved I am not able to follow the post comment on this clear. Could you please guide me on this?


raise ApiException(http_resp=r)

ApiException: (404)

Reason: Not Found

HTTP response headers: HTTPHeaderDict({‘Vary’: ‘Accept-Encoding’, ‘Content-Length’: ‘69’, ‘Content-Type’: ‘application/json;charset=utf-8’, ‘X-Content-Type-Options’: ‘nosniff’})

HTTP response body: {“message”:“Not found”,“documentation_url”:“http://docs.looker.com/”}

Userlevel 4
Badge

@svarun, what is this related to exactly? What Scott linked to is the needed swagger json file for generating the sdk. As mentioned in the article, you can to this with curl or wget: curl -0 https://master.dev.looker.com:19999/api/3.0/swagger.json > swagger.json.


The response you pasted in here seems to be related to something else. You’re getting a 404, which means the resource you’re looking for is simply not there. Please reach out via help.looker.com or pop on chat so we can have a look at your code.

Scott input was valuable and I was able to get swagger.json not I have moved to next level where I am writing the API script to connect looker via python. I was getting the error. The error is very much similar in early post. But I didn’t see any solution on that but people have overcome this.


to answer second question I even ran the curl via terminal and I get similar error which read as


HTTP/1.1 401 Unauthorized

Content-Type: application/json;charset=utf-8

Vary: Accept-Encoding

X-Content-Type-Options: nosniff

Content-Length: 84

Could you come on chat and we’ll work on this issue with you @svarun? Either that or you can pop us a mail at help.looker.com

Chat would be better. Where can we get connected in chat. ?

Right here while logged in to your instance as long as you are at least a Developer:


Userlevel 2

I am trying to generate a client using swagger-codegen in aspnetcore. When I generate the client everything gets generated but all the code in the controllers is filled with TODO comments rather than the actual code for the method:


Example:


public virtual IActionResult Login([FromQuery]string clientId, [FromQuery]string clientSecret)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(AccessToken));

//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400, default(Error));

//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(Error));

string exampleJson = null;
exampleJson = "{\n \"access_token\" : \"access_token\",\n \"token_type\" : \"token_type\",\n \"expires_in\" : 0\n}";

var example = exampleJson != null
? JsonConvert.DeserializeObject<AccessToken>(exampleJson)
: default(AccessToken);
//TODO: Change the data returned
return new ObjectResult(example);
}

However, when I generate the client using .net starndard, everything gets generated fine and I can consume the API endpoints as documented.


Here is the command I’m running:


swagger-codegen generate -i swagger.json -l aspnetcore -o LookerAPI


Does the swagger file provided by looker (API 3.0) support dotnet core? Seems like it might not be completed yet…

Reply