如何使用公共的swagger-generator docker镜像生成客户端? [英] How do I use the public swagger-generator docker image to generate a client?

查看:175
本文介绍了如何使用公共的swagger-generator docker镜像生成客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个完全使用docker化的Web应用程序,带有针对该API的有效Swagger定义。该API在其自己的Docker容器中运行,我们正在使用docker-compose来协调所有内容。我想基于位于 http:// api:8443 / apidocs.json 的Swagger定义生成Ruby客户端。

We have a fully dockerized web app with a valid Swagger definition for the API. The API runs in its own docker container, and we're using docker-compose to orchestrate everything. I want to generate a Ruby client based on the Swagger definition located at http://api:8443/apidocs.json.

我在此处中浏览了文档,这使我想到了Swagger的公共docker映像,用于生成客户端和服务器代码。遗憾的是,缺少文档,也没有提供使用docker镜像实际生成客户端的示例。

I've poured through the documentation here, which led me to Swagger's public docker image for generating client and server code. Sadly the documentation is lacking and offers no examples for actually generating a client with the docker image.

Dockerfile 表示其容器运行Web服务,我只能假定它是http://generator.swagger.io 。因此,我希望能够使用以下命令生成客户端:

The Dockerfile indicates its container runs a web service, which I can only assume is the dockerized version of http://generator.swagger.io. As such, I would expect to be able to generate a client with the following command:

curl -X POST -H content-type: application / json -d \
'{ swaggerUrl: http:// api:8443 / apidocs}'\
http:// swagger-generator:8080 / api / gen / clients / ruby​​

这里没有运气。即使我已经使用(npm -q install -g swagger-tools> / dev / null)&& swagger-tools验证http:// api:8443 / apidocs

No luck here. I keep getting "invalid swagger definition" even though I've confirmed the swagger definition is valid with (npm -q install -g swagger-tools >/dev/null) && swagger-tools validate http://api:8443/apidocs.

有任何想法吗?

推荐答案

实际上是正确的,您所指的docker映像与 http://generator.swagger.io

indeed you are correct, the docker image you're referring to is the same image used at http://generator.swagger.io

您遇到的问题是输入参数不正确。

The issue you're having is the input parameter isn't correct.

现在要正确处理,请注意,swagger-generator具有Web界面。因此,一旦按照说明进行启动,请在浏览器中将其打开。例如(用机器的IP地址替换GENERATOR_HOST):

Now to get it right, please note that the swagger-generator has a web interface. So once you start it up, like the instructions say, open it in a browser. For example (replace the GENERATOR_HOST with your machine's IP address):

docker run -d -e GENERATOR_HOST=http://192.168.99.100 -p 80:8080 swaggerapi/swagger-generator

然后您可以打开swagger-ui http://192.168.99.100

then you can open the swagger-ui on http://192.168.99.100

此处的重要部分是您可以使用UI来查看呼叫句法。如果要生成客户端,请转到 http://192.168.99.100/#!/clients/generateClient 选择要生成的语言,然后在对。将 swaggerUrl 字段替换为服务器和地址的地址。

The important part here is that you can use the UI to see the call syntax. If you're generating a client, go to http://192.168.99.100/#!/clients/generateClient select the language you want to generate and click the payload on the right. Replace the swaggerUrl field with the address of your server and voila.

您可以在curl中使用输出来找出如何从命令行调用。

You can use the output in the curl to figure out how to call from the command line. It should be easy from there.

请记住,仅仅因为第3方工具说招摇的定义是有效的,并不意味着它实际上是正确的。不过,我认为这不是您的问题,但是第三方工具的里程可能会有所不同...

Please keep in mind that just because a 3rd party tool says the swagger definition is valid doesn't mean it actually is. I don't think that's your issue, though, but 3rd party tool mileage may vary...

这篇关于如何使用公共的swagger-generator docker镜像生成客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆