Repository: jwg4/flask-selfdoc

Issue:
We should be able to order endpoints lexically.

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index d01c143..91ef85d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,7 +28,7 @@ install:
   - pip install ${DEP}
   - pip install flake8
 script: 
-  - python -m unittest discover
+  - python setup.py test
   - flake8 --exclude=examples --max-line-length=100
   - python -m tests.check_example
 before_deploy:
@@ -46,8 +46,9 @@ deploy:
   - provider: pypi
     user: jwg
     on:
-      python: '3.6'
       branch: 'master'
+      python: 3.6
+      env: DEP="Flask"
     password:
       secure: M05VqVhp1AWjnKpA5MVO1nM0jjFCEIk6pUmKaWl9yGuIrwTkhSkbPDqRsc2Fga3S1E2P5WMW1zDy33LgxfH2y3DrBbEZeiKtyvzPteZhRMRzcqApQWG5lIaYLyMBs/ygQy0f2l6zBZTRfZbx/rAoeegQx9Frxm3dcPLbADwhg1McZdhrcO5EXFYN+96jEtjz3ePNcV3fNuhjCt7vtMlpDSbG+Xd4eiwuyENbxQkoCl2pyNNghz6/iQN1yimjO1Ecb/yFbvjkZKLl7Co7mF3X9tnGkYxG+Dqb9ZFcqE/OZkEcwiWE/wn7KkOFHmJecjc+W8pr40xipP0KpLqpy9oNMgArywL6w1pLn2SsS8gvnd3JWHoXFVsQhAbPbffy7hDrAOHxZdFBnQGU8p/u8PRQQhScnDidteArySTvxfObU5BoRho9QMZpvZEps/bi2/BJpGiBOY6SRiFA21N5w6Xk7sI7xIEYE0/zUps79+t9aq+rOJ3XnUvkIDR7OVin78LqwLMJz+3AgpfTp2I6y1StgICVu3RH0dBazH64X6lcRekOhBokPUG5agvJhnq0kmXLooHu2VulnRWWxWrFAvO1vhww4L+fsj5VhaJtQaDWEdNUPht1ARU8foNANbPu5KoR2Xiv8N9kzd/8RTDZ5wuZQwRtazcQuVBFK1Ww6WUWJyA=
 notifications:
diff --git a/flask_selfdoc/autodoc.py b/flask_selfdoc/autodoc.py
index 27288a4..a20a074 100644
--- a/flask_selfdoc/autodoc.py
+++ b/flask_selfdoc/autodoc.py
@@ -162,6 +162,8 @@ class Autodoc(object):
                     if p not in self.immutable_props:
                         props[p] = func_props[p]
                 links.append(props)
+        if sort == "lexical":
+            sort = sort_lexically
         if sort:
             return sort(links)
         else:
@@ -225,4 +227,12 @@ class Autodoc(object):
         return jsonify(data)
 
 
+def sort_lexically(links):
+    def parts(endpoint):
+        rule = endpoint['rule']
+        return rule.split("/")
+
+    return sorted(links, key=parts)
+
+
 Selfdoc = Autodoc


Test patch:
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index f71fcdf..a1e5ade 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -300,6 +300,32 @@ class TestAutodoc(unittest.TestCase):
             self.assertTrue(1 == len(self.autodoc.generate('group2')))
             self.assertFalse(1 == len(self.autodoc.generate('group3')))
 
+    def testGetWithLexicalSort(self):
+        @self.app.route('/abc')
+        @self.autodoc.doc()
+        def abc_message():
+            """Returns a message"""
+            return 'ABC!'
+
+        @self.app.route('/ab/d')
+        @self.autodoc.doc()
+        def abd_message():
+            """Returns a second message"""
+            return 'AB D!'
+
+        @self.app.route('/ab')
+        @self.autodoc.doc()
+        def ab_message():
+            """Returns a different message"""
+            return 'AB!'
+
+        with self.app.app_context():
+            doc = self.autodoc.generate(sort="lexical")
+        self.assertTrue(len(doc) == 3)
+        self.assertEqual(doc[0]['rule'], '/ab')
+        self.assertEqual(doc[1]['rule'], '/ab/d')
+        self.assertEqual(doc[2]['rule'], '/abc')
+
 
 class TestSelfdoc(TestAutodoc):
     """ We want this class name to work