提交 8d4510c9 作者: 方治民

feat: 更新接口文档实现及示例

上级 f7188792
{ {
"originUrl": "http://localhost:8181/api/v2/api-docs", "originType": "SwaggerV2",
"originUrl": "http://127.0.0.1:8081/api/v2/api-docs",
"templateType": "fetch",
"templatePath": "./pont.template", "templatePath": "./pont.template",
"transformPath": "./pont.transform",
"outDir": "./src/api/services", "outDir": "./src/api/services",
"surrounding": "typeScript", "surrounding": "typeScript",
"mocks": { "mocks": {
...@@ -9,7 +12,6 @@ ...@@ -9,7 +12,6 @@
"port": 3101, "port": 3101,
"wrapper": "{\"status\": 200, \"body\": {response}, \"message\": \"OK\"}" "wrapper": "{\"status\": 200, \"body\": {response}, \"message\": \"OK\"}"
}, },
"templateType": "fetch",
"prettierConfig": { "prettierConfig": {
"printWidth": 120, "printWidth": 120,
"semi": false, "semi": false,
......
import * as Pont from 'pont-engine'
import { Interface, BaseClass, Property, CodeGenerator } from 'pont-engine' import { Interface, BaseClass, Property, CodeGenerator } from 'pont-engine'
// 接口 API 前缀 // 接口 API 前缀
// 通常与项目的 env 配置中的 VITE_GLOB_API_URL_PREFIX 相同 // 通常与项目的 env 配置中的 VITE_GLOB_API_URL_PREFIX 相同
const API_URL_PREFIX = '/api' const API_URL_PREFIX = '/api'
export class FileStructures extends Pont.FileStructures {
getModsDeclaration(originCode: string): string {
return originCode
}
}
export default class BasicGenerator extends CodeGenerator { export default class BasicGenerator extends CodeGenerator {
getParams(inter: Interface, paramsCode: string) { getParams(inter: Interface, paramsCode: string) {
let requestParams = inter.getRequestParams(this.surrounding) let requestParams = inter.getRequestParams(this.surrounding)
const prettier = require('prettier') const prettier = require('prettier')
if (prettier.format(paramsCode, { parser: 'typescript' }).includes('{}')) { if (prettier.format(paramsCode, { parser: 'typescript' }).includes('{}')) {
requestParams = requestParams.replace('params', 'params?') if (!requestParams.includes('form')) {
requestParams = requestParams.replace('params', 'params?')
}
} }
return `${requestParams.replace( return `${requestParams.replace(
...@@ -54,18 +63,19 @@ export default class BasicGenerator extends CodeGenerator { ...@@ -54,18 +63,19 @@ export default class BasicGenerator extends CodeGenerator {
const method = inter.method.toUpperCase() const method = inter.method.toUpperCase()
const paramsCode = inter.getParamsCode('Params', this.surrounding) const paramsCode = inter.getParamsCode('Params', this.surrounding)
const requestParams = this.getParams(inter, paramsCode) const requestParams = this.getParams(inter, paramsCode)
const undef = inter.response.getInitialValue() === 'undefined'
return ` return `
/** /**
* @desc ${inter.description} * @desc ${inter.description}
*/ */
import * as defs from '../../baseClass'; ${undef ? '' : `import * as defs from '../../baseClass';`}
import { defHttp } from '/@/utils/http/axios' import { defHttp } from '/@/utils/http/axios'
export ${paramsCode} export ${paramsCode}
export const init = ${inter.response.getInitialValue()}; ${undef ? '' : `export const init = ${inter.response.getInitialValue(true)};`}
export function request(${requestParams}) { export function request(${requestParams}) {
return defHttp.request({ return defHttp.request({
...@@ -76,6 +86,11 @@ export default class BasicGenerator extends CodeGenerator { ...@@ -76,6 +86,11 @@ export default class BasicGenerator extends CodeGenerator {
? 'params' ? 'params'
: `data: ${requestParams.includes('form') ? 'form || params' : 'params'}` : `data: ${requestParams.includes('form') ? 'form || params' : 'params'}`
}, },
${
requestParams.includes('form')
? `headers: { 'Content-Type': 'multipart/form-data;charset=UTF-8' },`
: ''
}
...config, ...config,
}, options); }, options);
......
import { StandardDataSource } from 'pont-engine'
export default function (dataSource: StandardDataSource): StandardDataSource {
return dataSource
}
...@@ -7,8 +7,8 @@ declare namespace defs { ...@@ -7,8 +7,8 @@ declare namespace defs {
/** token */ /** token */
token?: string token?: string
/** 主键 */ /** 用户 ID */
userId?: number userId?: string
} }
export class MenuVo { export class MenuVo {
...@@ -59,7 +59,7 @@ declare namespace defs { ...@@ -59,7 +59,7 @@ declare namespace defs {
icon?: string icon?: string
/** 主键 */ /** 主键 */
id?: number id?: string
/** 元数据 */ /** 元数据 */
meta?: ObjectMap<any, object> meta?: ObjectMap<any, object>
...@@ -71,7 +71,7 @@ declare namespace defs { ...@@ -71,7 +71,7 @@ declare namespace defs {
path?: string path?: string
/** 父级ID */ /** 父级ID */
pid?: number pid?: string
/** 序号 */ /** 序号 */
serial?: number serial?: number
...@@ -111,7 +111,7 @@ declare namespace defs { ...@@ -111,7 +111,7 @@ declare namespace defs {
export class RoleVo { export class RoleVo {
/** 主键 */ /** 主键 */
id?: number id?: string
/** 名称 */ /** 名称 */
name?: string name?: string
...@@ -140,7 +140,7 @@ declare namespace defs { ...@@ -140,7 +140,7 @@ declare namespace defs {
roles?: Array<defs.RoleVo> roles?: Array<defs.RoleVo>
/** 主键 */ /** 主键 */
userId?: number userId?: string
/** 用户名 */ /** 用户名 */
username?: string username?: string
...@@ -163,7 +163,7 @@ declare namespace defs { ...@@ -163,7 +163,7 @@ declare namespace defs {
enabled?: boolean enabled?: boolean
/** 主键 */ /** 主键 */
id?: number id?: string
/** 最后登录IP地址 */ /** 最后登录IP地址 */
lastLoginIp?: string lastLoginIp?: string
...@@ -185,9 +185,9 @@ declare namespace defs { ...@@ -185,9 +185,9 @@ declare namespace defs {
} }
} }
declare namespace API { namespace API {
/** /**
* * 身份认证
*/ */
export namespace auth { export namespace auth {
/** /**
...@@ -268,12 +268,12 @@ declare namespace API { ...@@ -268,12 +268,12 @@ declare namespace API {
} }
/** /**
* * 示例
*/ */
export namespace hello { export namespace example {
/** /**
* hello * hello
* /api/hello/ * /api/example/
*/ */
export namespace hello { export namespace hello {
export class Params {} export class Params {}
...@@ -290,8 +290,26 @@ declare namespace API { ...@@ -290,8 +290,26 @@ declare namespace API {
} }
/** /**
* download
* /api/example/download
*/
export namespace download {
export class Params {}
export type Response = any
export const init: Response
export function request(
params?: Params,
config?: http.RequestConfig<Params>,
options?: http.RequestOptions,
): Promise<Response>
}
/**
* fail * fail
* /api/hello/fail * /api/example/fail
*/ */
export namespace fail { export namespace fail {
export class Params {} export class Params {}
...@@ -309,7 +327,7 @@ declare namespace API { ...@@ -309,7 +327,7 @@ declare namespace API {
/** /**
* page * page
* /api/hello/page * /api/example/page
*/ */
export namespace page { export namespace page {
export class Params { export class Params {
...@@ -333,15 +351,33 @@ declare namespace API { ...@@ -333,15 +351,33 @@ declare namespace API {
options?: http.RequestOptions, options?: http.RequestOptions,
): Promise<Response> ): Promise<Response>
} }
/**
* 测试 MyBatis Plus 查询
* /api/example/test
*/
export namespace test {
export class Params {}
export type Response = string
export const init: Response
export function request(
params?: Params,
config?: http.RequestConfig<Params>,
options?: http.RequestOptions,
): Promise<Response>
}
} }
/** /**
* * 文件管理
*/ */
export namespace minio { export namespace file {
/** /**
* 文件上传 * 文件上传
* /api/common/minio/upload * /api/common/file/upload
*/ */
export namespace upload { export namespace upload {
export class Params {} export class Params {}
...@@ -351,7 +387,7 @@ declare namespace API { ...@@ -351,7 +387,7 @@ declare namespace API {
export const init: Response export const init: Response
export function request( export function request(
params?: Params, params: Params,
form: FormData, form: FormData,
config?: http.RequestConfig<Params | FormData>, config?: http.RequestConfig<Params | FormData>,
options?: http.RequestOptions, options?: http.RequestOptions,
...@@ -360,7 +396,7 @@ declare namespace API { ...@@ -360,7 +396,7 @@ declare namespace API {
} }
/** /**
* * 权限管理
*/ */
export namespace permission { export namespace permission {
/** /**
...@@ -384,7 +420,7 @@ declare namespace API { ...@@ -384,7 +420,7 @@ declare namespace API {
/** 路径 */ /** 路径 */
path?: string path?: string
/** 父级ID */ /** 父级ID */
pid?: number pid?: string
/** 重定向 */ /** 重定向 */
redirect?: string redirect?: string
/** 序号 */ /** 序号 */
...@@ -413,7 +449,7 @@ declare namespace API { ...@@ -413,7 +449,7 @@ declare namespace API {
export namespace deleted { export namespace deleted {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export type Response = string export type Response = string
...@@ -434,7 +470,7 @@ declare namespace API { ...@@ -434,7 +470,7 @@ declare namespace API {
export namespace find { export namespace find {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export type Response = defs.PermissionVo export type Response = defs.PermissionVo
...@@ -463,7 +499,7 @@ declare namespace API { ...@@ -463,7 +499,7 @@ declare namespace API {
/** 图标 */ /** 图标 */
icon?: string icon?: string
/** id */ /** id */
id: number id: string
/** 元数据 */ /** 元数据 */
meta?: string meta?: string
/** 名称 */ /** 名称 */
...@@ -471,7 +507,7 @@ declare namespace API { ...@@ -471,7 +507,7 @@ declare namespace API {
/** 路径 */ /** 路径 */
path?: string path?: string
/** 父级ID */ /** 父级ID */
pid?: number pid?: string
/** 重定向 */ /** 重定向 */
redirect?: string redirect?: string
/** 序号 */ /** 序号 */
...@@ -526,8 +562,8 @@ declare namespace API { ...@@ -526,8 +562,8 @@ declare namespace API {
*/ */
export namespace tree { export namespace tree {
export class Params { export class Params {
/** 父级 id */ /** pid */
pid?: number pid: string
} }
export type Response = Array<defs.PermissionVo> export type Response = Array<defs.PermissionVo>
...@@ -543,7 +579,7 @@ declare namespace API { ...@@ -543,7 +579,7 @@ declare namespace API {
} }
/** /**
* * 角色管理
*/ */
export namespace role { export namespace role {
/** /**
...@@ -576,7 +612,7 @@ declare namespace API { ...@@ -576,7 +612,7 @@ declare namespace API {
export namespace assign { export namespace assign {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
/** ids 多个以逗号分割 */ /** ids 多个以逗号分割 */
ids: string ids: string
} }
...@@ -599,7 +635,7 @@ declare namespace API { ...@@ -599,7 +635,7 @@ declare namespace API {
export namespace deleted { export namespace deleted {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export type Response = string export type Response = string
...@@ -620,7 +656,7 @@ declare namespace API { ...@@ -620,7 +656,7 @@ declare namespace API {
export namespace find { export namespace find {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export type Response = defs.RoleVo export type Response = defs.RoleVo
...@@ -641,7 +677,7 @@ declare namespace API { ...@@ -641,7 +677,7 @@ declare namespace API {
export namespace modify { export namespace modify {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
/** 名称 */ /** 名称 */
name: string name: string
/** 标识 */ /** 标识 */
...@@ -706,7 +742,7 @@ declare namespace API { ...@@ -706,7 +742,7 @@ declare namespace API {
} }
/** /**
* * 用户管理
*/ */
export namespace user { export namespace user {
/** /**
...@@ -770,7 +806,7 @@ declare namespace API { ...@@ -770,7 +806,7 @@ declare namespace API {
export namespace assign { export namespace assign {
export class Params { export class Params {
/** id */ /** id */
id: number id: string
/** ids 多个以逗号分割 */ /** ids 多个以逗号分割 */
ids: string ids: string
} }
......
...@@ -2,8 +2,8 @@ export class LoginVo { ...@@ -2,8 +2,8 @@ export class LoginVo {
/** token */ /** token */
token = '' token = ''
/** 主键 */ /** 用户 ID */
userId = undefined userId = ''
} }
export class MenuVo { export class MenuVo {
...@@ -54,7 +54,7 @@ export class PermissionVo { ...@@ -54,7 +54,7 @@ export class PermissionVo {
icon = '' icon = ''
/** 主键 */ /** 主键 */
id = undefined id = ''
/** 元数据 */ /** 元数据 */
meta = undefined meta = undefined
...@@ -66,7 +66,7 @@ export class PermissionVo { ...@@ -66,7 +66,7 @@ export class PermissionVo {
path = '' path = ''
/** 父级ID */ /** 父级ID */
pid = undefined pid = ''
/** 序号 */ /** 序号 */
serial = undefined serial = undefined
...@@ -106,7 +106,7 @@ export class Result { ...@@ -106,7 +106,7 @@ export class Result {
export class RoleVo { export class RoleVo {
/** 主键 */ /** 主键 */
id = undefined id = ''
/** 名称 */ /** 名称 */
name = '' name = ''
...@@ -135,7 +135,7 @@ export class UserInfo { ...@@ -135,7 +135,7 @@ export class UserInfo {
roles = [] roles = []
/** 主键 */ /** 主键 */
userId = undefined userId = ''
/** 用户名 */ /** 用户名 */
username = '' username = ''
...@@ -158,7 +158,7 @@ export class UserVo { ...@@ -158,7 +158,7 @@ export class UserVo {
enabled = false enabled = false
/** 主键 */ /** 主键 */
id = undefined id = ''
/** 最后登录IP地址 */ /** 最后登录IP地址 */
lastLoginIp = '' lastLoginIp = ''
......
/** /**
* @description * @description 身份认证
*/ */
import * as login from './login' import * as login from './login'
import * as logout from './logout' import * as logout from './logout'
......
/**
* @desc download
*/
import { defHttp } from '/@/utils/http/axios'
export class Params {}
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/example/download',
method: 'GET',
params,
...config,
},
options,
)
}
...@@ -12,7 +12,7 @@ export const init = new defs.Result() ...@@ -12,7 +12,7 @@ export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/hello/fail', url: '/example/fail',
method: 'GET', method: 'GET',
params, params,
......
...@@ -12,7 +12,7 @@ export const init = new defs.Result() ...@@ -12,7 +12,7 @@ export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/hello/', url: '/example/',
method: 'GET', method: 'GET',
params, params,
......
/** /**
* @description * @description 示例
*/ */
import * as hello from './hello' import * as hello from './hello'
import * as download from './download'
import * as fail from './fail' import * as fail from './fail'
import * as page from './page' import * as page from './page'
import * as test from './test'
export { hello, fail, page } export { hello, download, fail, page, test }
...@@ -21,7 +21,7 @@ export const init = new defs.Result() ...@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/hello/page', url: '/example/page',
method: 'GET', method: 'GET',
params, params,
......
/**
* @desc 测试 MyBatis Plus 查询
*/
import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios'
export class Params {}
export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/example/test',
method: 'GET',
params,
...config,
},
options,
)
}
/** /**
* @description * @description 文件管理
*/ */
import * as upload from './upload' import * as upload from './upload'
......
...@@ -10,16 +10,17 @@ export class Params {} ...@@ -10,16 +10,17 @@ export class Params {}
export const init = new defs.Result() export const init = new defs.Result()
export function request( export function request(
params?: Params, params: Params,
form: FormData, form: FormData,
config?: http.RequestConfig<Params | FormData>, config?: http.RequestConfig<Params | FormData>,
options?: http.RequestOptions, options?: http.RequestOptions,
) { ) {
return defHttp.request( return defHttp.request(
{ {
url: '/common/minio/upload', url: '/common/file/upload',
method: 'POST', method: 'POST',
data: form || params, data: form || params,
headers: { 'Content-Type': 'multipart/form-data;charset=UTF-8' },
...config, ...config,
}, },
......
import * as auth from './auth' import * as auth from './auth'
import * as hello from './hello' import * as example from './example'
import * as minio from './minio' import * as file from './file'
import * as permission from './permission' import * as permission from './permission'
import * as role from './role' import * as role from './role'
import * as user from './user' import * as user from './user'
export const API = { export const API = {
auth, auth,
hello, example,
minio, file,
permission, permission,
role, role,
user, user,
......
...@@ -21,7 +21,7 @@ export class Params { ...@@ -21,7 +21,7 @@ export class Params {
/** 路径 */ /** 路径 */
path?: string path?: string
/** 父级ID */ /** 父级ID */
pid?: number pid?: string
/** 重定向 */ /** 重定向 */
redirect?: string redirect?: string
/** 序号 */ /** 序号 */
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export const init = new defs.Result() export const init = new defs.Result()
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export const init = new defs.Result() export const init = new defs.Result()
......
/** /**
* @description * @description 权限管理
*/ */
import * as add from './add' import * as add from './add'
import * as deleted from './deleted' import * as deleted from './deleted'
......
...@@ -15,7 +15,7 @@ export class Params { ...@@ -15,7 +15,7 @@ export class Params {
/** 图标 */ /** 图标 */
icon?: string icon?: string
/** id */ /** id */
id: number id: string
/** 元数据 */ /** 元数据 */
meta?: string meta?: string
/** 名称 */ /** 名称 */
...@@ -23,7 +23,7 @@ export class Params { ...@@ -23,7 +23,7 @@ export class Params {
/** 路径 */ /** 路径 */
path?: string path?: string
/** 父级ID */ /** 父级ID */
pid?: number pid?: string
/** 重定向 */ /** 重定向 */
redirect?: string redirect?: string
/** 序号 */ /** 序号 */
......
...@@ -6,8 +6,8 @@ import * as defs from '../../baseClass' ...@@ -6,8 +6,8 @@ import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios' import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** 父级 id */ /** pid */
pid?: number pid: string
} }
export const init = new defs.Result() export const init = new defs.Result()
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
/** ids 多个以逗号分割 */ /** ids 多个以逗号分割 */
ids: string ids: string
} }
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export const init = new defs.Result() export const init = new defs.Result()
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
} }
export const init = new defs.Result() export const init = new defs.Result()
......
/** /**
* @description * @description 角色管理
*/ */
import * as add from './add' import * as add from './add'
import * as assign from './assign' import * as assign from './assign'
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
/** 名称 */ /** 名称 */
name: string name: string
/** 标识 */ /** 标识 */
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** id */
id: number id: string
/** ids 多个以逗号分割 */ /** ids 多个以逗号分割 */
ids: string ids: string
} }
......
/** /**
* @description * @description 用户管理
*/ */
import * as getMenuList from './getMenuList' import * as getMenuList from './getMenuList'
import * as getPermCode from './getPermCode' import * as getPermCode from './getPermCode'
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
const title = ref('Hello World') const title = ref('Hello World')
// TODO: 测试接口 // TODO: 测试接口
API.hello.hello.request().then((body) => { API.example.hello.request().then((body) => {
console.log(body) console.log(body)
}) })
</script> </script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论