简体   繁体   English

flask api 的 Swagger 文档是在 2 个不同的 url 上生成的:一个用于使用 flask_restx 的路由,另一个用于其他使用 swag_from

[英]Swagger documentation for flask api is generated on 2 different urls: one for routes using flask_restx and another - for others using swag_from

Please help!请帮忙!

I am new to Swagger and to writing flask APIs.我是 Swagger 和编写烧瓶 API 的新手。 We are still researching the best practices, so I needed to create some routes using Blueprint and swag_from:我们仍在研究最佳实践,因此我需要使用 Blueprint 和 swag_from 创建一些路线:

from flasgger import swag_from

While i have one other route that is using Blueprint and flask_restx package and has get() and post() methods in it.虽然我有另一条使用 Blueprint 和 flask_restx 包的路线,并且其中有 get() 和 post() 方法。 As a result, my swagger documentation is split between two different pages:结果,我的招摇文档分为两个不同的页面:

a) http://127.0.0.1:5000/apidocs/ - for routes using Blueprint and swag_from b) my Api's root url - for the endpoint that's using flask_restx a) http://127.0.0.1:5000/apidocs/ - 对于使用 Blueprint 和 swag_from 的路由 b) 我的 Api 的根 url - 对于使用 flask_restx 的端点

I want to merge these two swagger pages into a single swagger page.我想将这两个招摇页面合并为一个招摇页面。 Is there a way to do it?有没有办法做到这一点? And is it generally possible to do this while having different routes written using different packages as described above?并且通常可以在使用如上所述的不同包编写不同的路由时做到这一点?

Thanks a lot!非常感谢! Any pointers on how to this best would be much appreciated!任何关于如何做到最好的指示将不胜感激!

... needed to create some routes using Blueprint and swag_from... while i have one other route that is using Blueprint and flask_restx package ... I want to merge these two swagger pages into a single swagger page. ...需要使用 Blueprint 和 swag_from 创建一些路线...而我还有另一条使用 Blueprint 和 flask_restx 包的路线...我想将这两个 swagger 页面合并到一个 swagger 页面中。 Is there a way to do it?有没有办法做到这一点?

Both mentioned frameworks creates internal data structures in order to maintain data for OpenAPI spec generation.两个提到的框架都创建了内部数据结构,以便为 OpenAPI 规范生成维护数据。 Those internal data structures cannot be merged in any easy programmatic way.这些内部数据结构不能以任何简单的编程方式合并。

And is it generally possible to do this while having different routes written using different packages as described above?并且通常可以在使用如上所述的不同包编写不同的路由时做到这一点?

Except very special cases (some packages are meant to work together by design, eg. flasgger+flask-restful) it is not generally possible to combine multiple solutions into one.除了非常特殊的情况(某些包旨在通过设计协同工作,例如flasgger+flask-restful),通常不可能将多个解决方案组合成一个。

You can alternatively fully un-bundle OpenAPI specs documentation and publish specs by yourself for all routes no matter how or by which package they gets handled on the background.您也可以完全取消捆绑 OpenAPI 规范文档并自行为所有路由发布规范,无论它们在后台如何处理或由哪个包处理。

Thanks a lot!非常感谢! Any pointers on how to this best would be much appreciated!任何关于如何做到最好的指示将不胜感激!

It's hard to point at any really best practice since there is not much standardization in the REST API world.很难指出任何真正的最佳实践,因为 REST API 世界中没有太多标准化。 I would stick to the general rule of thumb "keep it simple, keep it safe" and stick only with one solution.我会坚持一般的经验法则“保持简单,保持安全”并且只坚持一种解决方案。

Alternatively you might research other libraries and frameworks available and find 3rd option which would satisfy all project requirements.或者,您可以研究其他可用的库和框架,并找到满足所有项目要求的第三个选项。

Also, if you know how to customize the url-route that hosts swagger documenation,此外,如果您知道如何自定义托管 swagger 文档的 url-route,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM