配置Swagger UI路径

huangapple go评论74阅读模式
英文:

Config Swagger-ui path

问题

我正在使用yml文件从以下上下文中配置swagger-ui路径,并使用quarkus

swagger-ui:
path: /clinic/swagger-ui

但是当我启动我的应用并访问swagger时,无法看到swagger-ui页面,将配置更改如下,我可以看到swagger-ui页面,当我将其改回上述配置时,我可以看到swagger-ui。

swagger-ui:
path: /swagger-ui

我这样做在本地执行时有效,如果停止并重新启动我的应用程序,我必须重做我上面描述的相同步骤。是否有解决方案让我不需要这样做?因为我必须遵循一个规则,即其余的路由和端点的rest都必须在/clinic下面

/clinic/swagger-ui -> swagger页面

/clinic/api/ -> 端点rest

英文:

I'm config swagger-ui path from this context below using yml file and using quarkus

> swagger-ui:
path: /clinic/swagger-ui

but when start my application and access swagger can't see the page swagger-ui and changing the configuration as bellow, i can see the page swagger-ui when I change it back to the above configuration I can see the swagger-ui.

> swagger-ui:
path: /swagger-ui

I do this and it works during local execution if it stops and restart my application I have to redo the same steps that I described above.
Is the any solution for me not to need this? Because I have a rule which I must follow where the rest of the routes and endpoint's rest must be inside /clinic as below

> /clinic/swagger-ui -> page swagger
>
> /clinic/api/ -> endpoints rest's

答案1

得分: 1

这是按照Quarkus OpenAPI 和 Swagger UI 指南所操作的。为了复现,我进行了以下步骤:

  1. 使用以下扩展创建了一个 Quarkus (1.8.1) 项目:
    • quarkus-smallrye-openapi
    • quarkus-config-yaml(用于你的 application.yml
    • quarkus-resteasy(用于编写 REST 服务)
    • quarkus-resteasy-jsonb
  2. 创建了你的 REST 端点(我只是按照上述指南中的 /fruits 示例进行了操作)
  3. 配置了 application.yml
quarkus:
    smallrye-openapi:
        path: /fruit/openapi
    swagger-ui:
        path: /fruit/swagger-ui
        always-include: true

现在,你可以通过 curl http://localhost:8080/fruit/openapi 访问 OpenAPI yml,通过将你的浏览器指向 http://localhost:8080/fruit/swagger-ui 来访问 Swagger UI。

请注意,设置 always-include: true 会使得 Swagger UI 即使在生产环境中也可用!

英文:

This works following the Quarkus guide for OpenAPI and Swagger UI. To reproduce, I did the following:

  1. Create a Quarkus (1.8.1) project with the following extensions:
    • quarkus-smallrye-openapi
    • quarkus-config-yaml (for your application.yml)
    • quarkus-resteasy (for programming REST services)
    • quarkus-resteasy-jsonb
  2. Create your REST endpoint (I just did the /fruits example of the aforementioned guide)
  3. Configure application.yml
quarkus:
    smallrye-openapi:
        path: /fruit/openapi
    swagger-ui:
        path: /fruit/swagger-ui
        always-include: true

Now you can access the OpenAPI yml via curl http://localhost:8080/fruit/openapi and the Swagger UI by pointing your browser to http://localhost:8080/fruit/swagger-ui.

Please note that the setting always-include: true makes the Swagger UI available even in production!

huangapple
  • 本文由 发表于 2020年9月7日 07:33:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63769783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定