moyan-api 1.0.77 → 1.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +333 -165
- package/dist/template/api.js +1 -1
- package/dist/template/api.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/template/api.ts +16 -16
package/package.json
CHANGED
package/src/template/api.ts
CHANGED
|
@@ -8,14 +8,14 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
8
8
|
|
|
9
9
|
schemaKeys = []
|
|
10
10
|
|
|
11
|
-
prefix =''
|
|
11
|
+
prefix = ''
|
|
12
12
|
|
|
13
13
|
pathPrefix = ''
|
|
14
14
|
|
|
15
|
-
constructor(openAPIObject:OpenAPIObject,prefix:string='',pathPrefix='') {
|
|
15
|
+
constructor(openAPIObject: OpenAPIObject, prefix: string = '', pathPrefix = '') {
|
|
16
16
|
super(smfType.ts)
|
|
17
17
|
this.prefix = prefix
|
|
18
|
-
this.pathPrefix =pathPrefix
|
|
18
|
+
this.pathPrefix = pathPrefix
|
|
19
19
|
this.openAPIObject = openAPIObject
|
|
20
20
|
this.init()
|
|
21
21
|
}
|
|
@@ -25,12 +25,12 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
25
25
|
for (const key in this.openAPIObject.paths) {
|
|
26
26
|
for (const key1 in this.openAPIObject.paths[key]) {
|
|
27
27
|
const item = this.openAPIObject.paths[key][key1]
|
|
28
|
-
item.path = this.pathPrefix+key
|
|
28
|
+
item.path = this.pathPrefix + key
|
|
29
29
|
item.method = key1.toUpperCase()
|
|
30
30
|
item.auth = !!item.security
|
|
31
31
|
paths.set(`${item.operationId}`, {
|
|
32
32
|
...item,
|
|
33
|
-
operationId:this.prefix+item.operationId,
|
|
33
|
+
operationId: this.prefix + item.operationId,
|
|
34
34
|
reqType: this._getReqType(item),
|
|
35
35
|
resType: this._getResType(item),
|
|
36
36
|
reqDescription: this._getReqDescription(item),
|
|
@@ -53,9 +53,9 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
parseSchema(schema: any) {
|
|
56
|
-
const parameters
|
|
57
|
-
(schema?.parameters||[] as Array<any>).forEach((item: any) => {
|
|
58
|
-
parameters.set(item.name, item)
|
|
56
|
+
const parameters: Map<string, any> = new Map();
|
|
57
|
+
(schema?.parameters || [] as Array<any>).forEach((item: any) => {
|
|
58
|
+
item.in !== 'header' && parameters.set(item.name, item)
|
|
59
59
|
})
|
|
60
60
|
const arr = [...parameters.values()]
|
|
61
61
|
|
|
@@ -63,8 +63,8 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
63
63
|
let str = '{'
|
|
64
64
|
arr.forEach((item1: any) => {
|
|
65
65
|
const fieldType = item1.schema.$ref ? this.getSchemaEntity(item1.schema.$ref) : item1.schema.type
|
|
66
|
-
const fieldName = item1.name.includes('.')? `'${item1.name}'` : item1.name
|
|
67
|
-
str += (` ${fieldName}${item1.required ? '' : '?'}:${fieldType},${item1.description ? ' //' + item1.description : ''}`).replace(/\"|\n|\\/g,'')+'\n'
|
|
66
|
+
const fieldName = item1.name.includes('.') ? `'${item1.name}'` : item1.name
|
|
67
|
+
str += (` ${fieldName}${item1.required ? '' : '?'}:${fieldType},${item1.description ? ' //' + item1.description : ''}`).replace(/\"|\n|\\/g, '') + '\n'
|
|
68
68
|
})
|
|
69
69
|
str += '}'
|
|
70
70
|
return str
|
|
@@ -82,13 +82,13 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
82
82
|
try {
|
|
83
83
|
const key = Object.keys(item.responses[200].content)[0]
|
|
84
84
|
const schema = item.responses[200].content[key].schema
|
|
85
|
-
if(schema.type==='array'
|
|
86
|
-
if(schema.items && schema.items.$ref){
|
|
85
|
+
if (schema.type === 'array') {
|
|
86
|
+
if (schema.items && schema.items.$ref) {
|
|
87
87
|
return `Array<${this.getSchemaEntity(schema.items.$ref)}>`
|
|
88
|
-
}else{
|
|
88
|
+
} else {
|
|
89
89
|
return `Array<any>`
|
|
90
90
|
}
|
|
91
|
-
}else if(schema.$ref) {
|
|
91
|
+
} else if (schema.$ref) {
|
|
92
92
|
return this.getSchemaEntity(schema.$ref)
|
|
93
93
|
}
|
|
94
94
|
return `any`
|
|
@@ -99,7 +99,7 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
99
99
|
|
|
100
100
|
_getReqDescription(item: any) {
|
|
101
101
|
try {
|
|
102
|
-
return (item.requestBody.description || '').trim().replace(/\"|\n|\\/g,'')
|
|
102
|
+
return (item.requestBody.description || '').trim().replace(/\"|\n|\\/g, '')
|
|
103
103
|
} catch {
|
|
104
104
|
return ''
|
|
105
105
|
}
|
|
@@ -107,7 +107,7 @@ export class ApiTemplate extends Temp implements Template {
|
|
|
107
107
|
|
|
108
108
|
_getResDescription(item: any) {
|
|
109
109
|
try {
|
|
110
|
-
return (item.responses[200].description || '').trim().replace(/\"|\n|\\/g,'')
|
|
110
|
+
return (item.responses[200].description || '').trim().replace(/\"|\n|\\/g, '')
|
|
111
111
|
} catch {
|
|
112
112
|
return ''
|
|
113
113
|
}
|