简体   繁体   English

Flask-restplus:有什么方法可以大摇大摆地对命名空间进行排序?

[英]Flask-restplus: any way to sort the namespaces in swagger?

Is there any way to sort the Namespace entries after they've been added to the Api?Namespace条目添加到 Api 后,有没有办法对它们进行排序?

I'm following the documentation, and the flow (AFAIK) appears to be:我正在关注文档,流程(AFAIK)似乎是:

a) Create the API: a) 创建 API:

api = Api(version="1.0",
      title="MahApi",
      description="Mah Nice Little API",
      doc="/swagger-ui",
      strict_slashes=False)

b) Define namespaces: b) 定义命名空间:

ns = Namespace("sample_namespace",
           description="sample module api",
           path='/sample_one')
...
@ns.route('/test1', endpoint='sample_ns_test1')
class TestApi(Resource):

    def get(self):
        df = mah_service.get_some_data()
        return jsonify(json.loads(df.to_json(orient='records')))

c) Add namespaces to the API: c) 向 API 添加命名空间:

api.add_namespace(mah_sample_ns)

Where I'm facing an issue (albeit it's a cosmetic yet annoying one) is that the namespaces are not being sorted in any way.我面临的一个问题(虽然它是一个装饰性但令人讨厌的问题)是命名空间没有以任何方式排序。 It seems that I will need to sort the namespaces myself, manually, in code.看来我需要自己在代码中手动对命名空间进行排序。 Is there a more clever, pythonic way to get swagger to sort the namespaces?有没有更聪明的 Pythonic 方法来大摇大摆地对命名空间进行排序?

I am probably way too late but I have been wondering the same thing but with flask_restx so posting this to hopefully help others.我可能为时已晚,但我一直在想同样的事情,但使用flask_restx,因此发布此信息以希望对其他人有所帮助。 But it seems to go by the order in which your namespaces are imported.但它似乎按照导入命名空间的顺序进行。

For example:例如:

from rest.endpoints.Episodes import ns as episodes_namespace
from rest.endpoints.Plex import ns as plex_namespace
from rest.endpoints.Server import ns as server_namespace

Will be ordered in swagger as:将大摇大摆地订购为:

  1. Episodes剧集
  2. Plex
  3. Server服务器

While:尽管:

from rest.endpoints.Server import ns as server_namespace
from rest.endpoints.Episodes import ns as episodes_namespace
from rest.endpoints.Plex import ns as plex_namespace

Will be ordered in swagger as:将大摇大摆地订购为:

  1. Server服务器
  2. Episodes剧集
  3. Plex

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

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