swagger-ui with cloud endpoints.

3,615 views
Skip to first unread message

molte...@gmail.com

unread,
May 12, 2017, 8:12:19 AM5/12/17
to Google Cloud Endpoints
Hi All,

I was trying to enable the swagger-ui interface for my endpoints. I can't find a way to enable them. I think there is a problem when the application is deployed behind an ESP.

I just downloaded the sample nodejs code to test. https://github.com/GoogleCloudPlatform/nodejs-docs-samples 

I'm using the sample endpoints application in nodejs-docs-samples\endpoints\getting-started

1) in the openapi.yaml i've update the host and adde this code to the path sectio


"/docs":
get:
summary: "Documentation"
operationId: "Docs"
produces:
- "application/json"
responses:
200:
description: " Documentation"

2) I've install the swagger-ui packages:

    npm install swagger-tools --save
    npm install swagger-ui --save
    npm install yamljs --save

3) i've added the swagger-ui middleware in my code (app.js) as explain here https://cloud.google.com/endpoints/docs/adding-swagger

var swaggerTools = require('swagger-tools');
var YAML = require('yamljs');
var swaggerDoc = YAML.load('openapi.yaml');

swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());
});
 
4) I've deployed the esp, updated the app.yaml file and deployed the application

Unfortunately it doesn't doesn't work (i've this result):


I tried to deploy the application without the ESP (changing only the host in the openapi.yaml) and it works!.... so I understand that the problem is with the Host url defined in the openapi.yaml.

I've tried to change the swaggerDoc.host field directly in the app.js source code to let it point to the right host. it doesn't work
i tried to create an openapi-appengine.yaml that is identical to the openapi.yaml changing only the host and use the openapi-appeninge.yaml file as input for my swaggerDoc in the app.js code. It doesn't work

I really don't know what to do :'(

any help will be really appreciate
Thanks :)
Diego 

John Daughtry

unread,
May 12, 2017, 1:50:39 PM5/12/17
to molte...@gmail.com, Google Cloud Endpoints
Hey Diego,

If you are running on GAE flex then the host field should be an appspot.com address and not endpoints.[project].cloud.goog.
Some more details on that distinction are found in the comments of the sample openapi.yaml file and in the Node quickstart guide.

Hope that helps,

John


--
You received this message because you are subscribed to the Google Groups "Google Cloud Endpoints" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endpoints+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-endpoints/76481af0-142e-4af0-81d6-3c45361d1496%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted

molte...@gmail.com

unread,
May 13, 2017, 6:27:29 AM5/13/17
to Google Cloud Endpoints, molte...@gmail.com
Hi John,

I've updated the code following your suggestion but it doesn't work.
still the same problem.

Diego

John Daughtry

unread,
May 15, 2017, 3:08:29 PM5/15/17
to Diego Molteni, Google Cloud Endpoints
Hi Diego,

It had been a while since I did this myself, so I went through it to try to replicate your problem. I wasn't able to replicate it, so I thought I'd write to tell you what I did. Maybe we can find where you and I are diverging in our process.

 1. Created project named swagger-test
 2. opened cloudshell (I'm doing everything in cloudshell)
 3. downloaded the NodeJS sample on Flex
 4. set host to be swagger-test.appspot.com in openapi.yaml
 5. gcloud service-management deploy openapi.yaml
 6. Got my config id.
 7. opened app.yaml, and entered servicename and config ID
 8. gcloud app deploy
 9. created an API key
 10. Curled my API, and verified it worked.

Now that I have a working NodeJS sample, I can continue with the swaggerUI steps at: https://cloud.google.com/endpoints/docs/adding-swagger
 11. Added specified things to app.js
 12. Added swagger-tools and yamljs to package.json dependencies list (they are already in the modules directory)
 13. added x-google-allow: all to openapi.yaml (so ESP will allow /doc call to go through... since I'm putting everything in one deployed GAE instance)
 14. redeployed this updated openapi config and got a new config ID
 15. updated config ID in the app.yaml so ESP will start up with the new config
 16. redeployed
 17. Tried again and swaggerUI is working.

John



To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endpoints+unsubscri...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud Endpoints" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endpoints+unsubscri...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-endpoints/e98d5fab-97e1-4968-963a-27010dacaf6a%40googlegroups.com.

molte...@gmail.com

unread,
May 16, 2017, 3:09:29 AM5/16/17
to Google Cloud Endpoints, molte...@gmail.com
Hey john,

Thanks for the exhaustive explanation. It's exactly what i did the only different was that i didn't add => x-google-allow: all in the openapi.yaml spec. Now works :) .
Previously I've explicitly defined the path for the /docs in the openapi.yaml in this way

"/docs":
get:
summary: "Documentation"
operationId: "docs"
produces:
- "application/json"
responses:
200:
description: "Documentation"

I will figure out this.
Thanks for the suggestion.
really appreciate it :)

Diego

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endpoints+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud Endpoints" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endpoints+unsub...@googlegroups.com.

Kevin Krefting

unread,
Oct 28, 2017, 5:51:14 PM10/28/17
to Google Cloud Endpoints
Hi Diego, did you happen to figure out how do enable swagger ui at the /docs endpoint without using x-google-allow?
Reply all
Reply to author
Forward
0 new messages