Skip to content

使用getRoutes得到的接口列表顺序能否按照书写顺序排序? #12

Open
@bymmry

Description

@bymmry

问题描述

比如有一个TestController,内部有两个接口对应两个function

...
@route('/api/test/create', { name: '创建test', method: ['post'] })
 async create() {
   return await this.ctx.service.test.create();
 }
@route('/api/test/update', { name: '更新test', method: ['post'] })
 async update() {
   return await this.ctx.service.test.update();
 }
...

使用getRoutes得到的数据是,顺序是update()在create()之前

[
  ...,
  {
    ...,
    url: [ '/api/test/update' ],
    typeGlobalName: 'TestController',
    functionName: 'update',
    ...
  },
  {
    ...,
    url: [ '/api/test/create' ],
    typeGlobalName: 'TestController',
    functionName: 'create',
    ...
  },
  ...
]

想达到的效果

使用getRoutes得到的数据,按照controller文件的书写顺序进行排序。按照这里的例子,就是得到create()在update()之前的接口数据。

已尝试过的方法

  • 在写接口的时候在extInfo中添加索引属性。比较麻烦的是,在添加接口的时候,如果想把后面写的接口提前,就要把之前排序重新写一遍,很麻烦,可以实现目的,但是比较不想用。

  • 使用数字作为functionName。比如async 1()、async 2()...比较尴尬的是,看起来呢,不是很好看...新加接口也得像上一种做法一样重新写排序。也比较不想用。

最后

谢谢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions